1 /* env.h : managing the BDB environment
3 * ====================================================================
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
20 * ====================================================================
23 #ifndef SVN_LIBSVN_FS_BDB_ENV_H
24 #define SVN_LIBSVN_FS_BDB_ENV_H
27 #include "svn_private_config.h"
29 #include <apr_pools.h>
30 #include <apr_file_io.h>
32 #include "bdb_compat.h"
36 #endif /* __cplusplus */
39 /* The name of the Berkeley DB config file. */
40 #define BDB_CONFIG_FILE "DB_CONFIG"
42 /* Prefix string for BDB errors. */
43 #define BDB_ERRPFX_STRING "svn (bdb): "
46 /* Opaque descriptor of an open BDB environment. */
47 typedef struct bdb_env_t bdb_env_t;
50 /* Thread-specific error info related to the bdb_env_t. */
51 typedef struct bdb_error_info_t
53 /* We hold the extended info here until the Berkeley DB function returns.
54 It usually returns an error code, triggering the collection and
55 wrapping of the additional errors stored here.
57 Note: In some circumstances BDB will call the error function and not
58 go on to return an error code, so the caller must always check whether
59 pending_errors is non-NULL to avoid leaking errors. This behaviour
60 has been seen when running recovery on a repository upgraded to 4.3
61 that still has old 4.2 log files present, a typical error string is
62 "Skipping log file db/log.0000000002: historic log version 8" */
63 svn_error_t *pending_errors;
65 /* We permitted clients of our library to install a Berkeley BDB errcall.
66 Since we now use the errcall ourselves, we must store and invoke a user
67 errcall, to maintain our API guarantees. */
68 void (*user_callback)(const char *errpfx, char *msg);
70 /* The reference count. It counts the number of bdb_env_baton_t
71 instances that refer to this object. */
77 /* The Berkeley DB environment baton. */
78 typedef struct bdb_env_baton_t
80 /* The Berkeley DB environment. This pointer must be identical to
81 the one in the bdb_env_t. */
84 /* The (opaque) cached environment descriptor. */
87 /* The error info related to this baton. */
88 bdb_error_info_t *error_info;
93 /* Flag combination for opening a shared BDB environment. */
94 #define SVN_BDB_STANDARD_ENV_FLAGS (DB_CREATE \
99 | SVN_BDB_AUTO_RECOVER)
101 /* Flag combination for opening a private BDB environment. */
102 #define SVN_BDB_PRIVATE_ENV_FLAGS (DB_CREATE \
109 /* Iniitalize the BDB back-end's private stuff. */
110 svn_error_t *svn_fs_bdb__init(apr_pool_t* pool);
113 /* Allocate the Berkeley DB descriptor BDB and open the environment.
115 * Allocate *BDBP from POOL and open (*BDBP)->env in PATH, using FLAGS
116 * and MODE. If applicable, set the BDB_AUTO_COMMIT flag for this
119 * Use POOL for temporary allocation.
121 * Note: This function may return a bdb_env_baton_t object that refers
122 * to a previously opened environment. If FLAGS contains
123 * DB_PRIVATE and the environment is already open, the function
124 * will fail (this isn't a problem in practice, because a caller
125 * should obtain an exclusive lock on the repository before
126 * opening the environment).
129 svn_error_t *svn_fs_bdb__open(bdb_env_baton_t **bdb_batonp,
131 u_int32_t flags, int mode,
134 /* Close the Berkeley DB descriptor BDB.
136 * Note: This function might not actually close the environment if it
137 * has been opened more than once.
139 svn_error_t *svn_fs_bdb__close(bdb_env_baton_t *bdb_baton);
142 /* Get the panic state of the open BDB environment. */
143 svn_boolean_t svn_fs_bdb__get_panic(bdb_env_baton_t *bdb_baton);
145 /* Set the panic flag on the open BDB environment. */
146 void svn_fs_bdb__set_panic(bdb_env_baton_t *bdb_baton);
149 /* Remove the Berkeley DB environment at PATH.
151 * Use POOL for temporary allocation.
153 svn_error_t *svn_fs_bdb__remove(const char *path, apr_pool_t *pool);
157 #endif /* __cplusplus */
159 #endif /* SVN_LIBSVN_FS_BDB_ENV_H */