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

db_int.h

00001 /* DO NOT EDIT: automatically built by dist/s_win32. */
00002 /*-
00003  * See the file LICENSE for redistribution information.
00004  *
00005  * Copyright (c) 1996-2005
00006  *      Sleepycat Software.  All rights reserved.
00007  *
00008  * $Id: db_int.in,v 12.15 2005/11/03 17:46:08 bostic Exp $
00009  */
00010 
00011 #ifndef _DB_INTERNAL_H_
00012 #define _DB_INTERNAL_H_
00013 
00014 /*******************************************************
00015  * System includes, db.h, a few general DB includes.  The DB includes are
00016  * here because it's OK if db_int.h includes queue structure declarations.
00017  *******************************************************/
00018 #ifndef NO_SYSTEM_INCLUDES
00019 #if defined(STDC_HEADERS) || defined(__cplusplus)
00020 #include <stdarg.h>
00021 #else
00022 #include <varargs.h>
00023 #endif
00024 #include <errno.h>
00025 #endif
00026 
00027 #include "db.h"
00028 
00029 #include "dbinc/queue.h"
00030 #include "dbinc/shqueue.h"
00031 
00032 #if defined(__cplusplus)
00033 extern "C" {
00034 #endif
00035 
00036 /*******************************************************
00037  * General purpose constants and macros.
00038  *******************************************************/
00039 #ifndef UINT16_MAX
00040 #define UINT16_MAX      65535           /* Maximum 16-bit unsigned. */
00041 #endif
00042 #ifndef UINT32_MAX
00043 #ifdef __STDC__
00044 #define UINT32_MAX      4294967295U     /* Maximum 32-bit unsigned. */
00045 #else
00046 #define UINT32_MAX      0xffffffff      /* Maximum 32-bit unsigned. */
00047 #endif
00048 #endif
00049 
00050 #if defined(HAVE_64BIT_TYPES)
00051 #undef  INT64_MAX
00052 #undef  INT64_MIN
00053 #undef  UINT64_MAX
00054 
00055 #ifdef  DB_WIN32
00056 #define INT64_MAX       _I64_MAX
00057 #define INT64_MIN       _I64_MIN
00058 #define UINT64_MAX      _UI64_MAX
00059 
00060 #define INT64_FMT       "%l64d"
00061 #define UINT64_FMT      "%l64u"
00062 #else
00063 /*
00064  * Override the system's 64-bit min/max constants.  AIX's 32-bit compiler can
00065  * handle 64-bit values, but the system's constants don't include the LL/ULL
00066  * suffix, and so can't be compiled using the 32-bit compiler.
00067  */
00068 #define INT64_MAX       9223372036854775807LL
00069 #define INT64_MIN       (-INT64_MAX-1)
00070 #define UINT64_MAX      18446744073709551615ULL
00071 
00072 
00073 
00074 #endif  /* DB_WIN32 */
00075 #endif  /* HAVE_LONG_LONG && HAVE_UNSIGNED_LONG_LONG */
00076 
00077 #define MEGABYTE        1048576
00078 #define GIGABYTE        1073741824
00079 
00080 #define MS_PER_SEC      1000            /* Milliseconds in a second. */
00081 #define USEC_PER_MS     1000            /* Microseconds in a millisecond. */
00082 
00083 #define RECNO_OOB       0               /* Illegal record number. */
00084 
00085 /* Test for a power-of-two (tests true for zero, which doesn't matter here). */
00086 #define POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0)
00087 
00088 /* Test for valid page sizes. */
00089 #define DB_MIN_PGSIZE   0x000200        /* Minimum page size (512). */
00090 #define DB_MAX_PGSIZE   0x010000        /* Maximum page size (65536). */
00091 #define IS_VALID_PAGESIZE(x)                                            \
00092         (POWER_OF_TWO(x) && (x) >= DB_MIN_PGSIZE && ((x) <= DB_MAX_PGSIZE))
00093 
00094 /* Minimum number of pages cached, by default. */
00095 #define DB_MINPAGECACHE 16
00096 
00097 /*
00098  * If we are unable to determine the underlying filesystem block size, use
00099  * 8K on the grounds that most OS's use less than 8K for a VM page size.
00100  */
00101 #define DB_DEF_IOSIZE   (8 * 1024)
00102 
00103 /* Align an integer to a specific boundary. */
00104 #undef  DB_ALIGN
00105 #define DB_ALIGN(v, bound)                                              \
00106         (((v) + (bound) - 1) & ~(((uintmax_t)(bound)) - 1))
00107 
00108 /* Increment a pointer to a specific boundary. */
00109 #undef  ALIGNP_INC
00110 #define ALIGNP_INC(p, bound)                                            \
00111         (void *)(((uintptr_t)(p) + (bound) - 1) & ~(((uintptr_t)(bound)) - 1))
00112 
00113 /* Decrement a pointer to a specific boundary. */
00114 #undef  ALIGNP_DEC
00115 #define ALIGNP_DEC(p, bound)                                            \
00116         (void *)((uintptr_t)(p) & ~(((uintptr_t)(bound)) - 1))
00117 
00118 /*
00119  * Print an address as a u_long (a u_long is the largest type we can print
00120  * portably).  Most 64-bit systems have made longs 64-bits, so this should
00121  * work.
00122  */
00123 #define P_TO_ULONG(p)   ((u_long)(uintptr_t)(p))
00124 
00125 /*
00126  * Convert a pointer to a small integral value.
00127  *
00128  * The (u_int16_t)(uintptr_t) cast avoids warnings: the (uintptr_t) cast
00129  * converts the value to an integral type, and the (u_int16_t) cast converts
00130  * it to a small integral type so we don't get complaints when we assign the
00131  * final result to an integral type smaller than uintptr_t.
00132  */
00133 #define P_TO_UINT32(p)  ((u_int32_t)(uintptr_t)(p))
00134 #define P_TO_UINT16(p)  ((u_int16_t)(uintptr_t)(p))
00135 
00136 /*
00137  * There are several on-page structures that are declared to have a number of
00138  * fields followed by a variable length array of items.  The structure size
00139  * without including the variable length array or the address of the first of
00140  * those elements can be found using SSZ.
00141  *
00142  * This macro can also be used to find the offset of a structure element in a
00143  * structure.  This is used in various places to copy structure elements from
00144  * unaligned memory references, e.g., pointers into a packed page.
00145  *
00146  * There are two versions because compilers object if you take the address of
00147  * an array.
00148  */
00149 #undef  SSZ
00150 #define SSZ(name, field)  P_TO_UINT16(&(((name *)0)->field))
00151 
00152 #undef  SSZA
00153 #define SSZA(name, field) P_TO_UINT16(&(((name *)0)->field[0]))
00154 
00155 /* Structure used to print flag values. */
00156 typedef struct __fn {
00157         u_int32_t mask;                 /* Flag value. */
00158         const char *name;               /* Flag name. */
00159 } FN;
00160 
00161 /* Set, clear and test flags. */
00162 #define FLD_CLR(fld, f)         (fld) &= ~(f)
00163 #define FLD_ISSET(fld, f)       ((fld) & (f))
00164 #define FLD_SET(fld, f)         (fld) |= (f)
00165 #define F_CLR(p, f)             (p)->flags &= ~(f)
00166 #define F_ISSET(p, f)           ((p)->flags & (f))
00167 #define F_SET(p, f)             (p)->flags |= (f)
00168 #define LF_CLR(f)               ((flags) &= ~(f))
00169 #define LF_ISSET(f)             ((flags) & (f))
00170 #define LF_SET(f)               ((flags) |= (f))
00171 
00172 /*
00173  * Calculate a percentage.  The values can overflow 32-bit integer arithmetic
00174  * so we use floating point.
00175  *
00176  * When calculating a bytes-vs-page size percentage, we're getting the inverse
00177  * of the percentage in all cases, that is, we want 100 minus the percentage we
00178  * calculate.
00179  */
00180 #define DB_PCT(v, total)                                                \
00181         ((int)((total) == 0 ? 0 : ((double)(v) * 100) / (total)))
00182 #define DB_PCT_PG(v, total, pgsize)                                     \
00183         ((int)((total) == 0 ? 0 :                                       \
00184             100 - ((double)(v) * 100) / (((double)total) * (pgsize))))
00185 
00186 /*
00187  * Structure used for callback message aggregation.
00188  *
00189  * Display values in XXX_stat_print calls.
00190  */
00191 typedef struct __db_msgbuf {
00192         char *buf;                      /* Heap allocated buffer. */
00193         char *cur;                      /* Current end of message. */
00194         size_t len;                     /* Allocated length of buffer. */
00195 } DB_MSGBUF;
00196 #define DB_MSGBUF_INIT(a) do {                                          \
00197         (a)->buf = (a)->cur = NULL;                                     \
00198         (a)->len = 0;                                                   \
00199 } while (0)
00200 #define DB_MSGBUF_FLUSH(dbenv, a) do {                                  \
00201         if ((a)->buf != NULL) {                                         \
00202                 if ((a)->cur != (a)->buf)                               \
00203                         __db_msg(dbenv, "%s", (a)->buf);                \
00204                 __os_free(dbenv, (a)->buf);                             \
00205                 DB_MSGBUF_INIT(a);                                      \
00206         }                                                               \
00207 } while (0)
00208 #define STAT_FMT(msg, fmt, type, v) do {                                \
00209         DB_MSGBUF __mb;                                                 \
00210         DB_MSGBUF_INIT(&__mb);                                          \
00211         __db_msgadd(dbenv, &__mb, fmt, (type)(v));                      \
00212         __db_msgadd(dbenv, &__mb, "\t%s", msg);                         \
00213         DB_MSGBUF_FLUSH(dbenv, &__mb);                                  \
00214 } while (0)
00215 #define STAT_HEX(msg, v)                                                \
00216         __db_msg(dbenv, "%#lx\t%s", (u_long)(v), msg)
00217 #define STAT_ISSET(msg, p)                                              \
00218         __db_msg(dbenv, "%sSet\t%s", (p) == NULL ? "!" : " ", msg)
00219 #define STAT_LONG(msg, v)                                               \
00220         __db_msg(dbenv, "%ld\t%s", (long)(v), msg)
00221 #define STAT_LSN(msg, lsnp)                                             \
00222         __db_msg(dbenv, "%lu/%lu\t%s",                                  \
00223             (u_long)(lsnp)->file, (u_long)(lsnp)->offset, msg)
00224 #define STAT_POINTER(msg, v)                                            \
00225         __db_msg(dbenv, "%#lx\t%s", P_TO_ULONG(v), msg)
00226 #define STAT_STRING(msg, p) do {                                        \
00227         const char *__p = p;    /* p may be a function call. */         \
00228         __db_msg(dbenv, "%s\t%s", __p == NULL ? "!Set" : __p, msg);     \
00229 } while (0)
00230 #define STAT_ULONG(msg, v)                                              \
00231         __db_msg(dbenv, "%lu\t%s", (u_long)(v), msg)
00232 
00233 /*******************************************************
00234  * API return values
00235  *******************************************************/
00236 /*
00237  * Return values that are OK for each different call.  Most calls have a
00238  * standard 'return of 0 is only OK value', but some, like db->get have
00239  * DB_NOTFOUND as a return value, but it really isn't an error.
00240  */
00241 #define DB_RETOK_STD(ret)       ((ret) == 0)
00242 #define DB_RETOK_DBCDEL(ret)    ((ret) == 0 || (ret) == DB_KEYEMPTY || \
00243                                     (ret) == DB_NOTFOUND)
00244 #define DB_RETOK_DBCGET(ret)    ((ret) == 0 || (ret) == DB_KEYEMPTY || \
00245                                     (ret) == DB_NOTFOUND)
00246 #define DB_RETOK_DBCPUT(ret)    ((ret) == 0 || (ret) == DB_KEYEXIST || \
00247                                     (ret) == DB_NOTFOUND)
00248 #define DB_RETOK_DBDEL(ret)     DB_RETOK_DBCDEL(ret)
00249 #define DB_RETOK_DBGET(ret)     DB_RETOK_DBCGET(ret)
00250 #define DB_RETOK_DBPUT(ret)     ((ret) == 0 || (ret) == DB_KEYEXIST)
00251 #define DB_RETOK_LGGET(ret)     ((ret) == 0 || (ret) == DB_NOTFOUND)
00252 #define DB_RETOK_MPGET(ret)     ((ret) == 0 || (ret) == DB_PAGE_NOTFOUND)
00253 #define DB_RETOK_REPPMSG(ret)   ((ret) == 0 || \
00254                                     (ret) == DB_REP_IGNORE || \
00255                                     (ret) == DB_REP_ISPERM || \
00256                                     (ret) == DB_REP_NEWMASTER || \
00257                                     (ret) == DB_REP_NEWSITE || \
00258                                     (ret) == DB_REP_NOTPERM || \
00259                                     (ret) == DB_REP_STARTUPDONE)
00260 
00261 /* Find a reasonable operation-not-supported error. */
00262 #ifdef  EOPNOTSUPP
00263 #define DB_OPNOTSUP     EOPNOTSUPP
00264 #else
00265 #ifdef  ENOTSUP
00266 #define DB_OPNOTSUP     ENOTSUP
00267 #else
00268 #define DB_OPNOTSUP     EINVAL
00269 #endif
00270 #endif
00271 
00272 /*******************************************************
00273  * Files.
00274  *******************************************************/
00275 /*
00276  * We use 1024 as the maximum path length.  It's too hard to figure out what
00277  * the real path length is, as it was traditionally stored in <sys/param.h>,
00278  * and that file isn't always available.
00279  */
00280 #undef  MAXPATHLEN
00281 #define MAXPATHLEN      1024
00282 
00283 #define PATH_DOT        "."     /* Current working directory. */
00284                                 /* Path separator character(s). */
00285 #define PATH_SEPARATOR  "\\/:"
00286 
00287 /*******************************************************
00288  * Environment.
00289  *******************************************************/
00290 /* Type passed to __db_appname(). */
00291 typedef enum {
00292         DB_APP_NONE=0,                  /* No type (region). */
00293         DB_APP_DATA,                    /* Data file. */
00294         DB_APP_LOG,                     /* Log file. */
00295         DB_APP_TMP                      /* Temporary file. */
00296 } APPNAME;
00297 
00298 /*
00299  * ALIVE_ON     The is_alive function is configured.
00300  * CDB_LOCKING  CDB product locking.
00301  * CRYPTO_ON    Security has been configured.
00302  * LOCKING_ON   Locking has been configured.
00303  * LOGGING_ON   Logging has been configured.
00304  * MUTEX_ON     Mutexes have been configured.
00305  * MPOOL_ON     Memory pool has been configured.
00306  * REP_ON       Replication has been configured.
00307  * RPC_ON       RPC has been configured.
00308  * TXN_ON       Transactions have been configured.
00309  */
00310 #define ALIVE_ON(dbenv)         ((dbenv)->is_alive != NULL)
00311 #define CDB_LOCKING(dbenv)      F_ISSET(dbenv, DB_ENV_CDB)
00312 #define CRYPTO_ON(dbenv)        ((dbenv)->crypto_handle != NULL)
00313 #define LOCKING_ON(dbenv)       ((dbenv)->lk_handle != NULL)
00314 #define LOGGING_ON(dbenv)       ((dbenv)->lg_handle != NULL)
00315 #define MPOOL_ON(dbenv)         ((dbenv)->mp_handle != NULL)
00316 #define MUTEX_ON(dbenv)         ((dbenv)->mutex_handle != NULL)
00317 #define REP_ON(dbenv)           ((dbenv)->rep_handle != NULL)
00318 #define RPC_ON(dbenv)           ((dbenv)->cl_handle != NULL)
00319 #define TXN_ON(dbenv)           ((dbenv)->tx_handle != NULL)
00320 
00321 /*
00322  * STD_LOCKING  Standard locking, that is, locking was configured and CDB
00323  *              was not.  We do not do locking in off-page duplicate trees,
00324  *              so we check for that in the cursor first.
00325  */
00326 #define STD_LOCKING(dbc)                                                \
00327         (!F_ISSET(dbc, DBC_OPD) &&                                      \
00328             !CDB_LOCKING((dbc)->dbp->dbenv) && LOCKING_ON((dbc)->dbp->dbenv))
00329 
00330 /*
00331  * IS_RECOVERING: The system is running recovery.
00332  */
00333 #define IS_RECOVERING(dbenv)                                            \
00334         (LOGGING_ON(dbenv) &&                                           \
00335             F_ISSET((DB_LOG *)(dbenv)->lg_handle, DBLOG_RECOVER))
00336 
00337 /* Initialization methods are often illegal before/after open is called. */
00338 #define ENV_ILLEGAL_AFTER_OPEN(dbenv, name)                             \
00339         if (F_ISSET((dbenv), DB_ENV_OPEN_CALLED))                       \
00340                 return (__db_mi_open(dbenv, name, 1));
00341 #define ENV_ILLEGAL_BEFORE_OPEN(dbenv, name)                            \
00342         if (!F_ISSET((dbenv), DB_ENV_OPEN_CALLED))                      \
00343                 return (__db_mi_open(dbenv, name, 0));
00344 
00345 /* We're not actually user hostile, honest. */
00346 #define ENV_REQUIRES_CONFIG(dbenv, handle, i, flags)                    \
00347         if (handle == NULL)                                             \
00348                 return (__db_env_config(dbenv, i, flags));
00349 #define ENV_NOT_CONFIGURED(dbenv, handle, i, flags)                     \
00350         if (F_ISSET((dbenv), DB_ENV_OPEN_CALLED))                       \
00351                 ENV_REQUIRES_CONFIG(dbenv, handle, i, flags)
00352 
00353 #define ENV_ENTER(dbenv, ip) do {                                       \
00354         int __ret;                                                      \
00355         if ((dbenv)->thr_hashtab == NULL)                               \
00356                 ip = NULL;                                              \
00357         else {                                                          \
00358                 if ((__ret =                                            \
00359                     __env_set_state(dbenv, &(ip), THREAD_ACTIVE)) != 0) \
00360                         return (__ret);                                 \
00361         }                                                               \
00362 } while (0)
00363 
00364 #ifdef DIAGNOSTIC
00365 #define ENV_LEAVE(dbenv, ip) do {                                       \
00366         if ((ip) != NULL) {                                             \
00367                 DB_ASSERT(ip->dbth_state == THREAD_ACTIVE);             \
00368                 (ip)->dbth_state = THREAD_OUT;                          \
00369         }                                                               \
00370 } while (0)
00371 #else
00372 #define ENV_LEAVE(dbenv, ip) do {                                       \
00373         if ((ip) != NULL)                                               \
00374                 (ip)->dbth_state = THREAD_OUT;                          \
00375 } while (0)
00376 #endif
00377 #ifdef DIAGNOSTIC
00378 #define CHECK_THREAD(dbenv) do {                                        \
00379         DB_THREAD_INFO *__ip;                                           \
00380         if ((dbenv)->thr_hashtab != NULL) {                             \
00381                 (void)__env_set_state(dbenv, &__ip, THREAD_DIAGNOSTIC); \
00382                 DB_ASSERT(__ip != NULL &&                               \
00383                      __ip->dbth_state != THREAD_OUT);                   \
00384         }                                                               \
00385 } while (0)
00386 #define CHECK_MTX_THREAD(dbenv, mtx) do {                               \
00387         if (mtx->alloc_id != MTX_MUTEX_REGION &&                        \
00388             mtx->alloc_id != MTX_ENV_REGION &&                          \
00389             mtx->alloc_id != MTX_APPLICATION)                           \
00390                 CHECK_THREAD(dbenv);                                    \
00391 } while (0)
00392 #else
00393 #define CHECK_THREAD(dbenv)
00394 #define CHECK_MTX_THREAD(dbenv, mtx)
00395 #endif
00396 
00397 typedef enum {
00398         THREAD_SLOT_NOT_IN_USE=0,
00399         THREAD_OUT,
00400         THREAD_ACTIVE,
00401         THREAD_BLOCKED
00402 #ifdef DIAGNOSTIC
00403         , THREAD_DIAGNOSTIC
00404 #endif
00405 } DB_THREAD_STATE;
00406 
00407 typedef struct __db_thread_info {
00408         pid_t           dbth_pid;
00409         db_threadid_t   dbth_tid;
00410         DB_THREAD_STATE dbth_state;
00411         SH_TAILQ_ENTRY  dbth_links;
00412 } DB_THREAD_INFO;
00413 
00414 typedef struct __env_thread_info {
00415         u_int32_t       thr_count;
00416         u_int32_t       thr_max;
00417         u_int32_t       thr_nbucket;
00418         roff_t          thr_hashoff;
00419 } THREAD_INFO;
00420 
00421 /*******************************************************
00422  * Database Access Methods.
00423  *******************************************************/
00424 /*
00425  * DB_IS_THREADED --
00426  *      The database handle is free-threaded (was opened with DB_THREAD).
00427  */
00428 #define DB_IS_THREADED(dbp)                                             \
00429         ((dbp)->mutex != MUTEX_INVALID)
00430 
00431 /* Initialization methods are often illegal before/after open is called. */
00432 #define DB_ILLEGAL_AFTER_OPEN(dbp, name)                                \
00433         if (F_ISSET((dbp), DB_AM_OPEN_CALLED))                          \
00434                 return (__db_mi_open((dbp)->dbenv, name, 1));
00435 #define DB_ILLEGAL_BEFORE_OPEN(dbp, name)                               \
00436         if (!F_ISSET((dbp), DB_AM_OPEN_CALLED))                         \
00437                 return (__db_mi_open((dbp)->dbenv, name, 0));
00438 /* Some initialization methods are illegal if environment isn't local. */
00439 #define DB_ILLEGAL_IN_ENV(dbp, name)                                    \
00440         if (!F_ISSET((dbp)->dbenv, DB_ENV_DBLOCAL))                     \
00441                 return (__db_mi_env((dbp)->dbenv, name));
00442 #define DB_ILLEGAL_METHOD(dbp, flags) {                                 \
00443         int __ret;                                                      \
00444         if ((__ret = __dbh_am_chk(dbp, flags)) != 0)                    \
00445                 return (__ret);                                         \
00446 }
00447 
00448 /*
00449  * Common DBC->internal fields.  Each access method adds additional fields
00450  * to this list, but the initial fields are common.
00451  */
00452 #define __DBC_INTERNAL                                                  \
00453         DBC      *opd;                  /* Off-page duplicate cursor. */\
00454                                                                         \
00455         void     *page;                 /* Referenced page. */          \
00456         db_pgno_t root;                 /* Tree root. */                \
00457         db_pgno_t pgno;                 /* Referenced page number. */   \
00458         db_indx_t indx;                 /* Referenced key item index. */\
00459                                                                         \
00460         DB_LOCK         lock;           /* Cursor lock. */              \
00461         db_lockmode_t   lock_mode;      /* Lock mode. */
00462 
00463 struct __dbc_internal {
00464         __DBC_INTERNAL
00465 };
00466 
00467 /* Actions that __db_master_update can take. */
00468 typedef enum { MU_REMOVE, MU_RENAME, MU_OPEN } mu_action;
00469 
00470 /*
00471  * Access-method-common macro for determining whether a cursor
00472  * has been initialized.
00473  */
00474 #define IS_INITIALIZED(dbc)     ((dbc)->internal->pgno != PGNO_INVALID)
00475 
00476 /* Free the callback-allocated buffer, if necessary, hanging off of a DBT. */
00477 #define FREE_IF_NEEDED(sdbp, dbt)                                       \
00478         if (F_ISSET((dbt), DB_DBT_APPMALLOC)) {                         \
00479                 __os_ufree((sdbp)->dbenv, (dbt)->data);                 \
00480                 F_CLR((dbt), DB_DBT_APPMALLOC);                         \
00481         }
00482 
00483 /*
00484  * Use memory belonging to object "owner" to return the results of
00485  * any no-DBT-flag get ops on cursor "dbc".
00486  */
00487 #define SET_RET_MEM(dbc, owner)                         \
00488         do {                                            \
00489                 (dbc)->rskey = &(owner)->my_rskey;      \
00490                 (dbc)->rkey = &(owner)->my_rkey;        \
00491                 (dbc)->rdata = &(owner)->my_rdata;      \
00492         } while (0)
00493 
00494 /* Use the return-data memory src is currently set to use in dest as well. */
00495 #define COPY_RET_MEM(src, dest)                         \
00496         do {                                            \
00497                 (dest)->rskey = (src)->rskey;           \
00498                 (dest)->rkey = (src)->rkey;             \
00499                 (dest)->rdata = (src)->rdata;           \
00500         } while (0)
00501 
00502 /* Reset the returned-memory pointers to their defaults. */
00503 #define RESET_RET_MEM(dbc)                              \
00504         do {                                            \
00505                 (dbc)->rskey = &(dbc)->my_rskey;        \
00506                 (dbc)->rkey = &(dbc)->my_rkey;          \
00507                 (dbc)->rdata = &(dbc)->my_rdata;        \
00508         } while (0)
00509 
00510 /*******************************************************
00511  * Mpool.
00512  *******************************************************/
00513 /*
00514  * File types for DB access methods.  Negative numbers are reserved to DB.
00515  */
00516 #define DB_FTYPE_SET            -1              /* Call pgin/pgout functions. */
00517 #define DB_FTYPE_NOTSET          0              /* Don't call... */
00518 #define DB_LSN_OFF_NOTSET       -1              /* Not yet set. */
00519 #define DB_CLEARLEN_NOTSET      UINT32_MAX      /* Not yet set. */
00520 
00521 /* Structure used as the DB pgin/pgout pgcookie. */
00522 typedef struct __dbpginfo {
00523         size_t  db_pagesize;            /* Underlying page size. */
00524         u_int32_t flags;                /* Some DB_AM flags needed. */
00525         DBTYPE  type;                   /* DB type */
00526 } DB_PGINFO;
00527 
00528 /*******************************************************
00529  * Log.
00530  *******************************************************/
00531 /* Initialize an LSN to 'zero'. */
00532 #define ZERO_LSN(LSN) do {                                              \
00533         (LSN).file = 0;                                                 \
00534         (LSN).offset = 0;                                               \
00535 } while (0)
00536 #define IS_ZERO_LSN(LSN)        ((LSN).file == 0 && (LSN).offset == 0)
00537 
00538 #define IS_INIT_LSN(LSN)        ((LSN).file == 1 && (LSN).offset == 0)
00539 #define INIT_LSN(LSN)           do {                                    \
00540         (LSN).file = 1;                                                 \
00541         (LSN).offset = 0;                                               \
00542 } while (0)
00543 
00544 #define MAX_LSN(LSN) do {                                               \
00545         (LSN).file = UINT32_MAX;                                        \
00546         (LSN).offset = UINT32_MAX;                                      \
00547 } while (0)
00548 #define IS_MAX_LSN(LSN) \
00549         ((LSN).file == UINT32_MAX && (LSN).offset == UINT32_MAX)
00550 
00551 /* If logging is turned off, smash the lsn. */
00552 #define LSN_NOT_LOGGED(LSN) do {                                        \
00553         (LSN).file = 0;                                                 \
00554         (LSN).offset = 1;                                               \
00555 } while (0)
00556 #define IS_NOT_LOGGED_LSN(LSN) \
00557         ((LSN).file == 0 && (LSN).offset == 1)
00558 
00559 /*******************************************************
00560  * Txn.
00561  *******************************************************/
00562 #define DB_NONBLOCK(C)  ((C)->txn != NULL && F_ISSET((C)->txn, TXN_NOWAIT))
00563 #define NOWAIT_FLAG(txn) \
00564         ((txn) != NULL && F_ISSET((txn), TXN_NOWAIT) ? DB_LOCK_NOWAIT : 0)
00565 #define IS_SUBTRANSACTION(txn)                                          \
00566         ((txn) != NULL && (txn)->parent != NULL)
00567 
00568 /*******************************************************
00569  * Crypto.
00570  *******************************************************/
00571 #define DB_IV_BYTES     16              /* Bytes per IV */
00572 #define DB_MAC_KEY      20              /* Bytes per MAC checksum */
00573 
00574 /*******************************************************
00575  * Secondaries over RPC.
00576  *******************************************************/
00577 #ifdef CONFIG_TEST
00578 /*
00579  * These are flags passed to DB->associate calls by the Tcl API if running
00580  * over RPC.  The RPC server will mask out these flags before making the real
00581  * DB->associate call.
00582  *
00583  * These flags must coexist with the valid flags to DB->associate (currently
00584  * DB_AUTO_COMMIT and DB_CREATE).  DB_AUTO_COMMIT is in the group of
00585  * high-order shared flags (0xff000000), and DB_CREATE is in the low-order
00586  * group (0x00000fff), so we pick a range in between.
00587  */
00588 #define DB_RPC2ND_MASK          0x00f00000 /* Reserved bits. */
00589 
00590 #define DB_RPC2ND_REVERSEDATA   0x00100000 /* callback_n(0) _s_reversedata. */
00591 #define DB_RPC2ND_NOOP          0x00200000 /* callback_n(1) _s_noop */
00592 #define DB_RPC2ND_CONCATKEYDATA 0x00300000 /* callback_n(2) _s_concatkeydata */
00593 #define DB_RPC2ND_CONCATDATAKEY 0x00400000 /* callback_n(3) _s_concatdatakey */
00594 #define DB_RPC2ND_REVERSECONCAT 0x00500000 /* callback_n(4) _s_reverseconcat */
00595 #define DB_RPC2ND_TRUNCDATA     0x00600000 /* callback_n(5) _s_truncdata */
00596 #define DB_RPC2ND_CONSTANT      0x00700000 /* callback_n(6) _s_constant */
00597 #define DB_RPC2ND_GETZIP        0x00800000 /* sj_getzip */
00598 #define DB_RPC2ND_GETNAME       0x00900000 /* sj_getname */
00599 #endif
00600 
00601 /*******************************************************
00602  * Forward structure declarations.
00603  *******************************************************/
00604 struct __db_reginfo_t;  typedef struct __db_reginfo_t REGINFO;
00605 struct __db_txnhead;    typedef struct __db_txnhead DB_TXNHEAD;
00606 struct __db_txnlist;    typedef struct __db_txnlist DB_TXNLIST;
00607 struct __vrfy_childinfo;typedef struct __vrfy_childinfo VRFY_CHILDINFO;
00608 struct __vrfy_dbinfo;   typedef struct __vrfy_dbinfo VRFY_DBINFO;
00609 struct __vrfy_pageinfo; typedef struct __vrfy_pageinfo VRFY_PAGEINFO;
00610 
00611 #if defined(__cplusplus)
00612 }
00613 #endif
00614 
00615 /*******************************************************
00616  * Remaining general DB includes.
00617  *******************************************************/
00618 
00619 
00620 #include "dbinc/globals.h"
00621 #include "dbinc/debug.h"
00622 #include "dbinc/region.h"
00623 #include "dbinc_auto/env_ext.h"
00624 #include "dbinc/mutex.h"
00625 #include "dbinc/os.h"
00626 #include "dbinc/rep.h"
00627 #include "dbinc_auto/clib_ext.h"
00628 #include "dbinc_auto/common_ext.h"
00629 
00630 /*******************************************************
00631  * Remaining Log.
00632  * These need to be defined after the general includes
00633  * because they need rep.h from above.
00634  *******************************************************/
00635 /*
00636  * Test if the environment is currently logging changes.  If we're in recovery
00637  * or we're a replication client, we don't need to log changes because they're
00638  * already in the log, even though we have a fully functional log system.
00639  */
00640 #define DBENV_LOGGING(dbenv)                                            \
00641         (LOGGING_ON(dbenv) && !IS_REP_CLIENT(dbenv) &&                  \
00642             (!IS_RECOVERING(dbenv)))
00643 
00644 /*
00645  * Test if we need to log a change.  By default, we don't log operations without
00646  * associated transactions, unless DIAGNOSTIC, DEBUG_ROP or DEBUG_WOP are on.
00647  * This is because we want to get log records for read/write operations, and, if
00648  * we trying to debug something, more information is always better.
00649  *
00650  * The DBC_RECOVER flag is set when we're in abort, as well as during recovery;
00651  * thus DBC_LOGGING may be false for a particular dbc even when DBENV_LOGGING
00652  * is true.
00653  *
00654  * We explicitly use LOGGING_ON/IS_REP_CLIENT here because we don't want to pull
00655  * in the log headers, which IS_RECOVERING (and thus DBENV_LOGGING) rely on, and
00656  * because DBC_RECOVER should be set anytime IS_RECOVERING would be true.
00657  *
00658  * If we're not in recovery (master - doing an abort a client applying
00659  * a txn), then a client's only path through here is on an internal
00660  * operation, and a master's only path through here is a transactional
00661  * operation.  Detect if either is not the case.
00662  */
00663 #if defined(DIAGNOSTIC) || defined(DEBUG_ROP)  || defined(DEBUG_WOP)
00664 #define DBC_LOGGING(dbc)        __dbc_logging(dbc)
00665 #else
00666 #define DBC_LOGGING(dbc)                                                \
00667         ((dbc)->txn != NULL && LOGGING_ON((dbc)->dbp->dbenv) &&         \
00668             !F_ISSET((dbc), DBC_RECOVER) && !IS_REP_CLIENT((dbc)->dbp->dbenv))
00669 #endif
00670 
00671 #endif /* !_DB_INTERNAL_H_ */

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