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

db.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.in,v 12.67 2005/11/10 21:10:24 bostic Exp $
00009  *
00010  * db.h include file layout:
00011  *      General.
00012  *      Database Environment.
00013  *      Locking subsystem.
00014  *      Logging subsystem.
00015  *      Shared buffer cache (mpool) subsystem.
00016  *      Transaction subsystem.
00017  *      Access methods.
00018  *      Access method cursors.
00019  *      Dbm/Ndbm, Hsearch historic interfaces.
00020  */
00021 
00022 #ifndef _DB_H_
00023 #define _DB_H_
00024 
00025 #ifndef __NO_SYSTEM_INCLUDES
00026 #include <sys/types.h>
00027 #include <stddef.h>
00028 #include <stdio.h>
00029 #endif
00030 
00031 #if defined(__cplusplus)
00032 extern "C" {
00033 #endif
00034 
00035 
00036 #undef __P
00037 #define __P(protos)     protos
00038 
00039 /*
00040  * Berkeley DB version information.
00041  */
00042 #define DB_VERSION_MAJOR        4
00043 #define DB_VERSION_MINOR        4
00044 #define DB_VERSION_PATCH        16
00045 #define DB_VERSION_STRING       "Sleepycat Software: Berkeley DB 4.4.16: (November 12, 2005)"
00046 
00047 /*
00048  * !!!
00049  * Berkeley DB uses specifically sized types.  If they're not provided by
00050  * the system, typedef them here.
00051  *
00052  * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
00053  * as does BIND and Kerberos, since we don't know for sure what #include
00054  * files the user is using.
00055  *
00056  * !!!
00057  * We also provide the standard u_int, u_long etc., if they're not provided
00058  * by the system.
00059  */
00060 #ifndef __BIT_TYPES_DEFINED__
00061 #define __BIT_TYPES_DEFINED__
00062 typedef unsigned char u_int8_t;
00063 typedef short int16_t;
00064 typedef unsigned short u_int16_t;
00065 typedef int int32_t;
00066 typedef unsigned int u_int32_t;
00067 typedef __int64 int64_t;
00068 typedef unsigned __int64 u_int64_t;
00069 #endif
00070 
00071 #ifndef _WINSOCKAPI_
00072 typedef unsigned char u_char;
00073 typedef unsigned short u_short;
00074 typedef unsigned int u_int;
00075 typedef unsigned long u_long;
00076 #endif
00077 #ifdef _WIN64
00078 typedef int64_t ssize_t;
00079 #else
00080 typedef int32_t ssize_t;
00081 #endif
00082 
00083 /*
00084  * uintmax_t --
00085  * Largest unsigned type, used to align structures in memory.  We don't store
00086  * floating point types in structures, so integral types should be sufficient
00087  * (and we don't have to worry about systems that store floats in other than
00088  * power-of-2 numbers of bytes).  Additionally this fixes compilers that rewrite
00089  * structure assignments and ANSI C memcpy calls to be in-line instructions
00090  * that happen to require alignment.
00091  *
00092  * uintptr_t --
00093  * Unsigned type that's the same size as a pointer.  There are places where
00094  * DB modifies pointers by discarding the bottom bits to guarantee alignment.
00095  * We can't use uintmax_t, it may be larger than the pointer, and compilers
00096  * get upset about that.  So far we haven't run on any machine where there's
00097  * no unsigned type the same size as a pointer -- here's hoping.
00098  */
00099 typedef u_int64_t uintmax_t;
00100 #ifdef _WIN64
00101 typedef u_int64_t uintptr_t;
00102 #else
00103 typedef u_int32_t uintptr_t;
00104 #endif
00105 
00106 /*
00107  * Sequences are only available on machines with 64-bit integral types.
00108  */
00109 typedef int64_t db_seq_t;
00110 
00111 /* Thread and process identification. */
00112 typedef u_int32_t db_threadid_t;
00113 typedef int pid_t;
00114 
00115 /* Basic types that are exported or quasi-exported. */
00116 typedef u_int32_t       db_pgno_t;      /* Page number type. */
00117 typedef u_int16_t       db_indx_t;      /* Page offset type. */
00118 #define DB_MAX_PAGES    0xffffffff      /* >= # of pages in a file */
00119 
00120 typedef u_int32_t       db_recno_t;     /* Record number type. */
00121 #define DB_MAX_RECORDS  0xffffffff      /* >= # of records in a tree */
00122 
00123 typedef u_int32_t       db_timeout_t;   /* Type of a timeout. */
00124 
00125 /*
00126  * Region offsets are the difference between a pointer in a region and the
00127  * region's base address.  With private environments, both addresses are the
00128  * result of calling malloc, and we can't assume anything about what malloc
00129  * will return, so region offsets have to be able to hold differences between
00130  * arbitrary pointers.
00131  */
00132 typedef uintptr_t       roff_t;
00133 
00134 /*
00135  * Forward structure declarations, so we can declare pointers and
00136  * applications can get type checking.
00137  */
00138 struct __db;            typedef struct __db DB;
00139 struct __db_bt_stat;    typedef struct __db_bt_stat DB_BTREE_STAT;
00140 struct __db_cipher;     typedef struct __db_cipher DB_CIPHER;
00141 struct __db_compact;    typedef struct __db_compact DB_COMPACT;
00142 struct __db_dbt;        typedef struct __db_dbt DBT;
00143 struct __db_env;        typedef struct __db_env DB_ENV;
00144 struct __db_h_stat;     typedef struct __db_h_stat DB_HASH_STAT;
00145 struct __db_ilock;      typedef struct __db_ilock DB_LOCK_ILOCK;
00146 struct __db_lock_stat;  typedef struct __db_lock_stat DB_LOCK_STAT;
00147 struct __db_lock_u;     typedef struct __db_lock_u DB_LOCK;
00148 struct __db_lockreq;    typedef struct __db_lockreq DB_LOCKREQ;
00149 struct __db_log_cursor; typedef struct __db_log_cursor DB_LOGC;
00150 struct __db_log_stat;   typedef struct __db_log_stat DB_LOG_STAT;
00151 struct __db_lsn;        typedef struct __db_lsn DB_LSN;
00152 struct __db_mpool;      typedef struct __db_mpool DB_MPOOL;
00153 struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
00154 struct __db_mpool_stat; typedef struct __db_mpool_stat DB_MPOOL_STAT;
00155 struct __db_mpoolfile;  typedef struct __db_mpoolfile DB_MPOOLFILE;
00156 struct __db_mutex_stat; typedef struct __db_mutex_stat DB_MUTEX_STAT;
00157 struct __db_preplist;   typedef struct __db_preplist DB_PREPLIST;
00158 struct __db_qam_stat;   typedef struct __db_qam_stat DB_QUEUE_STAT;
00159 struct __db_rep;        typedef struct __db_rep DB_REP;
00160 struct __db_rep_stat;   typedef struct __db_rep_stat DB_REP_STAT;
00161 struct __db_seq_record; typedef struct __db_seq_record DB_SEQ_RECORD;
00162 struct __db_seq_stat;   typedef struct __db_seq_stat DB_SEQUENCE_STAT;
00163 struct __db_sequence;   typedef struct __db_sequence DB_SEQUENCE;
00164 struct __db_txn;        typedef struct __db_txn DB_TXN;
00165 struct __db_txn_active; typedef struct __db_txn_active DB_TXN_ACTIVE;
00166 struct __db_txn_stat;   typedef struct __db_txn_stat DB_TXN_STAT;
00167 struct __db_txnmgr;     typedef struct __db_txnmgr DB_TXNMGR;
00168 struct __dbc;           typedef struct __dbc DBC;
00169 struct __dbc_internal;  typedef struct __dbc_internal DBC_INTERNAL;
00170 struct __fh_t;          typedef struct __fh_t DB_FH;
00171 struct __fname;         typedef struct __fname FNAME;
00172 struct __key_range;     typedef struct __key_range DB_KEY_RANGE;
00173 struct __mpoolfile;     typedef struct __mpoolfile MPOOLFILE;
00174 
00175 /* Key/data structure -- a Data-Base Thang. */
00176 struct __db_dbt {
00177         void     *data;                 /* Key/data */
00178         u_int32_t size;                 /* key/data length */
00179 
00180         u_int32_t ulen;                 /* RO: length of user buffer. */
00181         u_int32_t dlen;                 /* RO: get/put record length. */
00182         u_int32_t doff;                 /* RO: get/put record offset. */
00183 
00184 #define DB_DBT_APPMALLOC        0x001   /* Callback allocated memory. */
00185 #define DB_DBT_ISSET            0x002   /* Lower level calls set value. */
00186 #define DB_DBT_MALLOC           0x004   /* Return in malloc'd memory. */
00187 #define DB_DBT_PARTIAL          0x008   /* Partial put/get. */
00188 #define DB_DBT_REALLOC          0x010   /* Return in realloc'd memory. */
00189 #define DB_DBT_USERMEM          0x020   /* Return in user's memory. */
00190 #define DB_DBT_DUPOK            0x040   /* Insert if duplicate. */
00191         u_int32_t flags;
00192 };
00193 
00194 /*
00195  * Common flags --
00196  *      Interfaces which use any of these common flags should never have
00197  *      interface specific flags in this range.
00198  */
00199 #define DB_CREATE             0x0000001 /* Create file as necessary. */
00200 #define DB_DURABLE_UNKNOWN    0x0000002 /* Durability on open (internal). */
00201 #define DB_FORCE              0x0000004 /* Force (anything). */
00202 #define DB_NOMMAP             0x0000008 /* Don't mmap underlying file. */
00203 #define DB_RDONLY             0x0000010 /* Read-only (O_RDONLY). */
00204 #define DB_RECOVER            0x0000020 /* Run normal recovery. */
00205 #define DB_THREAD             0x0000040 /* Applications are threaded. */
00206 #define DB_TRUNCATE           0x0000080 /* Discard existing DB (O_TRUNC). */
00207 #define DB_TXN_NOSYNC         0x0000100 /* Do not sync log on commit. */
00208 #define DB_TXN_NOT_DURABLE    0x0000200 /* Do not log changes. */
00209 #define DB_TXN_WRITE_NOSYNC   0x0000400 /* Write the log but don't sync. */
00210 #define DB_USE_ENVIRON        0x0000800 /* Use the environment. */
00211 #define DB_USE_ENVIRON_ROOT   0x0001000 /* Use the environment if root. */
00212 
00213 /*
00214  * Common flags --
00215  *      Interfaces which use any of these common flags should never have
00216  *      interface specific flags in this range.
00217  *
00218  * DB_AUTO_COMMIT:
00219  *      DB_ENV->set_flags, DB->open
00220  *      (Note: until the 4.3 release, legal to DB->associate, DB->del,
00221  *      DB->put, DB->remove, DB->rename and DB->truncate, and others.)
00222  * DB_READ_COMMITTED:
00223  *      DB->cursor, DB->get, DB->join, DBcursor->c_get, DB_ENV->txn_begin
00224  * DB_READ_UNCOMMITTED:
00225  *      DB->cursor, DB->get, DB->join, DB->open, DBcursor->c_get,
00226  *      DB_ENV->txn_begin
00227  *
00228  * !!!
00229  * The DB_READ_COMMITTED and DB_READ_UNCOMMITTED bit masks can't be changed
00230  * without also changing the masks for the flags that can be OR'd into DB
00231  * access method and cursor operation values.
00232  */
00233 #define DB_AUTO_COMMIT        0x01000000/* Implied transaction. */
00234 
00235 #define DB_READ_COMMITTED     0x02000000/* Degree 2 isolation. */
00236 #define DB_DEGREE_2           0x02000000/*      Historic name. */
00237 
00238 #define DB_READ_UNCOMMITTED   0x04000000/* Degree 1 isolation. */
00239 #define DB_DIRTY_READ         0x04000000/*      Historic name. */
00240 
00241 /*
00242  * Flags common to db_env_create and db_create.
00243  */
00244 #define DB_CXX_NO_EXCEPTIONS  0x0000001 /* C++: return error values. */
00245 
00246 /*
00247  * Flags private to db_env_create.
00248  *         Shared flags up to 0x0000001 */
00249 #define DB_RPCCLIENT          0x0000002 /* An RPC client environment. */
00250 
00251 /*
00252  * Flags private to db_create.
00253  *         Shared flags up to 0x0000001 */
00254 #define DB_XA_CREATE          0x0000002 /* Open in an XA environment. */
00255 
00256 /*
00257  * Flags private to DB_ENV->open.
00258  *         Shared flags up to 0x0001000 */
00259 #define DB_INIT_CDB           0x0002000 /* Concurrent Access Methods. */
00260 #define DB_INIT_LOCK          0x0004000 /* Initialize locking. */
00261 #define DB_INIT_LOG           0x0008000 /* Initialize logging. */
00262 #define DB_INIT_MPOOL         0x0010000 /* Initialize mpool. */
00263 #define DB_INIT_REP           0x0020000 /* Initialize replication. */
00264 #define DB_INIT_TXN           0x0040000 /* Initialize transactions. */
00265 #define DB_LOCKDOWN           0x0080000 /* Lock memory into physical core. */
00266 #define DB_PRIVATE            0x0100000 /* DB_ENV is process local. */
00267 #define DB_RECOVER_FATAL      0x0200000 /* Run catastrophic recovery. */
00268 #define DB_REGISTER           0x0400000 /* Multi-process registry. */
00269 #define DB_SYSTEM_MEM         0x0800000 /* Use system-backed memory. */
00270 
00271 #define DB_JOINENV            0x0       /* Compatibility. */
00272 
00273 /*
00274  * Flags private to DB->open.
00275  *         Shared flags up to 0x0001000 */
00276 #define DB_EXCL               0x0002000 /* Exclusive open (O_EXCL). */
00277 #define DB_FCNTL_LOCKING      0x0004000 /* UNDOC: fcntl(2) locking. */
00278 #define DB_NO_AUTO_COMMIT     0x0008000 /* Override env-wide AUTOCOMMIT. */
00279 #define DB_RDWRMASTER         0x0010000 /* UNDOC: allow subdb master open R/W */
00280 #define DB_WRITEOPEN          0x0020000 /* UNDOC: open with write lock. */
00281 
00282 /*
00283  * Flags private to DB->associate.
00284  *         Shared flags up to 0x0001000 */
00285 #define DB_IMMUTABLE_KEY      0x0002000 /* Secondary key is immutable. */
00286 /*            Shared flags at 0x1000000 */
00287 
00288 /*
00289  * Flags private to DB_ENV->txn_begin.
00290  *         Shared flags up to 0x0001000 */
00291 #define DB_TXN_NOWAIT         0x0002000 /* Do not wait for locks in this TXN. */
00292 #define DB_TXN_SYNC           0x0004000 /* Always sync log on commit. */
00293 
00294 /*
00295  * Flags private to DB_ENV->set_encrypt.
00296  */
00297 #define DB_ENCRYPT_AES        0x0000001 /* AES, assumes SHA1 checksum */
00298 
00299 /*
00300  * Flags private to DB_ENV->set_flags.
00301  *         Shared flags up to 0x00001000 */
00302 #define DB_CDB_ALLDB          0x00002000/* Set CDB locking per environment. */
00303 #define DB_DIRECT_DB          0x00004000/* Don't buffer databases in the OS. */
00304 #define DB_DIRECT_LOG         0x00008000/* Don't buffer log files in the OS. */
00305 #define DB_DSYNC_DB           0x00010000/* Set O_DSYNC on the databases. */
00306 #define DB_DSYNC_LOG          0x00020000/* Set O_DSYNC on the log. */
00307 #define DB_LOG_AUTOREMOVE     0x00040000/* Automatically remove log files. */
00308 #define DB_LOG_INMEMORY       0x00080000/* Store logs in buffers in memory. */
00309 #define DB_NOLOCKING          0x00100000/* Set locking/mutex behavior. */
00310 #define DB_NOPANIC            0x00200000/* Set panic state per DB_ENV. */
00311 #define DB_OVERWRITE          0x00400000/* Overwrite unlinked region files. */
00312 #define DB_PANIC_ENVIRONMENT  0x00800000/* Set panic state per environment. */
00313 /*            Shared flags at 0x01000000 */
00314 /*            Shared flags at 0x02000000 */
00315 /*            Shared flags at 0x04000000 */
00316 #define DB_REGION_INIT        0x08000000/* Page-fault regions on open. */
00317 #define DB_TIME_NOTGRANTED    0x10000000/* Return NOTGRANTED on timeout. */
00318 #define DB_YIELDCPU           0x20000000/* Yield the CPU (a lot). */
00319 
00320 /*
00321  * Flags private to DB->set_feedback's callback.
00322  */
00323 #define DB_UPGRADE            0x0000001 /* Upgrading. */
00324 #define DB_VERIFY             0x0000002 /* Verifying. */
00325 
00326 /*
00327  * Flags private to DB->compact.
00328  *         Shared flags up to 0x00001000
00329  */
00330 #define DB_FREELIST_ONLY      0x00002000 /* Just sort and truncate. */
00331 #define DB_FREE_SPACE         0x00004000 /* Free space . */
00332 #define DB_COMPACT_FLAGS      \
00333       (DB_FREELIST_ONLY | DB_FREE_SPACE)
00334 
00335 /*
00336  * Flags private to DB_MPOOLFILE->open.
00337  *         Shared flags up to 0x0001000 */
00338 #define DB_DIRECT             0x0002000 /* Don't buffer the file in the OS. */
00339 #define DB_EXTENT             0x0004000 /* internal: dealing with an extent. */
00340 #define DB_ODDFILESIZE        0x0008000 /* Truncate file to N * pgsize. */
00341 
00342 /*
00343  * Flags private to DB->set_flags.
00344  *         Shared flags up to 0x00001000 */
00345 #define DB_CHKSUM             0x00002000 /* Do checksumming */
00346 #define DB_DUP                0x00004000 /* Btree, Hash: duplicate keys. */
00347 #define DB_DUPSORT            0x00008000 /* Btree, Hash: duplicate keys. */
00348 #define DB_ENCRYPT            0x00010000 /* Btree, Hash: duplicate keys. */
00349 #define DB_INORDER            0x00020000 /* Queue: strict ordering on consume */
00350 #define DB_RECNUM             0x00040000 /* Btree: record numbers. */
00351 #define DB_RENUMBER           0x00080000 /* Recno: renumber on insert/delete. */
00352 #define DB_REVSPLITOFF        0x00100000 /* Btree: turn off reverse splits. */
00353 #define DB_SNAPSHOT           0x00200000 /* Recno: snapshot the input. */
00354 
00355 /*
00356  * Flags private to the DB_ENV->stat_print, DB->stat and DB->stat_print methods.
00357  */
00358 #define DB_STAT_ALL           0x0000001 /* Print: Everything. */
00359 #define DB_STAT_CLEAR         0x0000002 /* Clear stat after returning values. */
00360 #define DB_STAT_LOCK_CONF     0x0000004 /* Print: Lock conflict matrix. */
00361 #define DB_STAT_LOCK_LOCKERS  0x0000008 /* Print: Lockers. */
00362 #define DB_STAT_LOCK_OBJECTS  0x0000010 /* Print: Lock objects. */
00363 #define DB_STAT_LOCK_PARAMS   0x0000020 /* Print: Lock parameters. */
00364 #define DB_STAT_MEMP_HASH     0x0000040 /* Print: Mpool hash buckets. */
00365 #define DB_STAT_SUBSYSTEM     0x0000080 /* Print: Subsystems too. */
00366 
00367 /*
00368  * Flags private to DB->join.
00369  */
00370 #define DB_JOIN_NOSORT        0x0000001 /* Don't try to optimize join. */
00371 
00372 /*
00373  * Flags private to DB->verify.
00374  */
00375 #define DB_AGGRESSIVE         0x0000001 /* Salvage whatever could be data.*/
00376 #define DB_NOORDERCHK         0x0000002 /* Skip sort order/hashing check. */
00377 #define DB_ORDERCHKONLY       0x0000004 /* Only perform the order check. */
00378 #define DB_PR_PAGE            0x0000008 /* Show page contents (-da). */
00379 #define DB_PR_RECOVERYTEST    0x0000010 /* Recovery test (-dr). */
00380 #define DB_PRINTABLE          0x0000020 /* Use printable format for salvage. */
00381 #define DB_SALVAGE            0x0000040 /* Salvage what looks like data. */
00382 #define DB_UNREF              0x0000080 /* Report unreferenced pages. */
00383 /*
00384  * !!!
00385  * These must not go over 0x8000, or they will collide with the flags
00386  * used by __bam_vrfy_subtree.
00387  */
00388 
00389 /*
00390  * Flags private to DB->set_rep_transport's send callback.
00391  */
00392 #define DB_REP_ANYWHERE       0x0000001 /* Message can be serviced anywhere. */
00393 #define DB_REP_NOBUFFER       0x0000002 /* Do not buffer this message. */
00394 #define DB_REP_PERMANENT      0x0000004 /* Important--app. may want to flush. */
00395 #define DB_REP_REREQUEST      0x0000008 /* This msg already been requested. */
00396 
00397 /*******************************************************
00398  * Mutexes.
00399  *******************************************************/
00400 typedef u_int32_t       db_mutex_t;
00401 
00402 /*
00403  * Flag arguments for DbEnv.mutex_alloc and for the DB_MUTEX structure.
00404  */
00405 #define DB_MUTEX_ALLOCATED      0x01    /* Mutex currently allocated. */
00406 #define DB_MUTEX_LOCKED         0x02    /* Mutex currently locked. */
00407 #define DB_MUTEX_LOGICAL_LOCK   0x04    /* Mutex backs a database lock. */
00408 #define DB_MUTEX_SELF_BLOCK     0x08    /* Must be able to block self. */
00409 #define DB_MUTEX_THREAD         0x10    /* Thread-only mutex. */
00410 
00411 struct __db_mutex_stat {
00412         /* The following fields are maintained in the region's copy. */
00413         u_int32_t st_mutex_align;       /* Mutex alignment */
00414         u_int32_t st_mutex_tas_spins;   /* Mutex test-and-set spins */
00415         u_int32_t st_mutex_cnt;         /* Mutex count */
00416         u_int32_t st_mutex_free;        /* Available mutexes */
00417         u_int32_t st_mutex_inuse;       /* Mutexes in use */
00418         u_int32_t st_mutex_inuse_max;   /* Maximum mutexes ever in use */
00419 
00420         /* The following fields are filled-in from other places. */
00421         u_int32_t st_region_wait;       /* Region lock granted after wait. */
00422         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
00423         roff_t    st_regsize;           /* Region size. */
00424 };
00425 
00426 /* This is the length of the buffer passed to DB_ENV->thread_id_string() */
00427 #define DB_THREADID_STRLEN      128
00428 
00429 /*******************************************************
00430  * Locking.
00431  *******************************************************/
00432 #define DB_LOCKVERSION  1
00433 
00434 #define DB_FILE_ID_LEN          20      /* Unique file ID length. */
00435 
00436 /*
00437  * Deadlock detector modes; used in the DB_ENV structure to configure the
00438  * locking subsystem.
00439  */
00440 #define DB_LOCK_NORUN           0
00441 #define DB_LOCK_DEFAULT         1       /* Default policy. */
00442 #define DB_LOCK_EXPIRE          2       /* Only expire locks, no detection. */
00443 #define DB_LOCK_MAXLOCKS        3       /* Select locker with max locks. */
00444 #define DB_LOCK_MAXWRITE        4       /* Select locker with max writelocks. */
00445 #define DB_LOCK_MINLOCKS        5       /* Select locker with min locks. */
00446 #define DB_LOCK_MINWRITE        6       /* Select locker with min writelocks. */
00447 #define DB_LOCK_OLDEST          7       /* Select oldest locker. */
00448 #define DB_LOCK_RANDOM          8       /* Select random locker. */
00449 #define DB_LOCK_YOUNGEST        9       /* Select youngest locker. */
00450 
00451 /* Flag values for lock_vec(), lock_get(). */
00452 #define DB_LOCK_ABORT           0x001   /* Internal: Lock during abort. */
00453 #define DB_LOCK_NOWAIT          0x002   /* Don't wait on unavailable lock. */
00454 #define DB_LOCK_RECORD          0x004   /* Internal: record lock. */
00455 #define DB_LOCK_SET_TIMEOUT     0x008   /* Internal: set lock timeout. */
00456 #define DB_LOCK_SWITCH          0x010   /* Internal: switch existing lock. */
00457 #define DB_LOCK_UPGRADE         0x020   /* Internal: upgrade existing lock. */
00458 
00459 /*
00460  * Simple R/W lock modes and for multi-granularity intention locking.
00461  *
00462  * !!!
00463  * These values are NOT random, as they are used as an index into the lock
00464  * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
00465  * must be == 4.
00466  */
00467 typedef enum {
00468         DB_LOCK_NG=0,                   /* Not granted. */
00469         DB_LOCK_READ=1,                 /* Shared/read. */
00470         DB_LOCK_WRITE=2,                /* Exclusive/write. */
00471         DB_LOCK_WAIT=3,                 /* Wait for event */
00472         DB_LOCK_IWRITE=4,               /* Intent exclusive/write. */
00473         DB_LOCK_IREAD=5,                /* Intent to share/read. */
00474         DB_LOCK_IWR=6,                  /* Intent to read and write. */
00475         DB_LOCK_READ_UNCOMMITTED=7,     /* Degree 1 isolation. */
00476         DB_LOCK_WWRITE=8                /* Was Written. */
00477 } db_lockmode_t;
00478 
00479 /*
00480  * Request types.
00481  */
00482 typedef enum {
00483         DB_LOCK_DUMP=0,                 /* Display held locks. */
00484         DB_LOCK_GET=1,                  /* Get the lock. */
00485         DB_LOCK_GET_TIMEOUT=2,          /* Get lock with a timeout. */
00486         DB_LOCK_INHERIT=3,              /* Pass locks to parent. */
00487         DB_LOCK_PUT=4,                  /* Release the lock. */
00488         DB_LOCK_PUT_ALL=5,              /* Release locker's locks. */
00489         DB_LOCK_PUT_OBJ=6,              /* Release locker's locks on obj. */
00490         DB_LOCK_PUT_READ=7,             /* Release locker's read locks. */
00491         DB_LOCK_TIMEOUT=8,              /* Force a txn to timeout. */
00492         DB_LOCK_TRADE=9,                /* Trade locker ids on a lock. */
00493         DB_LOCK_UPGRADE_WRITE=10        /* Upgrade writes for dirty reads. */
00494 } db_lockop_t;
00495 
00496 /*
00497  * Status of a lock.
00498  */
00499 typedef enum  {
00500         DB_LSTAT_ABORTED=1,             /* Lock belongs to an aborted txn. */
00501         DB_LSTAT_EXPIRED=2,             /* Lock has expired. */
00502         DB_LSTAT_FREE=3,                /* Lock is unallocated. */
00503         DB_LSTAT_HELD=4,                /* Lock is currently held. */
00504         DB_LSTAT_PENDING=5,             /* Lock was waiting and has been
00505                                          * promoted; waiting for the owner
00506                                          * to run and upgrade it to held. */
00507         DB_LSTAT_WAITING=6              /* Lock is on the wait queue. */
00508 }db_status_t;
00509 
00510 /* Lock statistics structure. */
00511 struct __db_lock_stat {
00512         u_int32_t st_id;                /* Last allocated locker ID. */
00513         u_int32_t st_cur_maxid;         /* Current maximum unused ID. */
00514         u_int32_t st_maxlocks;          /* Maximum number of locks in table. */
00515         u_int32_t st_maxlockers;        /* Maximum num of lockers in table. */
00516         u_int32_t st_maxobjects;        /* Maximum num of objects in table. */
00517         int       st_nmodes;            /* Number of lock modes. */
00518         u_int32_t st_nlocks;            /* Current number of locks. */
00519         u_int32_t st_maxnlocks;         /* Maximum number of locks so far. */
00520         u_int32_t st_nlockers;          /* Current number of lockers. */
00521         u_int32_t st_maxnlockers;       /* Maximum number of lockers so far. */
00522         u_int32_t st_nobjects;          /* Current number of objects. */
00523         u_int32_t st_maxnobjects;       /* Maximum number of objects so far. */
00524         u_int32_t st_nrequests;         /* Number of lock gets. */
00525         u_int32_t st_nreleases;         /* Number of lock puts. */
00526         u_int32_t st_nupgrade;          /* Number of lock upgrades. */
00527         u_int32_t st_ndowngrade;        /* Number of lock downgrades. */
00528         u_int32_t st_lock_wait;         /* Lock conflicts w/ subsequent wait */
00529         u_int32_t st_lock_nowait;       /* Lock conflicts w/o subsequent wait */
00530         u_int32_t st_ndeadlocks;        /* Number of lock deadlocks. */
00531         db_timeout_t st_locktimeout;    /* Lock timeout. */
00532         u_int32_t st_nlocktimeouts;     /* Number of lock timeouts. */
00533         db_timeout_t st_txntimeout;     /* Transaction timeout. */
00534         u_int32_t st_ntxntimeouts;      /* Number of transaction timeouts. */
00535         u_int32_t st_region_wait;       /* Region lock granted after wait. */
00536         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
00537         roff_t    st_regsize;           /* Region size. */
00538 };
00539 
00540 /*
00541  * DB_LOCK_ILOCK --
00542  *      Internal DB access method lock.
00543  */
00544 struct __db_ilock {
00545         db_pgno_t pgno;                 /* Page being locked. */
00546         u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
00547 #define DB_HANDLE_LOCK  1
00548 #define DB_RECORD_LOCK  2
00549 #define DB_PAGE_LOCK    3
00550         u_int32_t type;                 /* Type of lock. */
00551 };
00552 
00553 /*
00554  * DB_LOCK --
00555  *      The structure is allocated by the caller and filled in during a
00556  *      lock_get request (or a lock_vec/DB_LOCK_GET).
00557  */
00558 struct __db_lock_u {
00559         roff_t          off;            /* Offset of the lock in the region */
00560         u_int32_t       ndx;            /* Index of the object referenced by
00561                                          * this lock; used for locking. */
00562         u_int32_t       gen;            /* Generation number of this lock. */
00563         db_lockmode_t   mode;           /* mode of this lock. */
00564 };
00565 
00566 /* Lock request structure. */
00567 struct __db_lockreq {
00568         db_lockop_t      op;            /* Operation. */
00569         db_lockmode_t    mode;          /* Requested mode. */
00570         db_timeout_t     timeout;       /* Time to expire lock. */
00571         DBT             *obj;           /* Object being locked. */
00572         DB_LOCK          lock;          /* Lock returned. */
00573 };
00574 
00575 /*******************************************************
00576  * Logging.
00577  *******************************************************/
00578 #define DB_LOGVERSION   11              /* Current log version. */
00579 #define DB_LOGOLDVER    11              /* Oldest log version supported. */
00580 #define DB_LOGMAGIC     0x040988
00581 
00582 /* Flag values for DB_ENV->log_archive(). */
00583 #define DB_ARCH_ABS     0x001           /* Absolute pathnames. */
00584 #define DB_ARCH_DATA    0x002           /* Data files. */
00585 #define DB_ARCH_LOG     0x004           /* Log files. */
00586 #define DB_ARCH_REMOVE  0x008   /* Remove log files. */
00587 
00588 /* Flag values for DB_ENV->log_put(). */
00589 #define DB_FLUSH                0x001   /* Flush data to disk (public). */
00590 #define DB_LOG_CHKPNT           0x002   /* Flush supports a checkpoint */
00591 #define DB_LOG_COMMIT           0x004   /* Flush supports a commit */
00592 #define DB_LOG_NOCOPY           0x008   /* Don't copy data */
00593 #define DB_LOG_NOT_DURABLE      0x010   /* Do not log; keep in memory */
00594 #define DB_LOG_PERM             0x020   /* Flag record with REP_PERMANENT */
00595 #define DB_LOG_RESEND           0x040   /* Resent log record */
00596 #define DB_LOG_WRNOSYNC         0x080   /* Write, don't sync log_put */
00597 
00598 /*
00599  * A DB_LSN has two parts, a fileid which identifies a specific file, and an
00600  * offset within that file.  The fileid is an unsigned 4-byte quantity that
00601  * uniquely identifies a file within the log directory -- currently a simple
00602  * counter inside the log.  The offset is also an unsigned 4-byte value.  The
00603  * log manager guarantees the offset is never more than 4 bytes by switching
00604  * to a new log file before the maximum length imposed by an unsigned 4-byte
00605  * offset is reached.
00606  */
00607 struct __db_lsn {
00608         u_int32_t       file;           /* File ID. */
00609         u_int32_t       offset;         /* File offset. */
00610 };
00611 
00612 /*
00613  * Application-specified log record types start at DB_user_BEGIN, and must not
00614  * equal or exceed DB_debug_FLAG.
00615  *
00616  * DB_debug_FLAG is the high-bit of the u_int32_t that specifies a log record
00617  * type.  If the flag is set, it's a log record that was logged for debugging
00618  * purposes only, even if it reflects a database change -- the change was part
00619  * of a non-durable transaction.
00620  */
00621 #define DB_user_BEGIN           10000
00622 #define DB_debug_FLAG           0x80000000
00623 
00624 /*
00625  * DB_LOGC --
00626  *      Log cursor.
00627  */
00628 struct __db_log_cursor {
00629         DB_ENV   *dbenv;                /* Enclosing dbenv. */
00630 
00631         DB_FH    *c_fhp;                /* File handle. */
00632         DB_LSN    c_lsn;                /* Cursor: LSN */
00633         u_int32_t c_len;                /* Cursor: record length */
00634         u_int32_t c_prev;               /* Cursor: previous record's offset */
00635 
00636         DBT       c_dbt;                /* Return DBT. */
00637 
00638 #define DB_LOGC_BUF_SIZE        (32 * 1024)
00639         u_int8_t *bp;                   /* Allocated read buffer. */
00640         u_int32_t bp_size;              /* Read buffer length in bytes. */
00641         u_int32_t bp_rlen;              /* Read buffer valid data length. */
00642         DB_LSN    bp_lsn;               /* Read buffer first byte LSN. */
00643 
00644         u_int32_t bp_maxrec;            /* Max record length in the log file. */
00645 
00646         /* DB_LOGC PUBLIC HANDLE LIST BEGIN */
00647         int (*close) __P((DB_LOGC *, u_int32_t));
00648         int (*get) __P((DB_LOGC *, DB_LSN *, DBT *, u_int32_t));
00649         /* DB_LOGC PUBLIC HANDLE LIST END */
00650 
00651 #define DB_LOG_DISK             0x01    /* Log record came from disk. */
00652 #define DB_LOG_LOCKED           0x02    /* Log region already locked */
00653 #define DB_LOG_SILENT_ERR       0x04    /* Turn-off error messages. */
00654         u_int32_t flags;
00655 };
00656 
00657 /* Log statistics structure. */
00658 struct __db_log_stat {
00659         u_int32_t st_magic;             /* Log file magic number. */
00660         u_int32_t st_version;           /* Log file version number. */
00661         int       st_mode;              /* Log file permissions mode. */
00662         u_int32_t st_lg_bsize;          /* Log buffer size. */
00663         u_int32_t st_lg_size;           /* Log file size. */
00664         u_int32_t st_record;            /* Records entered into the log. */
00665         u_int32_t st_w_bytes;           /* Bytes to log. */
00666         u_int32_t st_w_mbytes;          /* Megabytes to log. */
00667         u_int32_t st_wc_bytes;          /* Bytes to log since checkpoint. */
00668         u_int32_t st_wc_mbytes;         /* Megabytes to log since checkpoint. */
00669         u_int32_t st_wcount;            /* Total I/O writes to the log. */
00670         u_int32_t st_wcount_fill;       /* Overflow writes to the log. */
00671         u_int32_t st_rcount;            /* Total I/O reads from the log. */
00672         u_int32_t st_scount;            /* Total syncs to the log. */
00673         u_int32_t st_region_wait;       /* Region lock granted after wait. */
00674         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
00675         u_int32_t st_cur_file;          /* Current log file number. */
00676         u_int32_t st_cur_offset;        /* Current log file offset. */
00677         u_int32_t st_disk_file;         /* Known on disk log file number. */
00678         u_int32_t st_disk_offset;       /* Known on disk log file offset. */
00679         roff_t    st_regsize;           /* Region size. */
00680         u_int32_t st_maxcommitperflush; /* Max number of commits in a flush. */
00681         u_int32_t st_mincommitperflush; /* Min number of commits in a flush. */
00682 };
00683 
00684 /*
00685  * We need to record the first log record of a transaction.  For user
00686  * defined logging this macro returns the place to put that information,
00687  * if it is need in rlsnp, otherwise it leaves it unchanged.  We also
00688  * need to track the last record of the transaction, this returns the
00689  * place to put that info.
00690  */
00691 #define DB_SET_TXN_LSNP(txn, blsnp, llsnp)              \
00692         ((txn)->set_txn_lsnp(txn, blsnp, llsnp))
00693 
00694 /*******************************************************
00695  * Shared buffer cache (mpool).
00696  *******************************************************/
00697 /* Flag values for DB_MPOOLFILE->get. */
00698 #define DB_MPOOL_CREATE         0x001   /* Create a page. */
00699 #define DB_MPOOL_LAST           0x002   /* Return the last page. */
00700 #define DB_MPOOL_NEW            0x004   /* Create a new page. */
00701 #define DB_MPOOL_FREE           0x008   /* Free page if present. */
00702 
00703 /* Flag values for DB_MPOOLFILE->put, DB_MPOOLFILE->set. */
00704 #define DB_MPOOL_CLEAN          0x001   /* Page is not modified. */
00705 #define DB_MPOOL_DIRTY          0x002   /* Page is modified. */
00706 #define DB_MPOOL_DISCARD        0x004   /* Don't cache the page. */
00707 
00708 /* Flags values for DB_MPOOLFILE->set_flags. */
00709 #define DB_MPOOL_NOFILE         0x001   /* Never open a backing file. */
00710 #define DB_MPOOL_UNLINK         0x002   /* Unlink the file on last close. */
00711 
00712 /* Priority values for DB_MPOOLFILE->set_priority. */
00713 typedef enum {
00714         DB_PRIORITY_VERY_LOW=1,
00715         DB_PRIORITY_LOW=2,
00716         DB_PRIORITY_DEFAULT=3,
00717         DB_PRIORITY_HIGH=4,
00718         DB_PRIORITY_VERY_HIGH=5
00719 } DB_CACHE_PRIORITY;
00720 
00721 /* Per-process DB_MPOOLFILE information. */
00722 struct __db_mpoolfile {
00723         DB_FH     *fhp;                 /* Underlying file handle. */
00724 
00725         /*
00726          * !!!
00727          * The ref, pinref and q fields are protected by the region lock.
00728          */
00729         u_int32_t  ref;                 /* Reference count. */
00730 
00731         u_int32_t pinref;               /* Pinned block reference count. */
00732 
00733         /*
00734          * !!!
00735          * Explicit representations of structures from queue.h.
00736          * TAILQ_ENTRY(__db_mpoolfile) q;
00737          */
00738         struct {
00739                 struct __db_mpoolfile *tqe_next;
00740                 struct __db_mpoolfile **tqe_prev;
00741         } q;                            /* Linked list of DB_MPOOLFILE's. */
00742 
00743         /*
00744          * !!!
00745          * The rest of the fields (with the exception of the MP_FLUSH flag)
00746          * are not thread-protected, even when they may be modified at any
00747          * time by the application.  The reason is the DB_MPOOLFILE handle
00748          * is single-threaded from the viewpoint of the application, and so
00749          * the only fields needing to be thread-protected are those accessed
00750          * by checkpoint or sync threads when using DB_MPOOLFILE structures
00751          * to flush buffers from the cache.
00752          */
00753         DB_ENV         *dbenv;          /* Overlying DB_ENV. */
00754         MPOOLFILE      *mfp;            /* Underlying MPOOLFILE. */
00755 
00756         u_int32_t       clear_len;      /* Cleared length on created pages. */
00757         u_int8_t                        /* Unique file ID. */
00758                         fileid[DB_FILE_ID_LEN];
00759         int             ftype;          /* File type. */
00760         int32_t         lsn_offset;     /* LSN offset in page. */
00761         u_int32_t       gbytes, bytes;  /* Maximum file size. */
00762         DBT            *pgcookie;       /* Byte-string passed to pgin/pgout. */
00763         int32_t         priority;       /* Cache priority. */
00764 
00765         void           *addr;           /* Address of mmap'd region. */
00766         size_t          len;            /* Length of mmap'd region. */
00767 
00768         u_int32_t       config_flags;   /* Flags to DB_MPOOLFILE->set_flags. */
00769 
00770         /* DB_MPOOLFILE PUBLIC HANDLE LIST BEGIN */
00771         int (*close) __P((DB_MPOOLFILE *, u_int32_t));
00772         int (*get) __P((DB_MPOOLFILE *, db_pgno_t *, u_int32_t, void *));
00773         int (*open) __P((DB_MPOOLFILE *, const char *, u_int32_t, int, size_t));
00774         int (*put) __P((DB_MPOOLFILE *, void *, u_int32_t));
00775         int (*set) __P((DB_MPOOLFILE *, void *, u_int32_t));
00776         int (*get_clear_len) __P((DB_MPOOLFILE *, u_int32_t *));
00777         int (*set_clear_len) __P((DB_MPOOLFILE *, u_int32_t));
00778         int (*get_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
00779         int (*set_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
00780         int (*get_flags) __P((DB_MPOOLFILE *, u_int32_t *));
00781         int (*set_flags) __P((DB_MPOOLFILE *, u_int32_t, int));
00782         int (*get_ftype) __P((DB_MPOOLFILE *, int *));
00783         int (*set_ftype) __P((DB_MPOOLFILE *, int));
00784         int (*get_lsn_offset) __P((DB_MPOOLFILE *, int32_t *));
00785         int (*set_lsn_offset) __P((DB_MPOOLFILE *, int32_t));
00786         int (*get_maxsize) __P((DB_MPOOLFILE *, u_int32_t *, u_int32_t *));
00787         int (*set_maxsize) __P((DB_MPOOLFILE *, u_int32_t, u_int32_t));
00788         int (*get_pgcookie) __P((DB_MPOOLFILE *, DBT *));
00789         int (*set_pgcookie) __P((DB_MPOOLFILE *, DBT *));
00790         int (*get_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY *));
00791         int (*set_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY));
00792         int (*sync) __P((DB_MPOOLFILE *));
00793         /* DB_MPOOLFILE PUBLIC HANDLE LIST END */
00794 
00795         /*
00796          * MP_FILEID_SET, MP_OPEN_CALLED and MP_READONLY do not need to be
00797          * thread protected because they are initialized before the file is
00798          * linked onto the per-process lists, and never modified.
00799          *
00800          * MP_FLUSH is thread protected because it is potentially read/set by
00801          * multiple threads of control.
00802          */
00803 #define MP_FILEID_SET   0x001           /* Application supplied a file ID. */
00804 #define MP_FLUSH        0x002           /* Was opened to flush a buffer. */
00805 #define MP_OPEN_CALLED  0x004           /* File opened. */
00806 #define MP_READONLY     0x008           /* File is readonly. */
00807         u_int32_t  flags;
00808 };
00809 
00810 /* Mpool statistics structure. */
00811 struct __db_mpool_stat {
00812         u_int32_t st_gbytes;            /* Total cache size: GB. */
00813         u_int32_t st_bytes;             /* Total cache size: B. */
00814         u_int32_t st_ncache;            /* Number of caches. */
00815         roff_t    st_regsize;           /* Region size. */
00816         size_t    st_mmapsize;          /* Maximum file size for mmap. */
00817         int       st_maxopenfd;         /* Maximum number of open fd's. */
00818         int       st_maxwrite;          /* Maximum buffers to write. */
00819         int       st_maxwrite_sleep;    /* Sleep after writing max buffers. */
00820         u_int32_t st_map;               /* Pages from mapped files. */
00821         u_int32_t st_cache_hit;         /* Pages found in the cache. */
00822         u_int32_t st_cache_miss;        /* Pages not found in the cache. */
00823         u_int32_t st_page_create;       /* Pages created in the cache. */
00824         u_int32_t st_page_in;           /* Pages read in. */
00825         u_int32_t st_page_out;          /* Pages written out. */
00826         u_int32_t st_ro_evict;          /* Clean pages forced from the cache. */
00827         u_int32_t st_rw_evict;          /* Dirty pages forced from the cache. */
00828         u_int32_t st_page_trickle;      /* Pages written by memp_trickle. */
00829         u_int32_t st_pages;             /* Total number of pages. */
00830         u_int32_t st_page_clean;        /* Clean pages. */
00831         u_int32_t st_page_dirty;        /* Dirty pages. */
00832         u_int32_t st_hash_buckets;      /* Number of hash buckets. */
00833         u_int32_t st_hash_searches;     /* Total hash chain searches. */
00834         u_int32_t st_hash_longest;      /* Longest hash chain searched. */
00835         u_int32_t st_hash_examined;     /* Total hash entries searched. */
00836         u_int32_t st_hash_nowait;       /* Hash lock granted with nowait. */
00837         u_int32_t st_hash_wait;         /* Hash lock granted after wait. */
00838         u_int32_t st_hash_max_wait;     /* Max hash lock granted after wait. */
00839         u_int32_t st_region_nowait;     /* Region lock granted with nowait. */
00840         u_int32_t st_region_wait;       /* Region lock granted after wait. */
00841         u_int32_t st_alloc;             /* Number of page allocations. */
00842         u_int32_t st_alloc_buckets;     /* Buckets checked during allocation. */
00843         u_int32_t st_alloc_max_buckets; /* Max checked during allocation. */
00844         u_int32_t st_alloc_pages;       /* Pages checked during allocation. */
00845         u_int32_t st_alloc_max_pages;   /* Max checked during allocation. */
00846 };
00847 
00848 /* Mpool file statistics structure. */
00849 struct __db_mpool_fstat {
00850         char *file_name;                /* File name. */
00851         u_int32_t st_pagesize;          /* Page size. */
00852         u_int32_t st_map;               /* Pages from mapped files. */
00853         u_int32_t st_cache_hit;         /* Pages found in the cache. */
00854         u_int32_t st_cache_miss;        /* Pages not found in the cache. */
00855         u_int32_t st_page_create;       /* Pages created in the cache. */
00856         u_int32_t st_page_in;           /* Pages read in. */
00857         u_int32_t st_page_out;          /* Pages written out. */
00858 };
00859 
00860 /*******************************************************
00861  * Transactions and recovery.
00862  *******************************************************/
00863 #define DB_TXNVERSION   1
00864 
00865 typedef enum {
00866         DB_TXN_ABORT=0,                 /* Public. */
00867         DB_TXN_APPLY=1,                 /* Public. */
00868         DB_TXN_BACKWARD_ALLOC=2,        /* Internal. */
00869         DB_TXN_BACKWARD_ROLL=3,         /* Public. */
00870         DB_TXN_FORWARD_ROLL=4,          /* Public. */
00871         DB_TXN_OPENFILES=5,             /* Internal. */
00872         DB_TXN_POPENFILES=6,            /* Internal. */
00873         DB_TXN_PRINT=7                  /* Public. */
00874 } db_recops;
00875 
00876 /*
00877  * BACKWARD_ALLOC is used during the forward pass to pick up any aborted
00878  * allocations for files that were created during the forward pass.
00879  * The main difference between _ALLOC and _ROLL is that the entry for
00880  * the file not exist during the rollforward pass.
00881  */
00882 #define DB_UNDO(op)     ((op) == DB_TXN_ABORT ||                        \
00883                 (op) == DB_TXN_BACKWARD_ROLL || (op) == DB_TXN_BACKWARD_ALLOC)
00884 #define DB_REDO(op)     ((op) == DB_TXN_FORWARD_ROLL || (op) == DB_TXN_APPLY)
00885 
00886 struct __db_txn {
00887         DB_TXNMGR       *mgrp;          /* Pointer to transaction manager. */
00888         DB_TXN          *parent;        /* Pointer to transaction's parent. */
00889 
00890         u_int32_t       txnid;          /* Unique transaction id. */
00891         char            *name;          /* Transaction name */
00892 
00893         db_threadid_t   tid;            /* Thread id for use in MT XA. */
00894         void            *td;            /* Detail structure within region. */
00895         db_timeout_t    lock_timeout;   /* Timeout for locks for this txn. */
00896         db_timeout_t    expire;         /* Time transaction expires. */
00897         void            *txn_list;      /* Undo information for parent. */
00898 
00899         /*
00900          * !!!
00901          * Explicit representations of structures from queue.h.
00902          * TAILQ_ENTRY(__db_txn) links;
00903          * TAILQ_ENTRY(__db_txn) xalinks;
00904          */
00905         struct {
00906                 struct __db_txn *tqe_next;
00907                 struct __db_txn **tqe_prev;
00908         } links;                        /* Links transactions off manager. */
00909         struct {
00910                 struct __db_txn *tqe_next;
00911                 struct __db_txn **tqe_prev;
00912         } xalinks;                      /* Links active XA transactions. */
00913 
00914         /*
00915          * !!!
00916          * Explicit representations of structures from queue.h.
00917          * TAILQ_HEAD(__kids, __db_txn) kids;
00918          */
00919         struct __kids {
00920                 struct __db_txn *tqh_first;
00921                 struct __db_txn **tqh_last;
00922         } kids;
00923 
00924         /*
00925          * !!!
00926          * Explicit representations of structures from queue.h.
00927          * TAILQ_HEAD(__events, __txn_event) events;
00928          */
00929         struct {
00930                 struct __txn_event *tqh_first;
00931                 struct __txn_event **tqh_last;
00932         } events;
00933 
00934         /*
00935          * !!!
00936          * Explicit representations of structures from queue.h.
00937          * STAILQ_HEAD(__logrec, __txn_logrec) logs;
00938          */
00939         struct {
00940                 struct __txn_logrec *stqh_first;
00941                 struct __txn_logrec **stqh_last;
00942         } logs;                         /* Links deferred events. */
00943 
00944         /*
00945          * !!!
00946          * Explicit representations of structures from queue.h.
00947          * TAILQ_ENTRY(__db_txn) klinks;
00948          */
00949         struct {
00950                 struct __db_txn *tqe_next;
00951                 struct __db_txn **tqe_prev;
00952         } klinks;
00953 
00954         void    *api_internal;          /* C++ API private. */
00955         void    *xml_internal;          /* XML API private. */
00956 
00957         u_int32_t       cursors;        /* Number of cursors open for txn */
00958 
00959         /* DB_TXN PUBLIC HANDLE LIST BEGIN */
00960         int       (*abort) __P((DB_TXN *));
00961         int       (*commit) __P((DB_TXN *, u_int32_t));
00962         int       (*discard) __P((DB_TXN *, u_int32_t));
00963         int       (*get_name) __P((DB_TXN *, const char **));
00964         u_int32_t (*id) __P((DB_TXN *));
00965         int       (*prepare) __P((DB_TXN *, u_int8_t *));
00966         int       (*set_name) __P((DB_TXN *, const char *));
00967         int       (*set_timeout) __P((DB_TXN *, db_timeout_t, u_int32_t));
00968         /* DB_TXN PUBLIC HANDLE LIST END */
00969 
00970         /* DB_TXN PRIVATE HANDLE LIST BEGIN */
00971         void      (*set_txn_lsnp) __P((DB_TXN *txn, DB_LSN **, DB_LSN **));
00972         /* DB_TXN PRIVATE HANDLE LIST END */
00973 
00974 #define TXN_CHILDCOMMIT         0x001   /* Txn has committed. */
00975 #define TXN_COMPENSATE          0x002   /* Compensating transaction. */
00976 #define TXN_DEADLOCK            0x004   /* Txn has deadlocked. */
00977 #define TXN_LOCKTIMEOUT         0x008   /* Txn has a lock timeout. */
00978 #define TXN_MALLOC              0x010   /* Structure allocated by TXN system. */
00979 #define TXN_NOSYNC              0x020   /* Do not sync on prepare and commit. */
00980 #define TXN_NOWAIT              0x040   /* Do not wait on locks. */
00981 #define TXN_READ_COMMITTED      0x080   /* Txn has degree 2 isolation. */
00982 #define TXN_READ_UNCOMMITTED    0x100   /* Txn has degree 1 isolation. */
00983 #define TXN_RESTORED            0x200   /* Txn has been restored. */
00984 #define TXN_SYNC                0x400   /* Write and sync on prepare/commit. */
00985 #define TXN_WRITE_NOSYNC        0x800   /* Write only on prepare/commit. */
00986         u_int32_t       flags;
00987 };
00988 
00989 #define TXN_SYNC_FLAGS (TXN_SYNC | TXN_NOSYNC | TXN_WRITE_NOSYNC)
00990 
00991 /*
00992  * Structure used for two phase commit interface.  Berkeley DB support for two
00993  * phase commit is compatible with the X/Open XA interface.
00994  *
00995  * The XA #define XIDDATASIZE defines the size of a global transaction ID.  We
00996  * have our own version here (for name space reasons) which must have the same
00997  * value.
00998  */
00999 #define DB_XIDDATASIZE  128
01000 struct __db_preplist {
01001         DB_TXN  *txn;
01002         u_int8_t gid[DB_XIDDATASIZE];
01003 };
01004 
01005 /* Transaction statistics structure. */
01006 struct __db_txn_active {
01007         u_int32_t txnid;                /* Transaction ID */
01008         u_int32_t parentid;             /* Transaction ID of parent */
01009         pid_t     pid;                  /* Process owning txn ID */
01010         db_threadid_t tid;              /* Thread owning txn ID */
01011         DB_LSN    lsn;                  /* LSN when transaction began */
01012         u_int32_t xa_status;            /* XA status */
01013         u_int8_t  xid[DB_XIDDATASIZE];  /* XA global transaction ID */
01014         char      name[51];             /* 50 bytes of name, nul termination */
01015 };
01016 
01017 struct __db_txn_stat {
01018         DB_LSN    st_last_ckp;          /* lsn of the last checkpoint */
01019         time_t    st_time_ckp;          /* time of last checkpoint */
01020         u_int32_t st_last_txnid;        /* last transaction id given out */
01021         u_int32_t st_maxtxns;           /* maximum txns possible */
01022         u_int32_t st_naborts;           /* number of aborted transactions */
01023         u_int32_t st_nbegins;           /* number of begun transactions */
01024         u_int32_t st_ncommits;          /* number of committed transactions */
01025         u_int32_t st_nactive;           /* number of active transactions */
01026         u_int32_t st_nrestores;         /* number of restored transactions
01027                                            after recovery. */
01028         u_int32_t st_maxnactive;        /* maximum active transactions */
01029         DB_TXN_ACTIVE *st_txnarray;     /* array of active transactions */
01030         u_int32_t st_region_wait;       /* Region lock granted after wait. */
01031         u_int32_t st_region_nowait;     /* Region lock granted without wait. */
01032         roff_t    st_regsize;           /* Region size. */
01033 };
01034 
01035 /*******************************************************
01036  * Replication.
01037  *******************************************************/
01038 /* Special, out-of-band environment IDs. */
01039 #define DB_EID_BROADCAST        -1
01040 #define DB_EID_INVALID          -2
01041 
01042 /* rep_config flag values. */
01043 #define DB_REP_CONF_BULK        0x0001  /* Bulk transfer. */
01044 #define DB_REP_CONF_DELAYCLIENT 0x0002  /* Delay client synchronization. */
01045 #define DB_REP_CONF_NOAUTOINIT  0x0004  /* No automatic client init. */
01046 #define DB_REP_CONF_NOWAIT      0x0008  /* Don't wait, return error. */
01047 
01048 /* rep_start flags values. */
01049 #define DB_REP_CLIENT           0x001
01050 #define DB_REP_MASTER           0x002
01051 
01052 /* Replication statistics. */
01053 struct __db_rep_stat {
01054         /* !!!
01055          * Many replication statistics fields cannot be protected by a mutex
01056          * without an unacceptable performance penalty, since most message
01057          * processing is done without the need to hold a region-wide lock.
01058          * Fields whose comments end with a '+' may be updated without holding
01059          * the replication or log mutexes (as appropriate), and thus may be
01060          * off somewhat (or, on unreasonable architectures under unlucky
01061          * circumstances, garbaged).
01062          */
01063         u_int32_t st_status;            /* Current replication status. */
01064         DB_LSN st_next_lsn;             /* Next LSN to use or expect. */
01065         DB_LSN st_waiting_lsn;          /* LSN we're awaiting, if any. */
01066         db_pgno_t st_next_pg;           /* Next pg we expect. */
01067         db_pgno_t st_waiting_pg;        /* pg we're awaiting, if any. */
01068 
01069         u_int32_t st_dupmasters;        /* # of times a duplicate master
01070                                            condition was detected.+ */
01071         int st_env_id;                  /* Current environment ID. */
01072         int st_env_priority;            /* Current environment priority. */
01073         u_int32_t st_bulk_fills;        /* Bulk buffer fills. */
01074         u_int32_t st_bulk_overflows;    /* Bulk buffer overflows. */
01075         u_int32_t st_bulk_records;      /* Bulk records stored. */
01076         u_int32_t st_bulk_transfers;    /* Transfers of bulk buffers. */
01077         u_int32_t st_client_rerequests; /* Number of forced rerequests. */
01078         u_int32_t st_client_svc_req;    /* Number of client service requests
01079                                            received by this client. */
01080         u_int32_t st_client_svc_miss;   /* Number of client service requests
01081                                            missing on this client. */
01082         u_int32_t st_gen;               /* Current generation number. */
01083         u_int32_t st_egen;              /* Current election gen number. */
01084         u_int32_t st_log_duplicated;    /* Log records received multiply.+ */
01085         u_int32_t st_log_queued;        /* Log records currently queued.+ */
01086         u_int32_t st_log_queued_max;    /* Max. log records queued at once.+ */
01087         u_int32_t st_log_queued_total;  /* Total # of log recs. ever queued.+ */
01088         u_int32_t st_log_records;       /* Log records received and put.+ */
01089         u_int32_t st_log_requested;     /* Log recs. missed and requested.+ */
01090         int st_master;                  /* Env. ID of the current master. */
01091         u_int32_t st_master_changes;    /* # of times we've switched masters. */
01092         u_int32_t st_msgs_badgen;       /* Messages with a bad generation #.+ */
01093         u_int32_t st_msgs_processed;    /* Messages received and processed.+ */
01094         u_int32_t st_msgs_recover;      /* Messages ignored because this site
01095                                            was a client in recovery.+ */
01096         u_int32_t st_msgs_send_failures;/* # of failed message sends.+ */
01097         u_int32_t st_msgs_sent;         /* # of successful message sends.+ */
01098         u_int32_t st_newsites;          /* # of NEWSITE msgs. received.+ */
01099         int st_nsites;                  /* Current number of sites we will
01100                                            assume during elections. */
01101         u_int32_t st_nthrottles;        /* # of times we were throttled. */
01102         u_int32_t st_outdated;          /* # of times we detected and returned
01103                                            an OUTDATED condition.+ */
01104         u_int32_t st_pg_duplicated;     /* Pages received multiply.+ */
01105         u_int32_t st_pg_records;        /* Pages received and stored.+ */
01106         u_int32_t st_pg_requested;      /* Pages missed and requested.+ */
01107         u_int32_t st_startup_complete;  /* Site completed client sync-up. */
01108         u_int32_t st_txns_applied;      /* # of transactions applied.+ */
01109 
01110         /* Elections generally. */
01111         u_int32_t st_elections;         /* # of elections held.+ */
01112         u_int32_t st_elections_won;     /* # of elections won by this site.+ */
01113 
01114         /* Statistics about an in-progress election. */
01115         int st_election_cur_winner;     /* Current front-runner. */
01116         u_int32_t st_election_gen;      /* Election generation number. */
01117         DB_LSN st_election_lsn;         /* Max. LSN of current winner. */
01118         int st_election_nsites;         /* # of "registered voters". */
01119         int st_election_nvotes;         /* # of "registered voters" needed. */
01120         int st_election_priority;       /* Current election priority. */
01121         int st_election_status;         /* Current election status. */
01122         u_int32_t st_election_tiebreaker;/* Election tiebreaker value. */
01123         int st_election_votes;          /* Votes received in this round. */
01124         u_int32_t st_election_sec;      /* Last election time seconds. */
01125         u_int32_t st_election_usec;     /* Last election time useconds. */
01126 };
01127 
01128 /*******************************************************
01129  * Sequences.
01130  *******************************************************/
01131 /*
01132  * The storage record for a sequence.
01133  */
01134 struct __db_seq_record {
01135         u_int32_t       seq_version;    /* Version size/number. */
01136 #define DB_SEQ_DEC              0x00000001      /* Decrement sequence. */
01137 #define DB_SEQ_INC              0x00000002      /* Increment sequence. */
01138 #define DB_SEQ_RANGE_SET        0x00000004      /* Range set (internal). */
01139 #define DB_SEQ_WRAP             0x00000008      /* Wrap sequence at min/max. */
01140 #define DB_SEQ_WRAPPED          0x00000010      /* Just wrapped (internal). */
01141         u_int32_t       flags;          /* Flags. */
01142         db_seq_t        seq_value;      /* Current value. */
01143         db_seq_t        seq_max;        /* Max permitted. */
01144         db_seq_t        seq_min;        /* Min permitted. */
01145 };
01146 
01147 /*
01148  * Handle for a sequence object.
01149  */
01150 struct __db_sequence {
01151         DB              *seq_dbp;       /* DB handle for this sequence. */
01152         db_mutex_t      mtx_seq;        /* Mutex if sequence is threaded. */
01153         DB_SEQ_RECORD   *seq_rp;        /* Pointer to current data. */
01154         DB_SEQ_RECORD   seq_record;     /* Data from DB_SEQUENCE. */
01155         int32_t         seq_cache_size; /* Number of values cached. */
01156         db_seq_t        seq_last_value; /* Last value cached. */
01157         DBT             seq_key;        /* DBT pointing to sequence key. */
01158         DBT             seq_data;       /* DBT pointing to seq_record. */
01159 
01160         /* API-private structure: used by C++ and Java. */
01161         void            *api_internal;
01162 
01163         /* DB_SEQUENCE PUBLIC HANDLE LIST BEGIN */
01164         int             (*close) __P((DB_SEQUENCE *, u_int32_t));
01165         int             (*get) __P((DB_SEQUENCE *,
01166                               DB_TXN *, int32_t, db_seq_t *, u_int32_t));
01167         int             (*get_cachesize) __P((DB_SEQUENCE *, int32_t *));
01168         int             (*get_db) __P((DB_SEQUENCE *, DB **));
01169         int             (*get_flags) __P((DB_SEQUENCE *, u_int32_t *));
01170         int             (*get_key) __P((DB_SEQUENCE *, DBT *));
01171         int             (*get_range) __P((DB_SEQUENCE *,
01172                              db_seq_t *, db_seq_t *));
01173         int             (*initial_value) __P((DB_SEQUENCE *, db_seq_t));
01174         int             (*open) __P((DB_SEQUENCE *,
01175                             DB_TXN *, DBT *, u_int32_t));
01176         int             (*remove) __P((DB_SEQUENCE *, DB_TXN *, u_int32_t));
01177         int             (*set_cachesize) __P((DB_SEQUENCE *, int32_t));
01178         int             (*set_flags) __P((DB_SEQUENCE *, u_int32_t));
01179         int             (*set_range) __P((DB_SEQUENCE *, db_seq_t, db_seq_t));
01180         int             (*stat) __P((DB_SEQUENCE *,
01181                             DB_SEQUENCE_STAT **, u_int32_t));
01182         int             (*stat_print) __P((DB_SEQUENCE *, u_int32_t));
01183         /* DB_SEQUENCE PUBLIC HANDLE LIST END */
01184 };
01185 
01186 struct __db_seq_stat {
01187         u_int32_t st_wait;              /* Sequence lock granted w/o wait. */
01188         u_int32_t st_nowait;            /* Sequence lock granted after wait. */
01189         db_seq_t  st_current;           /* Current value in db. */
01190         db_seq_t  st_value;             /* Current cached value. */
01191         db_seq_t  st_last_value;        /* Last cached value. */
01192         db_seq_t  st_min;               /* Minimum value. */
01193         db_seq_t  st_max;               /* Maximum value. */
01194         int32_t   st_cache_size;        /* Cache size. */
01195         u_int32_t st_flags;             /* Flag value. */
01196 };
01197 
01198 /*******************************************************
01199  * Access methods.
01200  *******************************************************/
01201 typedef enum {
01202         DB_BTREE=1,
01203         DB_HASH=2,
01204         DB_RECNO=3,
01205         DB_QUEUE=4,
01206         DB_UNKNOWN=5                    /* Figure it out on open. */
01207 } DBTYPE;
01208 
01209 #define DB_RENAMEMAGIC  0x030800        /* File has been renamed. */
01210 
01211 #define DB_BTREEVERSION 9               /* Current btree version. */
01212 #define DB_BTREEOLDVER  8               /* Oldest btree version supported. */
01213 #define DB_BTREEMAGIC   0x053162
01214 
01215 #define DB_HASHVERSION  8               /* Current hash version. */
01216 #define DB_HASHOLDVER   7               /* Oldest hash version supported. */
01217 #define DB_HASHMAGIC    0x061561
01218 
01219 #define DB_QAMVERSION   4               /* Current queue version. */
01220 #define DB_QAMOLDVER    3               /* Oldest queue version supported. */
01221 #define DB_QAMMAGIC     0x042253
01222 
01223 #define DB_SEQUENCE_VERSION 2           /* Current sequence version. */
01224 #define DB_SEQUENCE_OLDVER  1           /* Oldest sequence version supported. */
01225 
01226 /*
01227  * DB access method and cursor operation values.  Each value is an operation
01228  * code to which additional bit flags are added.
01229  */
01230 #define DB_AFTER                 1      /* c_put() */
01231 #define DB_APPEND                2      /* put() */
01232 #define DB_BEFORE                3      /* c_put() */
01233 #define DB_CACHED_COUNTS         4      /* stat() */
01234 #define DB_CONSUME               5      /* get() */
01235 #define DB_CONSUME_WAIT          6      /* get() */
01236 #define DB_CURRENT               7      /* c_get(), c_put(), DB_LOGC->get() */
01237 #define DB_FAST_STAT             8      /* stat() */
01238 #define DB_FIRST                 9      /* c_get(), DB_LOGC->get() */
01239 #define DB_GET_BOTH             10      /* get(), c_get() */
01240 #define DB_GET_BOTHC            11      /* c_get() (internal) */
01241 #define DB_GET_BOTH_RANGE       12      /* get(), c_get() */
01242 #define DB_GET_RECNO            13      /* c_get() */
01243 #define DB_JOIN_ITEM            14      /* c_get(); do not do primary lookup */
01244 #define DB_KEYFIRST             15      /* c_put() */
01245 #define DB_KEYLAST              16      /* c_put() */
01246 #define DB_LAST                 17      /* c_get(), DB_LOGC->get() */
01247 #define DB_NEXT                 18      /* c_get(), DB_LOGC->get() */
01248 #define DB_NEXT_DUP             19      /* c_get() */
01249 #define DB_NEXT_NODUP           20      /* c_get() */
01250 #define DB_NODUPDATA            21      /* put(), c_put() */
01251 #define DB_NOOVERWRITE          22      /* put() */
01252 #define DB_NOSYNC               23      /* close() */
01253 #define DB_POSITION             24      /* c_dup() */
01254 #define DB_PREV                 25      /* c_get(), DB_LOGC->get() */
01255 #define DB_PREV_NODUP           26      /* c_get(), DB_LOGC->get() */
01256 #define DB_RECORDCOUNT          27      /* stat() */
01257 #define DB_SET                  28      /* c_get(), DB_LOGC->get() */
01258 #define DB_SET_LOCK_TIMEOUT     29      /* set_timout() */
01259 #define DB_SET_RANGE            30      /* c_get() */
01260 #define DB_SET_RECNO            31      /* get(), c_get() */
01261 #define DB_SET_TXN_NOW          32      /* set_timout() (internal) */
01262 #define DB_SET_TXN_TIMEOUT      33      /* set_timout() */
01263 #define DB_UPDATE_SECONDARY     34      /* c_get(), c_del() (internal) */
01264 #define DB_WRITECURSOR          35      /* cursor() */
01265 #define DB_WRITELOCK            36      /* cursor() (internal) */
01266 
01267 /* This has to change when the max opcode hits 255. */
01268 #define DB_OPFLAGS_MASK 0x000000ff      /* Mask for operations flags. */
01269 
01270 /*
01271  * Masks for flags that can be OR'd into DB access method and cursor
01272  * operation values.  Three top bits have already been taken:
01273  *
01274  * DB_AUTO_COMMIT       0x01000000
01275  * DB_READ_COMMITTED    0x02000000
01276  * DB_READ_UNCOMMITTED  0x04000000
01277  */
01278 #define DB_MULTIPLE     0x08000000      /* Return multiple data values. */
01279 #define DB_MULTIPLE_KEY 0x10000000      /* Return multiple data/key pairs. */
01280 #define DB_RMW          0x20000000      /* Acquire write lock immediately. */
01281 
01282 /*
01283  * DB (user visible) error return codes.
01284  *
01285  * !!!
01286  * For source compatibility with DB 2.X deadlock return (EAGAIN), use the
01287  * following:
01288  *      #include <errno.h>
01289  *      #define DB_LOCK_DEADLOCK EAGAIN
01290  *
01291  * !!!
01292  * We don't want our error returns to conflict with other packages where
01293  * possible, so pick a base error value that's hopefully not common.  We
01294  * document that we own the error name space from -30,800 to -30,999.
01295  */
01296 /* DB (public) error return codes. */
01297 #define DB_BUFFER_SMALL         (-30999)/* User memory too small for return. */
01298 #define DB_DONOTINDEX           (-30998)/* "Null" return from 2ndary callbk. */
01299 #define DB_KEYEMPTY             (-30997)/* Key/data deleted or never created. */
01300 #define DB_KEYEXIST             (-30996)/* The key/data pair already exists. */
01301 #define DB_LOCK_DEADLOCK        (-30995)/* Deadlock. */
01302 #define DB_LOCK_NOTGRANTED      (-30994)/* Lock unavailable. */
01303 #define DB_LOG_BUFFER_FULL      (-30993)/* In-memory log buffer full. */
01304 #define DB_NOSERVER             (-30992)/* Server panic return. */
01305 #define DB_NOSERVER_HOME        (-30991)/* Bad home sent to server. */
01306 #define DB_NOSERVER_ID          (-30990)/* Bad ID sent to server. */
01307 #define DB_NOTFOUND             (-30989)/* Key/data pair not found (EOF). */
01308 #define DB_OLD_VERSION          (-30988)/* Out-of-date version. */
01309 #define DB_PAGE_NOTFOUND        (-30987)/* Requested page not found. */
01310 #define DB_REP_DUPMASTER        (-30986)/* There are two masters. */
01311 #define DB_REP_HANDLE_DEAD      (-30985)/* Rolled back a commit. */
01312 #define DB_REP_HOLDELECTION     (-30984)/* Time to hold an election. */
01313 #define DB_REP_IGNORE           (-30983)/* This msg should be ignored.*/
01314 #define DB_REP_ISPERM           (-30982)/* Cached not written perm written.*/
01315 #define DB_REP_JOIN_FAILURE     (-30981)/* Unable to join replication group. */
01316 #define DB_REP_LOCKOUT          (-30980)/* API/Replication lockout now. */
01317 #define DB_REP_NEWMASTER        (-30979)/* We have learned of a new master. */
01318 #define DB_REP_NEWSITE          (-30978)/* New site entered system. */
01319 #define DB_REP_NOTPERM          (-30977)/* Permanent log record not written. */
01320 #define DB_REP_STARTUPDONE      (-30976)/* Client startup complete. */
01321 #define DB_REP_UNAVAIL          (-30975)/* Site cannot currently be reached. */
01322 #define DB_RUNRECOVERY          (-30974)/* Panic return. */
01323 #define DB_SECONDARY_BAD        (-30973)/* Secondary index corrupt. */
01324 #define DB_VERIFY_BAD           (-30972)/* Verify failed; bad format. */
01325 #define DB_VERSION_MISMATCH     (-30971)/* Environment version mismatch. */
01326 
01327 /* DB (private) error return codes. */
01328 #define DB_ALREADY_ABORTED      (-30899)
01329 #define DB_DELETED              (-30898)/* Recovery file marked deleted. */
01330 #define DB_NEEDSPLIT            (-30897)/* Page needs to be split. */
01331 #define DB_REP_BULKOVF          (-30896)/* Rep bulk buffer overflow. */
01332 #define DB_REP_EGENCHG          (-30895)/* Egen changed while in election. */
01333 #define DB_REP_LOGREADY         (-30894)/* Rep log ready for recovery. */
01334 #define DB_REP_PAGEDONE         (-30893)/* This page was already done. */
01335 #define DB_SURPRISE_KID         (-30892)/* Child commit where parent
01336                                            didn't know it was a parent. */
01337 #define DB_SWAPBYTES            (-30891)/* Database needs byte swapping. */
01338 #define DB_TIMEOUT              (-30890)/* Timed out waiting for election. */
01339 #define DB_TXN_CKP              (-30889)/* Encountered ckp record in log. */
01340 #define DB_VERIFY_FATAL         (-30888)/* DB->verify cannot proceed. */
01341 
01342 /* Database handle. */
01343 struct __db {
01344         /*******************************************************
01345          * Public: owned by the application.
01346          *******************************************************/
01347         u_int32_t pgsize;               /* Database logical page size. */
01348 
01349                                         /* Callbacks. */
01350         int (*db_append_recno) __P((DB *, DBT *, db_recno_t));
01351         void (*db_feedback) __P((DB *, int, int));
01352         int (*dup_compare) __P((DB *, const DBT *, const DBT *));
01353 
01354         void    *app_private;           /* Application-private handle. */
01355 
01356         /*******************************************************
01357          * Private: owned by DB.
01358          *******************************************************/
01359         DB_ENV  *dbenv;                 /* Backing environment. */
01360 
01361         DBTYPE   type;                  /* DB access method type. */
01362 
01363         DB_MPOOLFILE *mpf;              /* Backing buffer pool. */
01364 
01365         db_mutex_t mutex;               /* Synchronization for free threading */
01366 
01367         char *fname, *dname;            /* File/database passed to DB->open. */
01368         u_int32_t open_flags;           /* Flags passed to DB->open. */
01369 
01370         u_int8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */
01371 
01372         u_int32_t adj_fileid;           /* File's unique ID for curs. adj. */
01373 
01374 #define DB_LOGFILEID_INVALID    -1
01375         FNAME *log_filename;            /* File's naming info for logging. */
01376 
01377         db_pgno_t meta_pgno;            /* Meta page number */
01378         u_int32_t lid;                  /* Locker id for handle locking. */
01379         u_int32_t cur_lid;              /* Current handle lock holder. */
01380         u_int32_t associate_lid;        /* Locker id for DB->associate call. */
01381         DB_LOCK  handle_lock;           /* Lock held on this handle. */
01382 
01383         u_int    cl_id;                 /* RPC: remote client id. */
01384 
01385         time_t   timestamp;             /* Handle timestamp for replication. */
01386         u_int32_t fid_gen;              /* Rep generation number for fids. */
01387 
01388         /*
01389          * Returned data memory for DB->get() and friends.
01390          */
01391         DBT      my_rskey;              /* Secondary key. */
01392         DBT      my_rkey;               /* [Primary] key. */
01393         DBT      my_rdata;              /* Data. */
01394 
01395         /*
01396          * !!!
01397          * Some applications use DB but implement their own locking outside of
01398          * DB.  If they're using fcntl(2) locking on the underlying database
01399          * file, and we open and close a file descriptor for that file, we will
01400          * discard their locks.  The DB_FCNTL_LOCKING flag to DB->open is an
01401          * undocumented interface to support this usage which leaves any file
01402          * descriptors we open until DB->close.  This will only work with the
01403          * DB->open interface and simple caches, e.g., creating a transaction
01404          * thread may open/close file descriptors this flag doesn't protect.
01405          * Locking with fcntl(2) on a file that you don't own is a very, very
01406          * unsafe thing to do.  'Nuff said.
01407          */
01408         DB_FH   *saved_open_fhp;        /* Saved file handle. */
01409 
01410         /*
01411          * Linked list of DBP's, linked from the DB_ENV, used to keep track
01412          * of all open db handles for cursor adjustment.
01413          *
01414          * !!!
01415          * Explicit representations of structures from queue.h.
01416          * LIST_ENTRY(__db) dblistlinks;
01417          */
01418         struct {
01419                 struct __db *le_next;
01420                 struct __db **le_prev;
01421         } dblistlinks;
01422 
01423         /*
01424          * Cursor queues.
01425          *
01426          * !!!
01427          * Explicit representations of structures from queue.h.
01428          * TAILQ_HEAD(__cq_fq, __dbc) free_queue;
01429          * TAILQ_HEAD(__cq_aq, __dbc) active_queue;
01430          * TAILQ_HEAD(__cq_jq, __dbc) join_queue;
01431          */
01432         struct __cq_fq {
01433                 struct __dbc *tqh_first;
01434                 struct __dbc **tqh_last;
01435         } free_queue;
01436         struct __cq_aq {
01437                 struct __dbc *tqh_first;
01438                 struct __dbc **tqh_last;
01439         } active_queue;
01440         struct __cq_jq {
01441                 struct __dbc *tqh_first;
01442                 struct __dbc **tqh_last;
01443         } join_queue;
01444 
01445         /*
01446          * Secondary index support.
01447          *
01448          * Linked list of secondary indices -- set in the primary.
01449          *
01450          * !!!
01451          * Explicit representations of structures from queue.h.
01452          * LIST_HEAD(s_secondaries, __db);
01453          */
01454         struct {
01455                 struct __db *lh_first;
01456         } s_secondaries;
01457 
01458         /*
01459          * List entries for secondaries, and reference count of how
01460          * many threads are updating this secondary (see __db_c_put).
01461          *
01462          * !!!
01463          * Note that these are synchronized by the primary's mutex, but
01464          * filled in in the secondaries.
01465          *
01466          * !!!
01467          * Explicit representations of structures from queue.h.
01468          * LIST_ENTRY(__db) s_links;
01469          */
01470         struct {
01471                 struct __db *le_next;
01472                 struct __db **le_prev;
01473         } s_links;
01474         u_int32_t s_refcnt;
01475 
01476         /* Secondary callback and free functions -- set in the secondary. */
01477         int     (*s_callback) __P((DB *, const DBT *, const DBT *, DBT *));
01478 
01479         /* Reference to primary -- set in the secondary. */
01480         DB      *s_primary;
01481 
01482 #define DB_ASSOC_IMMUTABLE_KEY    0x00000001 /* Secondary key is immutable. */
01483 
01484         /* Flags passed to associate -- set in the secondary. */
01485         u_int32_t s_assoc_flags;
01486 
01487         /* API-private structure: used by DB 1.85, C++, Java, Perl and Tcl */
01488         void    *api_internal;
01489 
01490         /* Subsystem-private structure. */
01491         void    *bt_internal;           /* Btree/Recno access method. */
01492         void    *h_internal;            /* Hash access method. */
01493         void    *q_internal;            /* Queue access method. */
01494         void    *xa_internal;           /* XA. */
01495 
01496         /* DB PUBLIC HANDLE LIST BEGIN */
01497         int  (*associate) __P((DB *, DB_TXN *, DB *,
01498                 int (*)(DB *, const DBT *, const DBT *, DBT *), u_int32_t));
01499         int  (*close) __P((DB *, u_int32_t));
01500         int  (*compact) __P((DB *,
01501                 DB_TXN *, DBT *, DBT *, DB_COMPACT *, u_int32_t, DBT *));
01502         int  (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
01503         int  (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
01504         void (*err) __P((DB *, int, const char *, ...));
01505         void (*errx) __P((DB *, const char *, ...));
01506         int  (*fd) __P((DB *, int *));
01507         int  (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
01508         int  (*get_bt_minkey) __P((DB *, u_int32_t *));
01509         int  (*get_byteswapped) __P((DB *, int *));
01510         int  (*get_cachesize) __P((DB *, u_int32_t *, u_int32_t *, int *));
01511         int  (*get_dbname) __P((DB *, const char **, const char **));
01512         int  (*get_encrypt_flags) __P((DB *, u_int32_t *));
01513         DB_ENV *(*get_env) __P((DB *));
01514         void (*get_errfile) __P((DB *, FILE **));
01515         void (*get_errpfx) __P((DB *, const char **));
01516         int  (*get_flags) __P((DB *, u_int32_t *));
01517         int  (*get_h_ffactor) __P((DB *, u_int32_t *));
01518         int  (*get_h_nelem) __P((DB *, u_int32_t *));
01519         int  (*get_lorder) __P((DB *, int *));
01520         DB_MPOOLFILE *(*get_mpf) __P((DB *));
01521         void (*get_msgfile) __P((DB *, FILE **));
01522         int  (*get_open_flags) __P((DB *, u_int32_t *));
01523         int  (*get_pagesize) __P((DB *, u_int32_t *));
01524         int  (*get_q_extentsize) __P((DB *, u_int32_t *));
01525         int  (*get_re_delim) __P((DB *, int *));
01526         int  (*get_re_len) __P((DB *, u_int32_t *));
01527         int  (*get_re_pad) __P((DB *, int *));
01528         int  (*get_re_source) __P((DB *, const char **));
01529         int  (*get_transactional) __P((DB *));
01530         int  (*get_type) __P((DB *, DBTYPE *));
01531         int  (*join) __P((DB *, DBC **, DBC **, u_int32_t));
01532         int  (*key_range)
01533                 __P((DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t));
01534         int  (*open) __P((DB *,
01535                 DB_TXN *, const char *, const char *, DBTYPE, u_int32_t, int));
01536         int  (*pget) __P((DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t));
01537         int  (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
01538         int  (*remove) __P((DB *, const char *, const char *, u_int32_t));
01539         int  (*rename) __P((DB *,
01540                 const char *, const char *, const char *, u_int32_t));
01541         int  (*set_alloc) __P((DB *, void *(*)(size_t),
01542                 void *(*)(void *, size_t), void (*)(void *)));
01543         int  (*set_append_recno) __P((DB *, int (*)(DB *, DBT *, db_recno_t)));
01544         int  (*set_bt_compare)
01545                 __P((DB *, int (*)(DB *, const DBT *, const DBT *)));
01546         int  (*set_bt_minkey) __P((DB *, u_int32_t));
01547         int  (*set_bt_prefix)
01548                 __P((DB *, size_t (*)(DB *, const DBT *, const DBT *)));
01549         int  (*set_cachesize) __P((DB *, u_int32_t, u_int32_t, int));
01550         int  (*set_dup_compare)
01551                 __P((DB *, int (*)(DB *, const DBT *, const DBT *)));
01552         int  (*set_encrypt) __P((DB *, const char *, u_int32_t));
01553         void (*set_errcall) __P((DB *,
01554                 void (*)(const DB_ENV *, const char *, const char *)));
01555         void (*set_errfile) __P((DB *, FILE *));
01556         void (*set_errpfx) __P((DB *, const char *));
01557         int  (*set_feedback) __P((DB *, void (*)(DB *, int, int)));
01558         int  (*set_flags) __P((DB *, u_int32_t));
01559         int  (*set_h_ffactor) __P((DB *, u_int32_t));
01560         int  (*set_h_hash)
01561                 __P((DB *, u_int32_t (*)(DB *, const void *, u_int32_t)));
01562         int  (*set_h_nelem) __P((DB *, u_int32_t));
01563         int  (*set_lorder) __P((DB *, int));
01564         void (*set_msgcall) __P((DB *, void (*)(const DB_ENV *, const char *)));
01565         void (*set_msgfile) __P((DB *, FILE *));
01566         int  (*set_pagesize) __P((DB *, u_int32_t));
01567         int  (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int)));
01568         int  (*set_q_extentsize) __P((DB *, u_int32_t));
01569         int  (*set_re_delim) __P((DB *, int));
01570         int  (*set_re_len) __P((DB *, u_int32_t));
01571         int  (*set_re_pad) __P((DB *, int));
01572         int  (*set_re_source) __P((DB *, const char *));
01573         int  (*stat) __P((DB *, DB_TXN *, void *, u_int32_t));
01574         int  (*stat_print) __P((DB *, u_int32_t));
01575         int  (*sync) __P((DB *, u_int32_t));
01576         int  (*truncate) __P((DB *, DB_TXN *, u_int32_t *, u_int32_t));
01577         int  (*upgrade) __P((DB *, const char *, u_int32_t));
01578         int  (*verify)
01579                 __P((DB *, const char *, const char *, FILE *, u_int32_t));
01580         /* DB PUBLIC HANDLE LIST END */
01581 
01582         /* DB PRIVATE HANDLE LIST BEGIN */
01583         int  (*dump) __P((DB *, const char *,
01584                 int (*)(void *, const void *), void *, int, int));
01585         int  (*db_am_remove) __P((DB *, DB_TXN *, const char *, const char *));
01586         int  (*db_am_rename) __P((DB *, DB_TXN *,
01587             const char *, const char *, const char *));
01588         /* DB PRIVATE HANDLE LIST END */
01589 
01590         /*
01591          * Never called; these are a place to save function pointers
01592          * so that we can undo an associate.
01593          */
01594         int  (*stored_get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
01595         int  (*stored_close) __P((DB *, u_int32_t));
01596 
01597 #define DB_OK_BTREE     0x01
01598 #define DB_OK_HASH      0x02
01599 #define DB_OK_QUEUE     0x04
01600 #define DB_OK_RECNO     0x08
01601         u_int32_t       am_ok;          /* Legal AM choices. */
01602 
01603         /*
01604          * This field really ought to be an AM_FLAG, but we have
01605          * have run out of bits.  If/when we decide to split up
01606          * the flags, we can incorporate it.
01607          */
01608         int      preserve_fid;          /* Do not free fileid on close. */
01609 
01610 #define DB_AM_CHKSUM            0x00000001 /* Checksumming */
01611 #define DB_AM_CL_WRITER         0x00000002 /* Allow writes in client replica */
01612 #define DB_AM_COMPENSATE        0x00000004 /* Created by compensating txn */
01613 #define DB_AM_CREATED           0x00000008 /* Database was created upon open */
01614 #define DB_AM_CREATED_MSTR      0x00000010 /* Encompassing file was created */
01615 #define DB_AM_DBM_ERROR         0x00000020 /* Error in DBM/NDBM database */
01616 #define DB_AM_DELIMITER         0x00000040 /* Variable length delimiter set */
01617 #define DB_AM_DISCARD           0x00000080 /* Discard any cached pages */
01618 #define DB_AM_DUP               0x00000100 /* DB_DUP */
01619 #define DB_AM_DUPSORT           0x00000200 /* DB_DUPSORT */
01620 #define DB_AM_ENCRYPT           0x00000400 /* Encryption */
01621 #define DB_AM_FIXEDLEN          0x00000800 /* Fixed-length records */
01622 #define DB_AM_INMEM             0x00001000 /* In-memory; no sync on close */
01623 #define DB_AM_INORDER           0x00002000 /* DB_INORDER */
01624 #define DB_AM_IN_RENAME         0x00004000 /* File is being renamed */
01625 #define DB_AM_NOT_DURABLE       0x00008000 /* Do not log changes */
01626 #define DB_AM_OPEN_CALLED       0x00010000 /* DB->open called */
01627 #define DB_AM_PAD               0x00020000 /* Fixed-length record pad */
01628 #define DB_AM_PGDEF             0x00040000 /* Page size was defaulted */
01629 #define DB_AM_RDONLY            0x00080000 /* Database is readonly */
01630 #define DB_AM_READ_UNCOMMITTED  0x00100000 /* Support degree 1 isolation */
01631 #define DB_AM_RECNUM            0x00200000 /* DB_RECNUM */
01632 #define DB_AM_RECOVER           0x00400000 /* DB opened by recovery routine */
01633 #define DB_AM_RENUMBER          0x00800000 /* DB_RENUMBER */
01634 #define DB_AM_REVSPLITOFF       0x01000000 /* DB_REVSPLITOFF */
01635 #define DB_AM_SECONDARY         0x02000000 /* Database is a secondary index */
01636 #define DB_AM_SNAPSHOT          0x04000000 /* DB_SNAPSHOT */
01637 #define DB_AM_SUBDB             0x08000000 /* Subdatabases supported */
01638 #define DB_AM_SWAP              0x10000000 /* Pages need to be byte-swapped */
01639 #define DB_AM_TXN               0x20000000 /* Opened in a transaction */
01640 #define DB_AM_VERIFYING         0x40000000 /* DB handle is in the verifier */
01641         u_int32_t orig_flags;              /* Flags at  open, for refresh */
01642         u_int32_t flags;
01643 };
01644 
01645 /*
01646  * Macros for bulk get.  These are only intended for the C API.
01647  * For C++, use DbMultiple*Iterator.
01648  */
01649 #define DB_MULTIPLE_INIT(pointer, dbt)                                  \
01650         (pointer = (u_int8_t *)(dbt)->data +                            \
01651             (dbt)->ulen - sizeof(u_int32_t))
01652 #define DB_MULTIPLE_NEXT(pointer, dbt, retdata, retdlen)                \
01653         do {                                                            \
01654                 if (*((u_int32_t *)(pointer)) == (u_int32_t)-1) {       \
01655                         retdata = NULL;                                 \
01656                         pointer = NULL;                                 \
01657                         break;                                          \
01658                 }                                                       \
01659                 retdata = (u_int8_t *)                                  \
01660                     (dbt)->data + *(u_int32_t *)(pointer);              \
01661                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01662                 retdlen = *(u_int32_t *)(pointer);                      \
01663                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01664                 if (retdlen == 0 &&                                     \
01665                     retdata == (u_int8_t *)(dbt)->data)                 \
01666                         retdata = NULL;                                 \
01667         } while (0)
01668 #define DB_MULTIPLE_KEY_NEXT(pointer, dbt, retkey, retklen, retdata, retdlen) \
01669         do {                                                            \
01670                 if (*((u_int32_t *)(pointer)) == (u_int32_t)-1) {       \
01671                         retdata = NULL;                                 \
01672                         retkey = NULL;                                  \
01673                         pointer = NULL;                                 \
01674                         break;                                          \
01675                 }                                                       \
01676                 retkey = (u_int8_t *)                                   \
01677                     (dbt)->data + *(u_int32_t *)(pointer);              \
01678                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01679                 retklen = *(u_int32_t *)(pointer);                      \
01680                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01681                 retdata = (u_int8_t *)                                  \
01682                     (dbt)->data + *(u_int32_t *)(pointer);              \
01683                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01684                 retdlen = *(u_int32_t *)(pointer);                      \
01685                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01686         } while (0)
01687 
01688 #define DB_MULTIPLE_RECNO_NEXT(pointer, dbt, recno, retdata, retdlen)   \
01689         do {                                                            \
01690                 if (*((u_int32_t *)(pointer)) == (u_int32_t)0) {        \
01691                         recno = 0;                                      \
01692                         retdata = NULL;                                 \
01693                         pointer = NULL;                                 \
01694                         break;                                          \
01695                 }                                                       \
01696                 recno = *(u_int32_t *)(pointer);                        \
01697                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01698                 retdata = (u_int8_t *)                                  \
01699                     (dbt)->data + *(u_int32_t *)(pointer);              \
01700                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01701                 retdlen = *(u_int32_t *)(pointer);                      \
01702                 (pointer) = (u_int32_t *)(pointer) - 1;                 \
01703         } while (0)
01704 
01705 /*******************************************************
01706  * Access method cursors.
01707  *******************************************************/
01708 struct __dbc {
01709         DB *dbp;                        /* Related DB access method. */
01710         DB_TXN   *txn;                  /* Associated transaction. */
01711 
01712         /*
01713          * Active/free cursor queues.
01714          *
01715          * !!!
01716          * Explicit representations of structures from queue.h.
01717          * TAILQ_ENTRY(__dbc) links;
01718          */
01719         struct {
01720                 DBC *tqe_next;
01721                 DBC **tqe_prev;
01722         } links;
01723 
01724         /*
01725          * The DBT *'s below are used by the cursor routines to return
01726          * data to the user when DBT flags indicate that DB should manage
01727          * the returned memory.  They point at a DBT containing the buffer
01728          * and length that will be used, and "belonging" to the handle that
01729          * should "own" this memory.  This may be a "my_*" field of this
01730          * cursor--the default--or it may be the corresponding field of
01731          * another cursor, a DB handle, a join cursor, etc.  In general, it
01732          * will be whatever handle the user originally used for the current
01733          * DB interface call.
01734          */
01735         DBT      *rskey;                /* Returned secondary key. */
01736         DBT      *rkey;                 /* Returned [primary] key. */
01737         DBT      *rdata;                /* Returned data. */
01738 
01739         DBT       my_rskey;             /* Space for returned secondary key. */
01740         DBT       my_rkey;              /* Space for returned [primary] key. */
01741         DBT       my_rdata;             /* Space for returned data. */
01742 
01743         void     *lref;                 /* Reference to default locker. */
01744         u_int32_t locker;               /* Locker for this operation. */
01745         DBT       lock_dbt;             /* DBT referencing lock. */
01746         DB_LOCK_ILOCK lock;             /* Object to be locked. */
01747         DB_LOCK   mylock;               /* CDB lock held on this cursor. */
01748 
01749         u_int     cl_id;                /* Remote client id. */
01750 
01751         DBTYPE    dbtype;               /* Cursor type. */
01752 
01753         DBC_INTERNAL *internal;         /* Access method private. */
01754 
01755         /* DBC PUBLIC HANDLE LIST BEGIN */
01756         int (*c_close) __P((DBC *));
01757         int (*c_count) __P((DBC *, db_recno_t *, u_int32_t));
01758         int (*c_del) __P((DBC *, u_int32_t));
01759         int (*c_dup) __P((DBC *, DBC **, u_int32_t));
01760         int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
01761         int (*c_pget) __P((DBC *, DBT *, DBT *, DBT *, u_int32_t));
01762         int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
01763         /* DBC PUBLIC HANDLE LIST END */
01764 
01765         /* DBC PRIVATE HANDLE LIST BEGIN */
01766         int (*c_am_bulk) __P((DBC *, DBT *, u_int32_t));
01767         int (*c_am_close) __P((DBC *, db_pgno_t, int *));
01768         int (*c_am_del) __P((DBC *));
01769         int (*c_am_destroy) __P((DBC *));
01770         int (*c_am_get) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
01771         int (*c_am_put) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
01772         int (*c_am_writelock) __P((DBC *));
01773         /* DBC PRIVATE HANDLE LIST END */
01774 
01775 /*
01776  * DBC_COMPENSATE and DBC_RECOVER are used during recovery and transaction
01777  * abort.  If a transaction is being aborted or recovered then DBC_RECOVER
01778  * will be set and locking and logging will be disabled on this cursor.  If
01779  * we are performing a compensating transaction (e.g. free page processing)
01780  * then DB_COMPENSATE will be set to inhibit locking, but logging will still
01781  * be required.
01782  */
01783 #define DBC_ACTIVE              0x0001  /* Cursor in use. */
01784 #define DBC_COMPENSATE          0x0002  /* Cursor compensating, don't lock. */
01785 #define DBC_MULTIPLE            0x0004  /* Return Multiple data. */
01786 #define DBC_MULTIPLE_KEY        0x0008  /* Return Multiple keys and data. */
01787 #define DBC_OPD                 0x0010  /* Cursor references off-page dups. */
01788 #define DBC_OWN_LID             0x0020  /* Free lock id on destroy. */
01789 #define DBC_READ_COMMITTED      0x0040  /* Cursor has degree 2 isolation. */
01790 #define DBC_READ_UNCOMMITTED    0x0080  /* Cursor has degree 1 isolation. */
01791 #define DBC_RECOVER             0x0100  /* Recovery cursor; don't log/lock. */
01792 #define DBC_RMW                 0x0200  /* Acquire write flag in read op. */
01793 #define DBC_TRANSIENT           0x0400  /* Cursor is transient. */
01794 #define DBC_WRITECURSOR         0x0800  /* Cursor may be used to write (CDB). */
01795 #define DBC_WRITER              0x1000  /* Cursor immediately writing (CDB). */
01796         u_int32_t flags;
01797 };
01798 
01799 /* Key range statistics structure */
01800 struct __key_range {
01801         double less;
01802         double equal;
01803         double greater;
01804 };
01805 
01806 /* Btree/Recno statistics structure. */
01807 struct __db_bt_stat {
01808         u_int32_t bt_magic;             /* Magic number. */
01809         u_int32_t bt_version;           /* Version number. */
01810         u_int32_t bt_metaflags;         /* Metadata flags. */
01811         u_int32_t bt_nkeys;             /* Number of unique keys. */
01812         u_int32_t bt_ndata;             /* Number of data items. */
01813         u_int32_t bt_pagesize;          /* Page size. */
01814         u_int32_t bt_minkey;            /* Minkey value. */
01815         u_int32_t bt_re_len;            /* Fixed-length record length. */
01816         u_int32_t bt_re_pad;            /* Fixed-length record pad. */
01817         u_int32_t bt_levels;            /* Tree levels. */
01818         u_int32_t bt_int_pg;            /* Internal pages. */
01819         u_int32_t bt_leaf_pg;           /* Leaf pages. */
01820         u_int32_t bt_dup_pg;            /* Duplicate pages. */
01821         u_int32_t bt_over_pg;           /* Overflow pages. */
01822         u_int32_t bt_empty_pg;          /* Empty pages. */
01823         u_int32_t bt_free;              /* Pages on the free list. */
01824         u_int32_t bt_int_pgfree;        /* Bytes free in internal pages. */
01825         u_int32_t bt_leaf_pgfree;       /* Bytes free in leaf pages. */
01826         u_int32_t bt_dup_pgfree;        /* Bytes free in duplicate pages. */
01827         u_int32_t bt_over_pgfree;       /* Bytes free in overflow pages. */
01828 };
01829 
01830 struct __db_compact {
01831         /* Input Parameters. */
01832         u_int32_t       compact_fillpercent;    /* Desired fillfactor: 1-100 */
01833         db_timeout_t    compact_timeout;        /* Lock timeout. */
01834         u_int32_t       compact_pages;          /* Max pages to process. */
01835         /* Output Stats. */
01836         u_int32_t       compact_pages_free;     /* Number of pages freed. */
01837         u_int32_t       compact_pages_examine;  /* Number of pages examine. */
01838         u_int32_t       compact_levels;         /* Number of levels removed. */
01839         u_int32_t       compact_deadlock;       /* Number of deadlocks. */
01840         db_pgno_t       compact_pages_truncated; /* Pages truncated to OS. */
01841         /* Internal. */
01842         db_pgno_t       compact_truncate;       /* Page number for truncation */
01843 };
01844 
01845 /* Hash statistics structure. */
01846 struct __db_h_stat {
01847         u_int32_t hash_magic;           /* Magic number. */
01848         u_int32_t hash_version;         /* Version number. */
01849         u_int32_t hash_metaflags;       /* Metadata flags. */
01850         u_int32_t hash_nkeys;           /* Number of unique keys. */
01851         u_int32_t hash_ndata;           /* Number of data items. */
01852         u_int32_t hash_pagesize;        /* Page size. */
01853         u_int32_t hash_ffactor;         /* Fill factor specified at create. */
01854         u_int32_t hash_buckets;         /* Number of hash buckets. */
01855         u_int32_t hash_free;            /* Pages on the free list. */
01856         u_int32_t hash_bfree;           /* Bytes free on bucket pages. */
01857         u_int32_t hash_bigpages;        /* Number of big key/data pages. */
01858         u_int32_t hash_big_bfree;       /* Bytes free on big item pages. */
01859         u_int32_t hash_overflows;       /* Number of overflow pages. */
01860         u_int32_t hash_ovfl_free;       /* Bytes free on ovfl pages. */
01861         u_int32_t hash_dup;             /* Number of dup pages. */
01862         u_int32_t hash_dup_free;        /* Bytes free on duplicate pages. */
01863 };
01864 
01865 /* Queue statistics structure. */
01866 struct __db_qam_stat {
01867         u_int32_t qs_magic;             /* Magic number. */
01868         u_int32_t qs_version;           /* Version number. */
01869         u_int32_t qs_metaflags;         /* Metadata flags. */
01870         u_int32_t qs_nkeys;             /* Number of unique keys. */
01871         u_int32_t qs_ndata;             /* Number of data items. */
01872         u_int32_t qs_pagesize;          /* Page size. */
01873         u_int32_t qs_extentsize;        /* Pages per extent. */
01874         u_int32_t qs_pages;             /* Data pages. */
01875         u_int32_t qs_re_len;            /* Fixed-length record length. */
01876         u_int32_t qs_re_pad;            /* Fixed-length record pad. */
01877         u_int32_t qs_pgfree;            /* Bytes free in data pages. */
01878         u_int32_t qs_first_recno;       /* First not deleted record. */
01879         u_int32_t qs_cur_recno;         /* Next available record number. */
01880 };
01881 
01882 /*******************************************************
01883  * Environment.
01884  *******************************************************/
01885 #define DB_REGION_MAGIC 0x120897        /* Environment magic number. */
01886 
01887 /* Database Environment handle. */
01888 struct __db_env {
01889         /*******************************************************
01890          * Public: owned by the application.
01891          *******************************************************/
01892                                         /* Error message callback. */
01893         void (*db_errcall) __P((const DB_ENV *, const char *, const char *));
01894         FILE            *db_errfile;    /* Error message file stream. */
01895         const char      *db_errpfx;     /* Error message prefix. */
01896 
01897         FILE            *db_msgfile;    /* Statistics message file stream. */
01898                                         /* Statistics message callback. */
01899         void (*db_msgcall) __P((const DB_ENV *, const char *));
01900 
01901                                         /* Other Callbacks. */
01902         void (*db_feedback) __P((DB_ENV *, int, int));
01903         void (*db_paniccall) __P((DB_ENV *, int));
01904 
01905                                         /* App-specified alloc functions. */
01906         void *(*db_malloc) __P((size_t));
01907         void *(*db_realloc) __P((void *, size_t));
01908         void (*db_free) __P((void *));
01909 
01910         /*
01911          * Currently, the verbose list is a bit field with room for 32
01912          * entries.  There's no reason that it needs to be limited, if
01913          * there are ever more than 32 entries, convert to a bit array.
01914          */
01915 #define DB_VERB_DEADLOCK        0x0001  /* Deadlock detection information. */
01916 #define DB_VERB_RECOVERY        0x0002  /* Recovery information. */
01917 #define DB_VERB_REGISTER        0x0004  /* Dump waits-for table. */
01918 #define DB_VERB_REPLICATION     0x0008  /* Replication information. */
01919 #define DB_VERB_WAITSFOR        0x0010  /* Dump waits-for table. */
01920         u_int32_t        verbose;       /* Verbose output. */
01921 
01922         void            *app_private;   /* Application-private handle. */
01923 
01924         int (*app_dispatch)             /* User-specified recovery dispatch. */
01925             __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
01926 
01927         /* Mutexes. */
01928         u_int32_t       mutex_align;    /* Mutex alignment */
01929         u_int32_t       mutex_cnt;      /* Number of mutexes to configure */
01930         u_int32_t       mutex_inc;      /* Number of mutexes to add */
01931         u_int32_t       mutex_tas_spins;/* Test-and-set spin count */
01932 
01933         struct {
01934                 int       alloc_id;     /* Allocation ID argument */
01935                 u_int32_t flags;        /* Flags argument */
01936         } *mutex_iq;                    /* Initial mutexes queue */
01937         u_int           mutex_iq_next;  /* Count of initial mutexes */
01938         u_int           mutex_iq_max;   /* Maximum initial mutexes */
01939 
01940         /* Locking. */
01941         u_int8_t        *lk_conflicts;  /* Two dimensional conflict matrix. */
01942         int              lk_modes;      /* Number of lock modes in table. */
01943         u_int32_t        lk_max;        /* Maximum number of locks. */
01944         u_int32_t        lk_max_lockers;/* Maximum number of lockers. */
01945         u_int32_t        lk_max_objects;/* Maximum number of locked objects. */
01946         u_int32_t        lk_detect;     /* Deadlock detect on all conflicts. */
01947         db_timeout_t     lk_timeout;    /* Lock timeout period. */
01948 
01949         /* Logging. */
01950         u_int32_t        lg_bsize;      /* Buffer size. */
01951         u_int32_t        lg_size;       /* Log file size. */
01952         u_int32_t        lg_regionmax;  /* Region size. */
01953         int              lg_filemode;   /* Log file permission mode. */
01954 
01955         /* Memory pool. */
01956         u_int32_t        mp_gbytes;     /* Cachesize: GB. */
01957         u_int32_t        mp_bytes;      /* Cachesize: Bytes. */
01958         u_int            mp_ncache;     /* Number of cache regions. */
01959         size_t           mp_mmapsize;   /* Maximum file size for mmap. */
01960         int              mp_maxopenfd;  /* Maximum open file descriptors. */
01961         int              mp_maxwrite;   /* Maximum buffers to write. */
01962         int                             /* Sleep after writing max buffers. */
01963                          mp_maxwrite_sleep;
01964 
01965         /* Replication */
01966         int              rep_eid;       /* environment id. */
01967         int             (*rep_send)     /* Send function. */
01968                             __P((DB_ENV *, const DBT *, const DBT *,
01969                             const DB_LSN *, int, u_int32_t));
01970 
01971         /* Transactions. */
01972         u_int32_t        tx_max;        /* Maximum number of transactions. */
01973         time_t           tx_timestamp;  /* Recover to specific timestamp. */
01974         db_timeout_t     tx_timeout;    /* Timeout for transactions. */
01975 
01976         /* Thread tracking. */
01977         u_int32_t       thr_nbucket;    /* Number of hash buckets. */
01978         u_int32_t       thr_max;        /* Max before garbage collection. */
01979         void            *thr_hashtab;   /* Hash table of DB_THREAD_INFO. */
01980 
01981         /*******************************************************
01982          * Private: owned by DB.
01983          *******************************************************/
01984         pid_t           pid_cache;      /* Cached process ID. */
01985 
01986                                         /* User files, paths. */
01987         char            *db_home;       /* Database home. */
01988         char            *db_abshome;    /* Absolute path when started. */
01989         char            *db_log_dir;    /* Database log file directory. */
01990         char            *db_tmp_dir;    /* Database tmp file directory. */
01991 
01992         char           **db_data_dir;   /* Database data file directories. */
01993         int              data_cnt;      /* Database data file slots. */
01994         int              data_next;     /* Next Database data file slot. */
01995 
01996         int              db_mode;       /* Default open permissions. */
01997         int              dir_mode;      /* Intermediate directory perms. */
01998         void            *env_lref;      /* Locker in non-threaded handles. */
01999         u_int32_t        open_flags;    /* Flags passed to DB_ENV->open. */
02000 
02001         void            *reginfo;       /* REGINFO structure reference. */
02002         DB_FH           *lockfhp;       /* fcntl(2) locking file handle. */
02003 
02004         DB_FH           *registry;      /* DB_REGISTER file handle. */
02005         u_int32_t       registry_off;   /*
02006                                          * Offset of our slot.  We can't use
02007                                          * off_t because its size depends on
02008                                          * build settings.
02009                                          */
02010 
02011                                         /* Return ID, check if ID alive. */
02012         void           (*thread_id) __P((DB_ENV *, pid_t *, db_threadid_t *));
02013         int            (*is_alive) __P((DB_ENV *, pid_t, db_threadid_t));
02014         char           *(*thread_id_string)
02015                         __P((DB_ENV *, pid_t, db_threadid_t, char *));
02016 
02017         int           (**recover_dtab)  /* Dispatch table for recover funcs. */
02018                             __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
02019         size_t           recover_dtab_size;
02020                                         /* Slots in the dispatch table. */
02021 
02022         void            *cl_handle;     /* RPC: remote client handle. */
02023         u_int            cl_id;         /* RPC: remote client env id. */
02024 
02025         int              db_ref;        /* DB reference count. */
02026 
02027         long             shm_key;       /* shmget(2) key. */
02028 
02029         /*
02030          * List of open DB handles for this DB_ENV, used for cursor
02031          * adjustment.  Must be protected for multi-threaded support.
02032          *
02033          * !!!
02034          * As this structure is allocated in per-process memory, the
02035          * mutex may need to be stored elsewhere on architectures unable
02036          * to support mutexes in heap memory, e.g. HP/UX 9.
02037          *
02038          * !!!
02039          * Explicit representation of structure in queue.h.
02040          * LIST_HEAD(dblist, __db);
02041          */
02042         db_mutex_t mtx_dblist;          /* Mutex. */
02043         struct {
02044                 struct __db *lh_first;
02045         } dblist;
02046 
02047         /*
02048          * XA support.
02049          *
02050          * !!!
02051          * Explicit representations of structures from queue.h.
02052          * TAILQ_ENTRY(__db_env) links;
02053          * TAILQ_HEAD(xa_txn, __db_txn);
02054          */
02055         struct {
02056                 struct __db_env *tqe_next;
02057                 struct __db_env **tqe_prev;
02058         } links;
02059         struct __xa_txn {       /* XA Active Transactions. */
02060                 struct __db_txn *tqh_first;
02061                 struct __db_txn **tqh_last;
02062         } xa_txn;
02063         int              xa_rmid;       /* XA Resource Manager ID. */
02064 
02065         char            *passwd;        /* Cryptography support. */
02066         size_t           passwd_len;
02067         void            *crypto_handle; /* Primary handle. */
02068         db_mutex_t       mtx_mt;        /* Mersenne Twister mutex. */
02069         int              mti;           /* Mersenne Twister index. */
02070         u_long          *mt;            /* Mersenne Twister state vector. */
02071 
02072         /* API-private structure. */
02073         void            *api1_internal; /* C++, Perl API private */
02074         void            *api2_internal; /* Java API private */
02075 
02076         void *lg_handle;                /* Log handle. */
02077         void *lk_handle;                /* Lock handle. */
02078         void *mp_handle;                /* Mpool handle. */
02079         void *mutex_handle;             /* Mutex handle. */
02080         void *rep_handle;               /* Replication handle. */
02081         void *tx_handle;                /* Txn handle. */
02082 
02083         /* DB_ENV PUBLIC HANDLE LIST BEGIN */
02084         int  (*close) __P((DB_ENV *, u_int32_t));
02085         int  (*dbremove) __P((DB_ENV *,
02086                 DB_TXN *, const char *, const char *, u_int32_t));
02087         int  (*dbrename) __P((DB_ENV *,
02088                 DB_TXN *, const char *, const char *, const char *, u_int32_t));
02089         void (*err) __P((const DB_ENV *, int, const char *, ...));
02090         void (*errx) __P((const DB_ENV *, const char *, ...));
02091         int  (*failchk) __P((DB_ENV *, u_int32_t));
02092         int  (*fileid_reset) __P((DB_ENV *, const char *, u_int32_t));
02093         int  (*get_cachesize) __P((DB_ENV *, u_int32_t *, u_int32_t *, int *));
02094         int  (*get_data_dirs) __P((DB_ENV *, const char ***));
02095         int  (*get_encrypt_flags) __P((DB_ENV *, u_int32_t *));
02096         void (*get_errfile) __P((DB_ENV *, FILE **));
02097         void (*get_errpfx) __P((DB_ENV *, const char **));
02098         int  (*get_flags) __P((DB_ENV *, u_int32_t *));
02099         int  (*get_home) __P((DB_ENV *, const char **));
02100         int  (*get_lg_bsize) __P((DB_ENV *, u_int32_t *));
02101         int  (*get_lg_dir) __P((DB_ENV *, const char **));
02102         int  (*get_lg_filemode) __P((DB_ENV *, int *));
02103         int  (*get_lg_max) __P((DB_ENV *, u_int32_t *));
02104         int  (*get_lg_regionmax) __P((DB_ENV *, u_int32_t *));
02105         int  (*get_lk_conflicts) __P((DB_ENV *, const u_int8_t **, int *));
02106         int  (*get_lk_detect) __P((DB_ENV *, u_int32_t *));
02107         int  (*get_lk_max_lockers) __P((DB_ENV *, u_int32_t *));
02108         int  (*get_lk_max_locks) __P((DB_ENV *, u_int32_t *));
02109         int  (*get_lk_max_objects) __P((DB_ENV *, u_int32_t *));
02110         int  (*get_mp_max_openfd) __P((DB_ENV *, int *));
02111         int  (*get_mp_max_write) __P((DB_ENV *, int *, int *));
02112         int  (*get_mp_mmapsize) __P((DB_ENV *, size_t *));
02113         void (*get_msgfile) __P((DB_ENV *, FILE **));
02114         int  (*get_open_flags) __P((DB_ENV *, u_int32_t *));
02115         int  (*get_rep_limit) __P((DB_ENV *, u_int32_t *, u_int32_t *));
02116         int  (*get_shm_key) __P((DB_ENV *, long *));
02117         int  (*get_timeout) __P((DB_ENV *, db_timeout_t *, u_int32_t));
02118         int  (*get_tmp_dir) __P((DB_ENV *, const char **));
02119         int  (*get_tx_max) __P((DB_ENV *, u_int32_t *));
02120         int  (*get_tx_timestamp) __P((DB_ENV *, time_t *));
02121         int  (*get_verbose) __P((DB_ENV *, u_int32_t, int *));
02122         int  (*is_bigendian) __P((void));
02123         int  (*lock_detect) __P((DB_ENV *, u_int32_t, u_int32_t, int *));
02124         int  (*lock_get) __P((DB_ENV *,
02125                 u_int32_t, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
02126         int  (*lock_id) __P((DB_ENV *, u_int32_t *));
02127         int  (*lock_id_free) __P((DB_ENV *, u_int32_t));
02128         int  (*lock_put) __P((DB_ENV *, DB_LOCK *));
02129         int  (*lock_stat) __P((DB_ENV *, DB_LOCK_STAT **, u_int32_t));
02130         int  (*lock_stat_print) __P((DB_ENV *, u_int32_t));
02131         int  (*lock_vec) __P((DB_ENV *,
02132                 u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
02133         int  (*log_archive) __P((DB_ENV *, char **[], u_int32_t));
02134         int  (*log_cursor) __P((DB_ENV *, DB_LOGC **, u_int32_t));
02135         int  (*log_file) __P((DB_ENV *, const DB_LSN *, char *, size_t));
02136         int  (*log_flush) __P((DB_ENV *, const DB_LSN *));
02137         int  (*log_printf) __P((DB_ENV *, DB_TXN *, const char *, ...));
02138         int  (*log_put) __P((DB_ENV *, DB_LSN *, const DBT *, u_int32_t));
02139         int  (*log_stat) __P((DB_ENV *, DB_LOG_STAT **, u_int32_t));
02140         int  (*log_stat_print) __P((DB_ENV *, u_int32_t));
02141         int  (*lsn_reset) __P((DB_ENV *, const char *, u_int32_t));
02142         int  (*memp_fcreate) __P((DB_ENV *, DB_MPOOLFILE **, u_int32_t));
02143         int  (*memp_register) __P((DB_ENV *, int, int (*)(DB_ENV *,
02144                 db_pgno_t, void *, DBT *), int (*)(DB_ENV *,
02145                 db_pgno_t, void *, DBT *)));
02146         int  (*memp_stat) __P((DB_ENV *,
02147                 DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, u_int32_t));
02148         int  (*memp_stat_print) __P((DB_ENV *, u_int32_t));
02149         int  (*memp_sync) __P((DB_ENV *, DB_LSN *));
02150         int  (*memp_trickle) __P((DB_ENV *, int, int *));
02151         int  (*mutex_alloc) __P((DB_ENV *, u_int32_t, db_mutex_t *));
02152         int  (*mutex_free) __P((DB_ENV *, db_mutex_t));
02153         int  (*mutex_get_align) __P((DB_ENV *, u_int32_t *));
02154         int  (*mutex_get_increment) __P((DB_ENV *, u_int32_t *));
02155         int  (*mutex_get_max) __P((DB_ENV *, u_int32_t *));
02156         int  (*mutex_get_tas_spins) __P((DB_ENV *, u_int32_t *));
02157         int  (*mutex_lock) __P((DB_ENV *, db_mutex_t));
02158         int  (*mutex_set_align) __P((DB_ENV *, u_int32_t));
02159         int  (*mutex_set_increment) __P((DB_ENV *, u_int32_t));
02160         int  (*mutex_set_max) __P((DB_ENV *, u_int32_t));
02161         int  (*mutex_set_tas_spins) __P((DB_ENV *, u_int32_t));
02162         int  (*mutex_stat) __P((DB_ENV *, DB_MUTEX_STAT **, u_int32_t));
02163         int  (*mutex_stat_print) __P((DB_ENV *, u_int32_t));
02164         int  (*mutex_unlock) __P((DB_ENV *, db_mutex_t));
02165         int  (*open) __P((DB_ENV *, const char *, u_int32_t, int));
02166         int  (*remove) __P((DB_ENV *, const char *, u_int32_t));
02167         int  (*rep_elect)
02168                 __P((DB_ENV *, int, int, int, u_int32_t, int *, u_int32_t));
02169         int  (*rep_flush) __P((DB_ENV *));
02170         int  (*rep_get_config) __P((DB_ENV *, u_int32_t, int *));
02171         int  (*rep_process_message)
02172                 __P((DB_ENV *, DBT *, DBT *, int *, DB_LSN *));
02173         int  (*rep_set_config) __P((DB_ENV *, u_int32_t, int));
02174         int  (*rep_start) __P((DB_ENV *, DBT *, u_int32_t));
02175         int  (*rep_stat) __P((DB_ENV *, DB_REP_STAT **, u_int32_t));
02176         int  (*rep_stat_print) __P((DB_ENV *, u_int32_t));
02177         int  (*rep_sync) __P((DB_ENV *, u_int32_t));
02178         int  (*set_alloc) __P((DB_ENV *, void *(*)(size_t),
02179                 void *(*)(void *, size_t), void (*)(void *)));
02180         int  (*set_app_dispatch)
02181                 __P((DB_ENV *, int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops)));
02182         int  (*set_cachesize) __P((DB_ENV *, u_int32_t, u_int32_t, int));
02183         int  (*set_data_dir) __P((DB_ENV *, const char *));
02184         int  (*set_encrypt) __P((DB_ENV *, const char *, u_int32_t));
02185         void (*set_errcall) __P((DB_ENV *,
02186                 void (*)(const DB_ENV *, const char *, const char *)));
02187         void (*set_errfile) __P((DB_ENV *, FILE *));
02188         void (*set_errpfx) __P((DB_ENV *, const char *));
02189         int  (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
02190         int  (*set_flags) __P((DB_ENV *, u_int32_t, int));
02191         int  (*set_intermediate_dir) __P((DB_ENV *, int, u_int32_t));
02192         int  (*set_isalive) __P((DB_ENV *,
02193                 int (*)(DB_ENV *, pid_t, db_threadid_t)));
02194         int  (*set_lg_bsize) __P((DB_ENV *, u_int32_t));
02195         int  (*set_lg_dir) __P((DB_ENV *, const char *));
02196         int  (*set_lg_filemode) __P((DB_ENV *, int));
02197         int  (*set_lg_max) __P((DB_ENV *, u_int32_t));
02198         int  (*set_lg_regionmax) __P((DB_ENV *, u_int32_t));
02199         int  (*set_lk_conflicts) __P((DB_ENV *, u_int8_t *, int));
02200         int  (*set_lk_detect) __P((DB_ENV *, u_int32_t));
02201         int  (*set_lk_max) __P((DB_ENV *, u_int32_t));
02202         int  (*set_lk_max_lockers) __P((DB_ENV *, u_int32_t));
02203         int  (*set_lk_max_locks) __P((DB_ENV *, u_int32_t));
02204         int  (*set_lk_max_objects) __P((DB_ENV *, u_int32_t));
02205         int  (*set_mp_max_openfd) __P((DB_ENV *, int));
02206         int  (*set_mp_max_write) __P((DB_ENV *, int, int));
02207         int  (*set_mp_mmapsize) __P((DB_ENV *, size_t));
02208         void (*set_msgcall)
02209                 __P((DB_ENV *, void (*)(const DB_ENV *, const char *)));
02210         void (*set_msgfile) __P((DB_ENV *, FILE *));
02211         int  (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int)));
02212         int  (*set_rep_limit) __P((DB_ENV *, u_int32_t, u_int32_t));
02213         int  (*set_rep_request) __P((DB_ENV *, u_int32_t, u_int32_t));
02214         int  (*set_rep_transport) __P((DB_ENV *, int, int (*)(DB_ENV *,
02215                 const DBT *, const DBT *, const DB_LSN *, int, u_int32_t)));
02216         int  (*set_rpc_server)
02217                 __P((DB_ENV *, void *, const char *, long, long, u_int32_t));
02218         int  (*set_shm_key) __P((DB_ENV *, long));
02219         int  (*set_thread_count) __P((DB_ENV *, u_int32_t));
02220         int  (*set_thread_id) __P((DB_ENV *,
02221                 void (*)(DB_ENV *, pid_t *, db_threadid_t *)));
02222         int  (*set_thread_id_string) __P((DB_ENV *,
02223                 char *(*)(DB_ENV *, pid_t, db_threadid_t, char *)));
02224         int  (*set_timeout) __P((DB_ENV *, db_timeout_t, u_int32_t));
02225         int  (*set_tmp_dir) __P((DB_ENV *, const char *));
02226         int  (*set_tx_max) __P((DB_ENV *, u_int32_t));
02227         int  (*set_tx_timestamp) __P((DB_ENV *, time_t *));
02228         int  (*set_verbose) __P((DB_ENV *, u_int32_t, int));
02229         int  (*stat_print) __P((DB_ENV *, u_int32_t));
02230         int  (*txn_begin) __P((DB_ENV *, DB_TXN *, DB_TXN **, u_int32_t));
02231         int  (*txn_checkpoint) __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
02232         int  (*txn_recover)
02233                 __P((DB_ENV *, DB_PREPLIST *, long, long *, u_int32_t));
02234         int  (*txn_stat) __P((DB_ENV *, DB_TXN_STAT **, u_int32_t));
02235         int  (*txn_stat_print) __P((DB_ENV *, u_int32_t));
02236         /* DB_ENV PUBLIC HANDLE LIST END */
02237 
02238         /* DB_ENV PRIVATE HANDLE LIST BEGIN */
02239         int  (*prdbt) __P((DBT *,
02240                 int, const char *, void *, int (*)(void *, const void *), int));
02241         /* DB_ENV PRIVATE HANDLE LIST END */
02242 
02243 #define DB_TEST_ELECTINIT        1      /* after __rep_elect_init */
02244 #define DB_TEST_ELECTVOTE1       2      /* after sending VOTE1 */
02245 #define DB_TEST_POSTDESTROY      3      /* after destroy op */
02246 #define DB_TEST_POSTLOG          4      /* after logging all pages */
02247 #define DB_TEST_POSTLOGMETA      5      /* after logging meta in btree */
02248 #define DB_TEST_POSTOPEN         6      /* after __os_open */
02249 #define DB_TEST_POSTSYNC         7      /* after syncing the log */
02250 #define DB_TEST_PREDESTROY       8      /* before destroy op */
02251 #define DB_TEST_PREOPEN          9      /* before __os_open */
02252 #define DB_TEST_SUBDB_LOCKS      10     /* subdb locking tests */
02253         int              test_abort;    /* Abort value for testing. */
02254         int              test_check;    /* Checkpoint value for testing. */
02255         int              test_copy;     /* Copy value for testing. */
02256 
02257 #define DB_ENV_AUTO_COMMIT      0x0000001 /* DB_AUTO_COMMIT. */
02258 #define DB_ENV_CDB              0x0000002 /* DB_INIT_CDB. */
02259 #define DB_ENV_CDB_ALLDB        0x0000004 /* CDB environment wide locking. */
02260 #define DB_ENV_CREATE           0x0000008 /* DB_CREATE set. */
02261 #define DB_ENV_DBLOCAL          0x0000010 /* DB_ENV allocated for private DB. */
02262 #define DB_ENV_DIRECT_DB        0x0000020 /* DB_DIRECT_DB set. */
02263 #define DB_ENV_DIRECT_LOG       0x0000040 /* DB_DIRECT_LOG set. */
02264 #define DB_ENV_DSYNC_DB         0x0000080 /* DB_DSYNC_DB set. */
02265 #define DB_ENV_DSYNC_LOG        0x0000100 /* DB_DSYNC_LOG set. */
02266 #define DB_ENV_FATAL            0x0000200 /* Doing fatal recovery in env. */
02267 #define DB_ENV_LOCKDOWN         0x0000400 /* DB_LOCKDOWN set. */
02268 #define DB_ENV_LOG_AUTOREMOVE   0x0000800 /* DB_LOG_AUTOREMOVE set. */
02269 #define DB_ENV_LOG_INMEMORY     0x0001000 /* DB_LOG_INMEMORY set. */
02270 #define DB_ENV_NOLOCKING        0x0002000 /* DB_NOLOCKING set. */
02271 #define DB_ENV_NOMMAP           0x0004000 /* DB_NOMMAP set. */
02272 #define DB_ENV_NOPANIC          0x0008000 /* Okay if panic set. */
02273 #define DB_ENV_OPEN_CALLED      0x0010000 /* DB_ENV->open called. */
02274 #define DB_ENV_OVERWRITE        0x0020000 /* DB_OVERWRITE set. */
02275 #define DB_ENV_PRIVATE          0x0040000 /* DB_PRIVATE set. */
02276 #define DB_ENV_REGION_INIT      0x0080000 /* DB_REGION_INIT set. */
02277 #define DB_ENV_RPCCLIENT        0x0100000 /* DB_RPCCLIENT set. */
02278 #define DB_ENV_RPCCLIENT_GIVEN  0x0200000 /* User-supplied RPC client struct */
02279 #define DB_ENV_SYSTEM_MEM       0x0400000 /* DB_SYSTEM_MEM set. */
02280 #define DB_ENV_THREAD           0x0800000 /* DB_THREAD set. */
02281 #define DB_ENV_TIME_NOTGRANTED  0x1000000 /* DB_TIME_NOTGRANTED set. */
02282 #define DB_ENV_TXN_NOSYNC       0x2000000 /* DB_TXN_NOSYNC set. */
02283 #define DB_ENV_TXN_WRITE_NOSYNC 0x4000000 /* DB_TXN_WRITE_NOSYNC set. */
02284 #define DB_ENV_YIELDCPU         0x8000000 /* DB_YIELDCPU set. */
02285         u_int32_t flags;
02286 };
02287 
02288 #ifndef DB_DBM_HSEARCH
02289 #define DB_DBM_HSEARCH  0               /* No historic interfaces by default. */
02290 #endif
02291 #if DB_DBM_HSEARCH != 0
02292 /*******************************************************
02293  * Dbm/Ndbm historic interfaces.
02294  *******************************************************/
02295 typedef struct __db DBM;
02296 
02297 #define DBM_INSERT      0               /* Flags to dbm_store(). */
02298 #define DBM_REPLACE     1
02299 
02300 /*
02301  * The DB support for ndbm(3) always appends this suffix to the
02302  * file name to avoid overwriting the user's original database.
02303  */
02304 #define DBM_SUFFIX      ".db"
02305 
02306 #if defined(_XPG4_2)
02307 typedef struct {
02308         char *dptr;
02309         size_t dsize;
02310 } datum;
02311 #else
02312 typedef struct {
02313         char *dptr;
02314         int dsize;
02315 } datum;
02316 #endif
02317 
02318 /*
02319  * Translate NDBM calls into DB calls so that DB doesn't step on the
02320  * application's name space.
02321  */
02322 #define dbm_clearerr(a)         __db_ndbm_clearerr(a)
02323 #define dbm_close(a)            __db_ndbm_close(a)
02324 #define dbm_delete(a, b)        __db_ndbm_delete(a, b)
02325 #define dbm_dirfno(a)           __db_ndbm_dirfno(a)
02326 #define dbm_error(a)            __db_ndbm_error(a)
02327 #define dbm_fetch(a, b)         __db_ndbm_fetch(a, b)
02328 #define dbm_firstkey(a)         __db_ndbm_firstkey(a)
02329 #define dbm_nextkey(a)          __db_ndbm_nextkey(a)
02330 #define dbm_open(a, b, c)       __db_ndbm_open(a, b, c)
02331 #define dbm_pagfno(a)           __db_ndbm_pagfno(a)
02332 #define dbm_rdonly(a)           __db_ndbm_rdonly(a)
02333 #define dbm_store(a, b, c, d) \
02334         __db_ndbm_store(a, b, c, d)
02335 
02336 /*
02337  * Translate DBM calls into DB calls so that DB doesn't step on the
02338  * application's name space.
02339  *
02340  * The global variables dbrdonly, dirf and pagf were not retained when 4BSD
02341  * replaced the dbm interface with ndbm, and are not supported here.
02342  */
02343 #define dbminit(a)      __db_dbm_init(a)
02344 #define dbmclose        __db_dbm_close
02345 #if !defined(__cplusplus)
02346 #define delete(a)       __db_dbm_delete(a)
02347 #endif
02348 #define fetch(a)        __db_dbm_fetch(a)
02349 #define firstkey        __db_dbm_firstkey
02350 #define nextkey(a)      __db_dbm_nextkey(a)
02351 #define store(a, b)     __db_dbm_store(a, b)
02352 
02353 /*******************************************************
02354  * Hsearch historic interface.
02355  *******************************************************/
02356 typedef enum {
02357         FIND, ENTER
02358 } ACTION;
02359 
02360 typedef struct entry {
02361         char *key;
02362         char *data;
02363 } ENTRY;
02364 
02365 #define hcreate(a)      __db_hcreate(a)
02366 #define hdestroy        __db_hdestroy
02367 #define hsearch(a, b)   __db_hsearch(a, b)
02368 
02369 #endif /* DB_DBM_HSEARCH */
02370 
02371 #if defined(__cplusplus)
02372 }
02373 #endif
02374 #endif /* !_DB_H_ */
02375 
02376 /* DO NOT EDIT: automatically built by dist/s_include. */
02377 #ifndef _DB_EXT_PROT_IN_
02378 #define _DB_EXT_PROT_IN_
02379 
02380 #if defined(__cplusplus)
02381 extern "C" {
02382 #endif
02383 
02384 int db_create __P((DB **, DB_ENV *, u_int32_t));
02385 char *db_strerror __P((int));
02386 int db_env_create __P((DB_ENV **, u_int32_t));
02387 char *db_version __P((int *, int *, int *));
02388 int log_compare __P((const DB_LSN *, const DB_LSN *));
02389 int db_env_set_func_close __P((int (*)(int)));
02390 int db_env_set_func_dirfree __P((void (*)(char **, int)));
02391 int db_env_set_func_dirlist __P((int (*)(const char *, char ***, int *)));
02392 int db_env_set_func_exists __P((int (*)(const char *, int *)));
02393 int db_env_set_func_free __P((void (*)(void *)));
02394 int db_env_set_func_fsync __P((int (*)(int)));
02395 int db_env_set_func_ftruncate __P((int (*)(int, off_t)));
02396 int db_env_set_func_ioinfo __P((int (*)(const char *, int, u_int32_t *, u_int32_t *, u_int32_t *)));
02397 int db_env_set_func_malloc __P((void *(*)(size_t)));
02398 int db_env_set_func_map __P((int (*)(char *, size_t, int, int, void **)));
02399 int db_env_set_func_pread __P((ssize_t (*)(int, void *, size_t, off_t)));
02400 int db_env_set_func_pwrite __P((ssize_t (*)(int, const void *, size_t, off_t)));
02401 int db_env_set_func_open __P((int (*)(const char *, int, ...)));
02402 int db_env_set_func_read __P((ssize_t (*)(int, void *, size_t)));
02403 int db_env_set_func_realloc __P((void *(*)(void *, size_t)));
02404 int db_env_set_func_rename __P((int (*)(const char *, const char *)));
02405 int db_env_set_func_seek __P((int (*)(int, off_t, int)));
02406 int db_env_set_func_sleep __P((int (*)(u_long, u_long)));
02407 int db_env_set_func_unlink __P((int (*)(const char *)));
02408 int db_env_set_func_unmap __P((int (*)(void *, size_t)));
02409 int db_env_set_func_write __P((ssize_t (*)(int, const void *, size_t)));
02410 int db_env_set_func_yield __P((int (*)(void)));
02411 int db_sequence_create __P((DB_SEQUENCE **, DB *, u_int32_t));
02412 #if DB_DBM_HSEARCH != 0
02413 int      __db_ndbm_clearerr __P((DBM *));
02414 void     __db_ndbm_close __P((DBM *));
02415 int      __db_ndbm_delete __P((DBM *, datum));
02416 int      __db_ndbm_dirfno __P((DBM *));
02417 int      __db_ndbm_error __P((DBM *));
02418 datum __db_ndbm_fetch __P((DBM *, datum));
02419 datum __db_ndbm_firstkey __P((DBM *));
02420 datum __db_ndbm_nextkey __P((DBM *));
02421 DBM     *__db_ndbm_open __P((const char *, int, int));
02422 int      __db_ndbm_pagfno __P((DBM *));
02423 int      __db_ndbm_rdonly __P((DBM *));
02424 int      __db_ndbm_store __P((DBM *, datum, datum, int));
02425 int      __db_dbm_close __P((void));
02426 int      __db_dbm_delete __P((datum));
02427 datum __db_dbm_fetch __P((datum));
02428 datum __db_dbm_firstkey __P((void));
02429 int      __db_dbm_init __P((char *));
02430 datum __db_dbm_nextkey __P((datum));
02431 int      __db_dbm_store __P((datum, datum));
02432 #endif
02433 #if DB_DBM_HSEARCH != 0
02434 int __db_hcreate __P((size_t));
02435 ENTRY *__db_hsearch __P((ENTRY, ACTION));
02436 void __db_hdestroy __P((void));
02437 #endif
02438 
02439 #if defined(__cplusplus)
02440 }
02441 #endif
02442 #endif /* !_DB_EXT_PROT_IN_ */

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