1251881Speter/* env.h : managing the BDB environment 2251881Speter * 3251881Speter * ==================================================================== 4251881Speter * Licensed to the Apache Software Foundation (ASF) under one 5251881Speter * or more contributor license agreements. See the NOTICE file 6251881Speter * distributed with this work for additional information 7251881Speter * regarding copyright ownership. The ASF licenses this file 8251881Speter * to you under the Apache License, Version 2.0 (the 9251881Speter * "License"); you may not use this file except in compliance 10251881Speter * with the License. You may obtain a copy of the License at 11251881Speter * 12251881Speter * http://www.apache.org/licenses/LICENSE-2.0 13251881Speter * 14251881Speter * Unless required by applicable law or agreed to in writing, 15251881Speter * software distributed under the License is distributed on an 16251881Speter * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17251881Speter * KIND, either express or implied. See the License for the 18251881Speter * specific language governing permissions and limitations 19251881Speter * under the License. 20251881Speter * ==================================================================== 21251881Speter */ 22251881Speter 23251881Speter#ifndef SVN_LIBSVN_FS_BDB_ENV_H 24251881Speter#define SVN_LIBSVN_FS_BDB_ENV_H 25251881Speter 26251881Speter#define SVN_WANT_BDB 27251881Speter#include "svn_private_config.h" 28251881Speter 29251881Speter#include <apr_pools.h> 30251881Speter#include <apr_file_io.h> 31251881Speter 32251881Speter#include "bdb_compat.h" 33251881Speter 34251881Speter#ifdef __cplusplus 35251881Speterextern "C" { 36251881Speter#endif /* __cplusplus */ 37251881Speter 38251881Speter 39251881Speter/* The name of the Berkeley DB config file. */ 40251881Speter#define BDB_CONFIG_FILE "DB_CONFIG" 41251881Speter 42251881Speter/* Prefix string for BDB errors. */ 43251881Speter#define BDB_ERRPFX_STRING "svn (bdb): " 44251881Speter 45251881Speter 46251881Speter/* Opaque descriptor of an open BDB environment. */ 47251881Spetertypedef struct bdb_env_t bdb_env_t; 48251881Speter 49251881Speter 50251881Speter/* Thread-specific error info related to the bdb_env_t. */ 51251881Spetertypedef struct bdb_error_info_t 52251881Speter{ 53251881Speter /* We hold the extended info here until the Berkeley DB function returns. 54251881Speter It usually returns an error code, triggering the collection and 55251881Speter wrapping of the additional errors stored here. 56251881Speter 57251881Speter Note: In some circumstances BDB will call the error function and not 58251881Speter go on to return an error code, so the caller must always check whether 59251881Speter pending_errors is non-NULL to avoid leaking errors. This behaviour 60251881Speter has been seen when running recovery on a repository upgraded to 4.3 61251881Speter that still has old 4.2 log files present, a typical error string is 62251881Speter "Skipping log file db/log.0000000002: historic log version 8" */ 63251881Speter svn_error_t *pending_errors; 64251881Speter 65251881Speter /* We permitted clients of our library to install a Berkeley BDB errcall. 66251881Speter Since we now use the errcall ourselves, we must store and invoke a user 67251881Speter errcall, to maintain our API guarantees. */ 68251881Speter void (*user_callback)(const char *errpfx, char *msg); 69251881Speter 70251881Speter /* The reference count. It counts the number of bdb_env_baton_t 71251881Speter instances that refer to this object. */ 72251881Speter unsigned refcount; 73251881Speter 74251881Speter} bdb_error_info_t; 75251881Speter 76251881Speter 77251881Speter/* The Berkeley DB environment baton. */ 78251881Spetertypedef struct bdb_env_baton_t 79251881Speter{ 80251881Speter /* The Berkeley DB environment. This pointer must be identical to 81251881Speter the one in the bdb_env_t. */ 82251881Speter DB_ENV *env; 83251881Speter 84251881Speter /* The (opaque) cached environment descriptor. */ 85251881Speter bdb_env_t *bdb; 86251881Speter 87251881Speter /* The error info related to this baton. */ 88251881Speter bdb_error_info_t *error_info; 89251881Speter} bdb_env_baton_t; 90251881Speter 91251881Speter 92251881Speter 93251881Speter/* Flag combination for opening a shared BDB environment. */ 94251881Speter#define SVN_BDB_STANDARD_ENV_FLAGS (DB_CREATE \ 95251881Speter | DB_INIT_LOCK \ 96251881Speter | DB_INIT_LOG \ 97251881Speter | DB_INIT_MPOOL \ 98251881Speter | DB_INIT_TXN \ 99251881Speter | SVN_BDB_AUTO_RECOVER) 100251881Speter 101251881Speter/* Flag combination for opening a private BDB environment. */ 102251881Speter#define SVN_BDB_PRIVATE_ENV_FLAGS (DB_CREATE \ 103251881Speter | DB_INIT_LOG \ 104251881Speter | DB_INIT_MPOOL \ 105251881Speter | DB_INIT_TXN \ 106251881Speter | DB_PRIVATE) 107251881Speter 108251881Speter 109251881Speter/* Iniitalize the BDB back-end's private stuff. */ 110251881Spetersvn_error_t *svn_fs_bdb__init(apr_pool_t* pool); 111251881Speter 112251881Speter 113251881Speter/* Allocate the Berkeley DB descriptor BDB and open the environment. 114251881Speter * 115251881Speter * Allocate *BDBP from POOL and open (*BDBP)->env in PATH, using FLAGS 116251881Speter * and MODE. If applicable, set the BDB_AUTO_COMMIT flag for this 117251881Speter * environment. 118251881Speter * 119251881Speter * Use POOL for temporary allocation. 120251881Speter * 121251881Speter * Note: This function may return a bdb_env_baton_t object that refers 122251881Speter * to a previously opened environment. If FLAGS contains 123251881Speter * DB_PRIVATE and the environment is already open, the function 124251881Speter * will fail (this isn't a problem in practice, because a caller 125251881Speter * should obtain an exclusive lock on the repository before 126251881Speter * opening the environment). 127251881Speter */ 128251881Speter 129251881Spetersvn_error_t *svn_fs_bdb__open(bdb_env_baton_t **bdb_batonp, 130251881Speter const char *path, 131251881Speter u_int32_t flags, int mode, 132251881Speter apr_pool_t *pool); 133251881Speter 134251881Speter/* Close the Berkeley DB descriptor BDB. 135251881Speter * 136251881Speter * Note: This function might not actually close the environment if it 137251881Speter * has been opened more than once. 138251881Speter */ 139251881Spetersvn_error_t *svn_fs_bdb__close(bdb_env_baton_t *bdb_baton); 140251881Speter 141251881Speter 142251881Speter/* Get the panic state of the open BDB environment. */ 143251881Spetersvn_boolean_t svn_fs_bdb__get_panic(bdb_env_baton_t *bdb_baton); 144251881Speter 145251881Speter/* Set the panic flag on the open BDB environment. */ 146251881Spetervoid svn_fs_bdb__set_panic(bdb_env_baton_t *bdb_baton); 147251881Speter 148251881Speter 149251881Speter/* Remove the Berkeley DB environment at PATH. 150251881Speter * 151251881Speter * Use POOL for temporary allocation. 152251881Speter */ 153251881Spetersvn_error_t *svn_fs_bdb__remove(const char *path, apr_pool_t *pool); 154251881Speter 155251881Speter#ifdef __cplusplus 156251881Speter} 157251881Speter#endif /* __cplusplus */ 158251881Speter 159251881Speter#endif /* SVN_LIBSVN_FS_BDB_ENV_H */ 160