Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

db_am.h

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: db_am.h,v 12.8 2005/09/28 17:44:24 margo Exp $
00008  */
00009 #ifndef _DB_AM_H_
00010 #define _DB_AM_H_
00011 
00012 /*
00013  * IS_ENV_AUTO_COMMIT --
00014  *      Auto-commit test for enviroment operations: DbEnv::{open,remove,rename}
00015  */
00016 #define IS_ENV_AUTO_COMMIT(dbenv, txn, flags)                           \
00017         (LF_ISSET(DB_AUTO_COMMIT) ||                                    \
00018             ((txn) == NULL && F_ISSET((dbenv), DB_ENV_AUTO_COMMIT) &&   \
00019             !LF_ISSET(DB_NO_AUTO_COMMIT)))
00020 
00021 /*
00022  * IS_DB_AUTO_COMMIT --
00023  *      Auto-commit test for database operations.
00024  */
00025 #define IS_DB_AUTO_COMMIT(dbp, txn)                                     \
00026             ((txn) == NULL && F_ISSET((dbp), DB_AM_TXN))
00027 
00028 /*
00029  * STRIP_AUTO_COMMIT --
00030  *      Releases after 4.3 no longer requires DB operations to specify the
00031  *      AUTO_COMMIT flag, but the API continues to allow it to be specified.
00032  */
00033 #define STRIP_AUTO_COMMIT(f)    FLD_CLR((f), DB_AUTO_COMMIT)
00034 
00035 /* DB recovery operation codes. */
00036 #define DB_ADD_DUP      1
00037 #define DB_REM_DUP      2
00038 #define DB_ADD_BIG      3
00039 #define DB_REM_BIG      4
00040 
00041 /*
00042  * Standard initialization and shutdown macros for all recovery functions.
00043  */
00044 #define REC_INTRO(func, inc_count, do_cursor) do {                      \
00045         argp = NULL;                                                    \
00046         file_dbp = NULL;                                                \
00047         COMPQUIET(dbc, NULL);                                           \
00048         /* mpf isn't used by all of the recovery functions. */          \
00049         COMPQUIET(mpf, NULL);                                           \
00050         if ((ret = func(dbenv, dbtp->data, &argp)) != 0)                \
00051                 goto out;                                               \
00052         if ((ret = __dbreg_id_to_db(dbenv, argp->txnid,                 \
00053             &file_dbp, argp->fileid, inc_count)) != 0) {                \
00054                 if (ret == DB_DELETED) {                                \
00055                         ret = 0;                                        \
00056                         goto done;                                      \
00057                 }                                                       \
00058                 goto out;                                               \
00059         }                                                               \
00060         if (do_cursor) {                                                \
00061                 if ((ret = __db_cursor(file_dbp, NULL, &dbc, 0)) != 0)  \
00062                         goto out;                                       \
00063                 F_SET(dbc, DBC_RECOVER);                                \
00064         }                                                               \
00065         mpf = file_dbp->mpf;                                            \
00066 } while (0)
00067 
00068 #define REC_CLOSE {                                                     \
00069         int __t_ret;                                                    \
00070         if (argp != NULL)                                               \
00071                 __os_free(dbenv, argp);                                 \
00072         if (dbc != NULL &&                                              \
00073             (__t_ret = __db_c_close(dbc)) != 0 && ret == 0)             \
00074                 ret = __t_ret;                                          \
00075         }                                                               \
00076         return (ret)
00077 
00078 /*
00079  * No-op versions of the same macros.
00080  */
00081 #define REC_NOOP_INTRO(func) do {                                       \
00082         argp = NULL;                                                    \
00083         if ((ret = func(dbenv, dbtp->data, &argp)) != 0)                \
00084                 return (ret);                                           \
00085 } while (0)
00086 #define REC_NOOP_CLOSE                                                  \
00087         if (argp != NULL)                                               \
00088                 __os_free(dbenv, argp);                                 \
00089         return (ret)
00090 
00091 /*
00092  * Macro for reading pages during recovery.  In most cases we
00093  * want to avoid an error if the page is not found during rollback
00094  * or if we are using truncate to remove pages from the file.
00095  */
00096 #ifndef HAVE_FTRUNCATE
00097 #define REC_FGET(mpf, pgno, pagep, cont)                                \
00098         if ((ret = __memp_fget(mpf, &(pgno), 0, pagep)) != 0) {         \
00099                 if (ret != DB_PAGE_NOTFOUND || DB_REDO(op)) {           \
00100                         ret = __db_pgerr(file_dbp, pgno, ret);          \
00101                         goto out;                                       \
00102                 } else                                                  \
00103                         goto cont;                                      \
00104         }
00105 #else
00106 #define REC_FGET(mpf, pgno, pagep, cont)                                \
00107         if ((ret = __memp_fget(mpf, &(pgno), 0, pagep)) != 0) {         \
00108                 if (ret != DB_PAGE_NOTFOUND) {                          \
00109                         ret = __db_pgerr(file_dbp, pgno, ret);          \
00110                         goto out;                                       \
00111                 } else                                                  \
00112                         goto cont;                                      \
00113         }
00114 #endif
00115 
00116 /*
00117  * Standard debugging macro for all recovery functions.
00118  */
00119 #ifdef DEBUG_RECOVER
00120 #define REC_PRINT(func)                                                 \
00121         (void)func(dbenv, dbtp, lsnp, op, info);
00122 #else
00123 #define REC_PRINT(func)
00124 #endif
00125 
00126 /*
00127  * Actions to __db_lget
00128  */
00129 #define LCK_ALWAYS              1       /* Lock even for off page dup cursors */
00130 #define LCK_COUPLE              2       /* Lock Couple */
00131 #define LCK_COUPLE_ALWAYS       3       /* Lock Couple even in txn. */
00132 #define LCK_DOWNGRADE           4       /* Downgrade the lock. (internal) */
00133 #define LCK_ROLLBACK            5       /* Lock even if in rollback */
00134 
00135 /*
00136  * If doing transactions we have to hold the locks associated with a data item
00137  * from a page for the entire transaction.  However, we don't have to hold the
00138  * locks associated with walking the tree.  Distinguish between the two so that
00139  * we don't tie up the internal pages of the tree longer than necessary.
00140  */
00141 #define __LPUT(dbc, lock)                                               \
00142         __ENV_LPUT((dbc)->dbp->dbenv, lock)
00143 
00144 #define __ENV_LPUT(dbenv, lock)                                         \
00145         (LOCK_ISSET(lock) ? __lock_put(dbenv, &(lock)) : 0)
00146 
00147 /*
00148  * __TLPUT -- transactional lock put
00149  *      If the lock is valid then
00150  *         If we are not in a transaction put the lock.
00151  *         Else if the cursor is doing dirty reads and this was a read then
00152  *              put the lock.
00153  *         Else if the db is supporting dirty reads and this is a write then
00154  *              downgrade it.
00155  *      Else do nothing.
00156  */
00157 #define __TLPUT(dbc, lock)                                              \
00158         (LOCK_ISSET(lock) ? __db_lput(dbc, &(lock)) : 0)
00159 
00160 typedef struct {
00161         DBC *dbc;
00162         u_int32_t count;
00163 } db_trunc_param;
00164 
00165 /*
00166  * A database should be required to be readonly if it's been explicitly
00167  * specified as such or if we're a client in a replicated environment and
00168  * we don't have the special "client-writer" designation.
00169  */
00170 #define DB_IS_READONLY(dbp)                                             \
00171     (F_ISSET(dbp, DB_AM_RDONLY) ||                                      \
00172     (IS_REP_CLIENT((dbp)->dbenv) &&                                     \
00173     !F_ISSET((dbp), DB_AM_CL_WRITER)))
00174 
00175 /*
00176  * For portability, primary keys that are record numbers are stored in
00177  * secondaries in the same byte order as the secondary database.  As a
00178  * consequence, we need to swap the byte order of these keys before attempting
00179  * to use them for lookups in the primary.  We also need to swap user-supplied
00180  * primary keys that are used in secondary lookups (for example, with the
00181  * DB_GET_BOTH flag on a secondary get).
00182  */
00183 #include "dbinc/db_swap.h"
00184 
00185 #define SWAP_IF_NEEDED(pdbp, sdbp, pkey)                                \
00186         do {                                                            \
00187                 if (((pdbp)->type == DB_QUEUE ||                        \
00188                     (pdbp)->type == DB_RECNO) &&                        \
00189                     F_ISSET((sdbp), DB_AM_SWAP))                        \
00190                         P_32_SWAP((pkey)->data);                        \
00191         } while (0)
00192 
00193 #include "dbinc/db_dispatch.h"
00194 #include "dbinc_auto/db_auto.h"
00195 #include "dbinc_auto/crdel_auto.h"
00196 #include "dbinc_auto/db_ext.h"
00197 #endif /* !_DB_AM_H_ */

Generated on Sun Dec 25 12:14:22 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2