]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/subversion/subversion/libsvn_fs_base/bdb/env.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / subversion / subversion / libsvn_fs_base / bdb / env.h
1 /* env.h : managing the BDB environment
2  *
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  *    under the License.
20  * ====================================================================
21  */
22
23 #ifndef SVN_LIBSVN_FS_BDB_ENV_H
24 #define SVN_LIBSVN_FS_BDB_ENV_H
25
26 #define SVN_WANT_BDB
27 #include "svn_private_config.h"
28
29 #include <apr_pools.h>
30 #include <apr_file_io.h>
31
32 #include "bdb_compat.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif /* __cplusplus */
37
38 \f
39 /* The name of the Berkeley DB config file.  */
40 #define BDB_CONFIG_FILE "DB_CONFIG"
41
42 /* Prefix string for BDB errors. */
43 #define BDB_ERRPFX_STRING "svn (bdb): "
44
45
46 /* Opaque descriptor of an open BDB environment. */
47 typedef struct bdb_env_t bdb_env_t;
48
49
50 /* Thread-specific error info related to the bdb_env_t. */
51 typedef struct bdb_error_info_t
52 {
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.
56
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;
64
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);
69
70   /* The reference count.  It counts the number of bdb_env_baton_t
71      instances that refer to this object. */
72   unsigned refcount;
73
74 } bdb_error_info_t;
75
76
77 /* The Berkeley DB environment baton. */
78 typedef struct bdb_env_baton_t
79 {
80   /* The Berkeley DB environment. This pointer must be identical to
81      the one in the bdb_env_t. */
82   DB_ENV *env;
83
84   /* The (opaque) cached environment descriptor. */
85   bdb_env_t *bdb;
86
87   /* The error info related to this baton. */
88   bdb_error_info_t *error_info;
89 } bdb_env_baton_t;
90
91
92 \f
93 /* Flag combination for opening a shared BDB environment. */
94 #define SVN_BDB_STANDARD_ENV_FLAGS (DB_CREATE       \
95                                     | DB_INIT_LOCK  \
96                                     | DB_INIT_LOG   \
97                                     | DB_INIT_MPOOL \
98                                     | DB_INIT_TXN   \
99                                     | SVN_BDB_AUTO_RECOVER)
100
101 /* Flag combination for opening a private BDB environment. */
102 #define SVN_BDB_PRIVATE_ENV_FLAGS (DB_CREATE       \
103                                    | DB_INIT_LOG   \
104                                    | DB_INIT_MPOOL \
105                                    | DB_INIT_TXN   \
106                                    | DB_PRIVATE)
107
108
109 /* Iniitalize the BDB back-end's private stuff. */
110 svn_error_t *svn_fs_bdb__init(apr_pool_t* pool);
111
112
113 /* Allocate the Berkeley DB descriptor BDB and open the environment.
114  *
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
117  * environment.
118  *
119  * Use POOL for temporary allocation.
120  *
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).
127  */
128
129 svn_error_t *svn_fs_bdb__open(bdb_env_baton_t **bdb_batonp,
130                               const char *path,
131                               u_int32_t flags, int mode,
132                               apr_pool_t *pool);
133
134 /* Close the Berkeley DB descriptor BDB.
135  *
136  * Note: This function might not actually close the environment if it
137  *       has been opened more than once.
138  */
139 svn_error_t *svn_fs_bdb__close(bdb_env_baton_t *bdb_baton);
140
141
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);
144
145 /* Set the panic flag on the open BDB environment. */
146 void svn_fs_bdb__set_panic(bdb_env_baton_t *bdb_baton);
147
148
149 /* Remove the Berkeley DB environment at PATH.
150  *
151  * Use POOL for temporary allocation.
152  */
153 svn_error_t *svn_fs_bdb__remove(const char *path, apr_pool_t *pool);
154
155 #ifdef __cplusplus
156 }
157 #endif /* __cplusplus */
158
159 #endif /* SVN_LIBSVN_FS_BDB_ENV_H */