db

db.h

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996, 1997, 1998, 1999, 2000
00005  * Sleepycat Software. All rights reserved.
00006  *
00007  * $Id: db_8h-source.html,v 1.1 2008年06月08日 10:16:35 sebdiaz Exp $
00008  */
00009 
00010 #ifndef _DB_H_
00011 #define _DB_H_
00012 
00013 #ifndef __NO_SYSTEM_INCLUDES
00014 #include <sys/types.h>
00015 
00016 #include <stdio.h>
00017 #endif
00018 
00019 #if defined(__cplusplus)
00020 extern "C" {
00021 #endif
00022 
00023 /*
00024  * XXX
00025  * MacOS: ensure that Metrowerks C makes enumeration types int sized.
00026  */
00027 #ifdef __MWERKS__
00028 #pragma enumsalwaysint on
00029 #endif
00030 
00031 /*
00032  * XXX
00033  * Handle function prototypes and the keyword "const". This steps on name
00034  * space that DB doesn't control, but all of the other solutions are worse.
00035  *
00036  * XXX
00037  * While Microsoft's compiler is ANSI C compliant, it doesn't have _STDC_
00038  * defined by default, you specify a command line flag or #pragma to turn
00039  * it on. Don't do that, however, because some of Microsoft's own header
00040  * files won't compile.
00041  */
00042 #undef __P
00043 #if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER)
00044 #define __P(protos) protos /* ANSI C prototypes */
00045 #else
00046 #define const
00047 #define __P(protos) () /* K&R C preprocessor */
00048 #endif
00049 
00050 /*
00051  * !!!
00052  * DB needs basic information about specifically sized types. If they're
00053  * not provided by the system, typedef them here.
00054  *
00055  * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
00056  * as does BIND and Kerberos, since we don't know for sure what #include
00057  * files the user is using.
00058  *
00059  * !!!
00060  * We also provide the standard u_int, u_long etc., if they're not provided
00061  * by the system.
00062  */
00063 #ifndef __BIT_TYPES_DEFINED__
00064 #define __BIT_TYPES_DEFINED__
00065 
00066 
00067 
00068 
00069 
00070 #endif
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 #define DB_VERSION_MAJOR 3
00079 #define DB_VERSION_MINOR 1
00080 #define DB_VERSION_PATCH 14
00081 #define DB_VERSION_STRING "Sleepycat Software: Berkeley DB 3.1.14: (June, 2000)"
00082 
00083 typedef u_int32_t db_pgno_t; /* Page number type. */
00084 typedef u_int16_t db_indx_t; /* Page offset type. */
00085 #define DB_MAX_PAGES 0xffffffff /* >= # of pages in a file */
00086 
00087 typedef u_int32_t db_recno_t; /* Record number type. */
00088 #define DB_MAX_RECORDS 0xffffffff /* >= # of records in a tree */
00089 
00090 /* Forward structure declarations, so applications get type checking. */
00091 struct __db; typedef struct __db DB;
00092 #ifdef DB_DBM_HSEARCH
00093 typedef struct __db DBM;
00094 #endif
00095 struct __db_bt_stat; typedef struct __db_bt_stat DB_BTREE_STAT;
00096 struct __db_dbt; typedef struct __db_dbt DBT;
00097 struct __db_env; typedef struct __db_env DB_ENV;
00098 struct __db_h_stat; typedef struct __db_h_stat DB_HASH_STAT;
00099 struct __db_ilock; typedef struct __db_ilock DB_LOCK_ILOCK;
00100 struct __db_lock_stat; typedef struct __db_lock_stat DB_LOCK_STAT;
00101 struct __db_lock_u; typedef struct __db_lock_u DB_LOCK;
00102 struct __db_lockreq; typedef struct __db_lockreq DB_LOCKREQ;
00103 struct __db_log_stat; typedef struct __db_log_stat DB_LOG_STAT;
00104 struct __db_lsn; typedef struct __db_lsn DB_LSN;
00105 struct __db_mpool_finfo;typedef struct __db_mpool_finfo DB_MPOOL_FINFO;
00106 struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
00107 struct __db_mpool_stat; typedef struct __db_mpool_stat DB_MPOOL_STAT;
00108 struct __db_mpoolfile; typedef struct __db_mpoolfile DB_MPOOLFILE;
00109 struct __db_qam_stat; typedef struct __db_qam_stat DB_QUEUE_STAT;
00110 struct __db_txn; typedef struct __db_txn DB_TXN;
00111 struct __db_txn_active; typedef struct __db_txn_active DB_TXN_ACTIVE;
00112 struct __db_txn_stat; typedef struct __db_txn_stat DB_TXN_STAT;
00113 struct __dbc; typedef struct __dbc DBC;
00114 struct __dbc_internal; typedef struct __dbc_internal DBC_INTERNAL;
00115 struct __fh_t; typedef struct __fh_t DB_FH;
00116 struct __key_range; typedef struct __key_range DB_KEY_RANGE;
00117 struct __db_cmpr_info; typedef struct __db_cmpr_info DB_CMPR_INFO;
00118 
00119 /* Key/data structure -- a Data-Base Thang. */
00120 struct __db_dbt {
00121 /*
00122  * data/size must be fields 1 and 2 for DB 1.85 compatibility.
00123  */
00124 void *data; /* Key/data */
00125 u_int32_t size; /* key/data length */
00126 
00127 u_int32_t ulen; /* RO: length of user buffer. */
00128 u_int32_t dlen; /* RO: get/put record length. */
00129 u_int32_t doff; /* RO: get/put record offset. */
00130 
00131 #define DB_DBT_ISSET 0x001 /* Lower level calls set value. */
00132 #define DB_DBT_MALLOC 0x002 /* Return in malloc'd memory. */
00133 #define DB_DBT_PARTIAL 0x004 /* Partial put/get. */
00134 #define DB_DBT_REALLOC 0x008 /* Return in realloc'd memory. */
00135 #define DB_DBT_USERMEM 0x010 /* Return in user's memory. */
00136 #define DB_DBT_DUPOK 0x020 /* Insert if duplicate. */
00137 u_int32_t flags;
00138 
00139 void *app_private; /* Key/data application private. */
00140 };
00141 
00142 /*
00143  * Information from user specified page compression
00144  */
00145 struct __db_cmpr_info {
00146 int (*compress) /* Compression function */
00147 __P((DB_ENV *, const u_int8_t*, int, u_int8_t**, int*,void *));
00148 int (*uncompress) /* Uncompression function */
00149 __P((DB_ENV *, const u_int8_t*, int, u_int8_t*, int,void *));
00150 u_int8_t coefficient; /* Compression factor is 1<<coefficient */
00151 u_int8_t max_npages; /* Max number of pages worst case */
00152 void *user_data; /* Persistent information for compression functions */
00153 };
00154 
00155 /*
00156  * Flags understood by both CDB_db_env_create and CDB_db_create.
00157  */
00158 #define DB_CXX_NO_EXCEPTIONS 0x000001 /* C++: return error values. */
00159 
00160 /*
00161  * Flags understood by only CDB_db_env_create.
00162  */
00163 #define DB_CLIENT 0x000002 /* Open for a client environment. */
00164 
00165 /*
00166  * Flags understood by only CDB_db_create.
00167  */
00168 #define DB_XA_CREATE 0x000002 /* Open in an XA environment. */
00169 
00170 /*
00171  * Flags understood by both DBENV->open and DB->open.
00172  */
00173 #define DB_CREATE 0x000001 /* Create file as necessary. */
00174 #define DB_NOMMAP 0x000002 /* Don't mmap underlying file. */
00175 #define DB_THREAD 0x000004 /* Applications are threaded. */
00176 
00177 /*
00178  * Flags understood by both DBENV->open and DBENV->remove.
00179  */
00180 #define DB_FORCE 0x000008 /* Force (anything). */
00181 #define DB_INIT_CDB 0x000010 /* Concurrent Access Methods. */
00182 #define DB_INIT_LOCK 0x000020 /* Initialize locking. */
00183 #define DB_INIT_LOG 0x000040 /* Initialize logging. */
00184 #define DB_INIT_MPOOL 0x000080 /* Initialize mpool. */
00185 #define DB_INIT_TXN 0x000100 /* Initialize transactions. */
00186 #define DB_RECOVER 0x000200 /* Run normal recovery. */
00187 #define DB_RECOVER_FATAL 0x000400 /* Run catastrophic recovery. */
00188 #define DB_SYSTEM_MEM 0x000800 /* Use system-backed memory. */
00189 #define DB_TXN_NOSYNC 0x001000 /* Do not sync log on commit. */
00190 #define DB_USE_ENVIRON 0x002000 /* Use the environment. */
00191 #define DB_USE_ENVIRON_ROOT 0x004000 /* Use the environment if root. */
00192 
00193 /*
00194  * Flags understood by only DBENV->open.
00195  */
00196 #define DB_LOCKDOWN 0x008000 /* Lock memory into physical core. */
00197 #define DB_PRIVATE 0x010000 /* DB_ENV is process local. */
00198 
00199 /*
00200  * Flags understood by DBENV->CDB_txn_begin.
00201  */
00202 /* DB_TXN_NOSYNC 0x001000 Do not sync log on commit. */
00203 #define DB_TXN_SYNC 0x000001 /* Always sync log on commit. */
00204 #define DB_TXN_NOWAIT 0x000002 /* Do not wait for locks in this TXN. */
00205 
00206 /*
00207  * Flags understood by only DB->open.
00208  */
00209 #define DB_EXCL 0x000008 /* Exclusive open (O_EXCL). */
00210 #define DB_RDONLY 0x000010 /* Read-only (O_RDONLY). */
00211 #define DB_TRUNCATE 0x000020 /* Discard existing DB (O_TRUNC). */
00212 #define DB_FCNTL_LOCKING 0x000040 /* Undocumented: fcntl(2) locking. */
00213 #define DB_ODDFILESIZE 0x000080 /* Undocumented: trunc. to N*pgsize. */
00214 #define DB_RDWRMASTER 0x000100 /* Undoc: allow subdb master open R/W */
00215 #define DB_COMPRESS 0x000200 /* Transparent I/O compression */
00216 
00217 /*
00218  * Flags understood by DB->verify.
00219  *
00220  * !!!
00221  * These must not go over 0x8000, or they will collide with the flags
00222  * used by CDB___bam_vrfy_subtree.
00223  */
00224 #define DB_AGGRESSIVE 0x0001 /* Salvage anything which might be data.*/
00225 #define DB_NOORDERCHK 0x0002 /* Skip order check; subdb w/ user func */
00226 #define DB_ORDERCHKONLY 0x0004 /* Only perform an order check on subdb */
00227 #define DB_PR_PAGE 0x0008 /* Show page contents (-da). */
00228 #define DB_PR_HEADERS 0x0010 /* Show only page headers (-dh). */
00229 #define DB_PR_RECOVERYTEST 0x0020 /* Recovery test (-dr). */
00230 #define DB_SALVAGE 0x0040 /* Salvage what looks like data. */
00231 #define DB_VRFY_FLAGMASK 0xffff /* For masking above flags. */
00232 
00233 /*
00234  * Flags understood by only DB->set_feedback's callback.
00235  */
00236 /* DB_RECOVER 0x000200 Running recovery. */
00237 #define DB_UPGRADE 0x000001 /* Upgrading. */
00238 
00239 /*
00240  * Deadlock detector modes; used in the DBENV structure to configure the
00241  * locking subsystem.
00242  */
00243 #define DB_LOCK_NORUN 0
00244 #define DB_LOCK_DEFAULT 1 /* Default policy. */
00245 #define DB_LOCK_OLDEST 2 /* Abort oldest transaction. */
00246 #define DB_LOCK_RANDOM 3 /* Abort random transaction. */
00247 #define DB_LOCK_YOUNGEST 4 /* Abort youngest transaction. */
00248 
00249 /*
00250  * Flags understood by only DB->set_flags.
00251  */
00252 #define DB_DUP 0x0001 /* Btree, Hash: duplicate keys. */
00253 #define DB_DUPSORT 0x0002 /* Btree, Hash: duplicate keys. */
00254 #define DB_RECNUM 0x0004 /* Btree: record numbers. */
00255 #define DB_RENUMBER 0x0008 /* Recno: renumber on insert/delete. */
00256 #define DB_REVSPLITOFF 0x0010 /* Btree: turn off reverse splits. */
00257 #define DB_SNAPSHOT 0x0020 /* Recno: snapshot the input. */
00258 
00259 /*
00260  * Flags understood only by DB->join.
00261  */
00262 #define DB_JOIN_NOSORT 0x0001 /* Don't try to optimize join. */
00263 
00264 typedef enum {
00265 DB_TXN_ABORT,
00266 DB_TXN_BACKWARD_ROLL,
00267 DB_TXN_FORWARD_ROLL,
00268 DB_TXN_OPENFILES
00269 } db_recops;
00270 
00271 #define DB_UNDO(op) ((op) == DB_TXN_ABORT || (op) == DB_TXN_BACKWARD_ROLL)
00272 #define DB_REDO(op) ((op) == DB_TXN_FORWARD_ROLL)
00273 
00274 #define DB_MONITOR(e) ((e)->mp_monitor)
00275 
00276 struct __db_env {
00277 /*******************************************************
00278  * Public: owned by the application.
00279  *******************************************************/
00280 FILE *db_errfile; /* Error message file stream. */
00281 const char *db_errpfx; /* Error message prefix. */
00282 /* Callbacks. */
00283 void (*db_errcall) __P((const char *, char *));
00284 void (*db_feedback) __P((DB_ENV *, int, int));
00285 void (*db_paniccall) __P((DB_ENV *, int));
00286 int (*db_recovery_init) __P((DB_ENV *));
00287 
00288 /*
00289  * Currently, the verbose list is a bit field with room for 32
00290  * entries. There's no reason that it needs to be limited, if
00291  * there are ever more than 32 entries, convert to a bit array.
00292  */
00293 #define DB_VERB_CHKPOINT 0x0001 /* List checkpoints. */
00294 #define DB_VERB_DEADLOCK 0x0002 /* Deadlock detection information. */
00295 #define DB_VERB_RECOVERY 0x0004 /* Recovery information. */
00296 #define DB_VERB_WAITSFOR 0x0008 /* Dump waits-for table. */
00297 u_int32_t verbose; /* Verbose output. */
00298 
00299 /* Locking. */
00300 u_int8_t *lk_conflicts; /* Two dimensional conflict matrix. */
00301 u_int32_t lk_modes; /* Number of lock modes in table. */
00302 u_int32_t lk_max; /* Maximum number of locks. */
00303 u_int32_t lk_detect; /* Deadlock detect on all conflicts. */
00304 
00305 /* Logging. */
00306 u_int32_t lg_bsize; /* Buffer size. */
00307 u_int32_t lg_max; /* Maximum file size. */
00308 
00309 /* Memory pool. */
00310 u_int32_t mp_gbytes; /* Cachesize: GB. */
00311 u_int32_t mp_bytes; /* Cachesize: Bytes. */
00312 size_t mp_size; /* DEPRECATED: Cachesize: bytes. */
00313 int mp_ncache; /* Number of cache regions. */
00314 size_t mp_mmapsize; /* Maximum file size for mmap. */
00315 DB_CMPR_INFO * mp_cmpr_info; /* Compression info. */
00316 void * mp_monitor; /* Monitoring tool. */
00317 void * app_private; /* Private application pointer. */
00318 
00319 /* Transactions. */
00320 u_int32_t tx_max; /* Maximum number of transactions. */
00321 time_t tx_timestamp; /* Recover to specific timestamp. */
00322 int (*tx_recover) /* Dispatch function for recovery. */
00323 __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
00324 
00325 /*******************************************************
00326  * Private: owned by DB.
00327  *******************************************************/
00328 int db_panic; /* Panic causing errno. */
00329 
00330 /* User files, paths. */
00331 char *db_home; /* Database home. */
00332 char *db_log_dir; /* Database log file directory. */
00333 char *db_tmp_dir; /* Database tmp file directory. */
00334 
00335 char **db_data_dir; /* Database data file directories. */
00336 int data_cnt; /* Database data file slots. */
00337 int data_next; /* Next Database data file slot. */
00338 
00339 int db_mode; /* Default open permissions. */
00340 
00341 void *reginfo; /* REGINFO structure reference. */
00342 DB_FH *lockfhp; /* fcntl(2) locking file handle. */
00343 long shm_key; /* shmget(2) key. */
00344 
00345 void *lg_handle; /* Log handle. */
00346 
00347 void *lk_handle; /* Lock handle. */
00348 
00349 void *mp_handle; /* Mpool handle. */
00350 
00351 void *tx_handle; /* Txn handle. */
00352 
00353 int (**dtab) /* Dispatch table */
00354 __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
00355 size_t dtab_size; /* Slots in the dispatch table. */
00356 
00357 void *cl_handle; /* RPC: remote client handle. */
00358 long cl_id; /* RPC: Remote client env id. */
00359 
00360 int dblocal_ref; /* DB_ENV_DBLOCAL: reference count. */
00361 
00362 /*
00363  * XA support.
00364  *
00365  * !!!
00366  * Explicit representations of structures in queue.h.
00367  *
00368  * TAILQ_ENTRY(__db_env);
00369  */
00370 struct {
00371 struct __db_env *tqe_next;
00372 struct __db_env **tqe_prev;
00373 } links;
00374 int xa_rmid; /* XA Resource Manager ID. */
00375 DB_TXN *xa_txn; /* XA Current transaction. */
00376 
00377 void *cj_internal; /* C++/Java private. */
00378 
00379 /* Methods. */
00380 int (*close) __P((DB_ENV *, u_int32_t));
00381 void (*err) __P((const DB_ENV *, int, const char *, ...));
00382 void (*errx) __P((const DB_ENV *, const char *, ...));
00383 int (*open) __P((DB_ENV *, const char *, u_int32_t, int));
00384 int (*remove) __P((DB_ENV *, const char *, u_int32_t));
00385 int (*set_data_dir) __P((DB_ENV *, const char *));
00386 void (*set_errcall) __P((DB_ENV *, void (*)(const char *, char *)));
00387 void (*set_errfile) __P((DB_ENV *, FILE *));
00388 void (*set_errpfx) __P((DB_ENV *, const char *));
00389 int (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
00390 int (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int)));
00391 int (*set_recovery_init) __P((DB_ENV *, int (*)(DB_ENV *)));
00392 int (*set_server) __P((DB_ENV *, char *, long, long, u_int32_t));
00393 int (*set_shm_key) __P((DB_ENV *, long));
00394 int (*set_tmp_dir) __P((DB_ENV *, const char *));
00395 int (*set_verbose) __P((DB_ENV *, u_int32_t, int));
00396 
00397 int (*set_lg_bsize) __P((DB_ENV *, u_int32_t));
00398 int (*set_lg_dir) __P((DB_ENV *, const char *));
00399 int (*set_lg_max) __P((DB_ENV *, u_int32_t));
00400 
00401 int (*set_lk_conflicts) __P((DB_ENV *, u_int8_t *, int));
00402 int (*set_lk_detect) __P((DB_ENV *, u_int32_t));
00403 int (*set_lk_max) __P((DB_ENV *, u_int32_t));
00404 
00405 int (*set_mp_mmapsize) __P((DB_ENV *, size_t));
00406 int (*set_cachesize) __P((DB_ENV *, u_int32_t, u_int32_t, int));
00407 
00408 int (*set_tx_max) __P((DB_ENV *, u_int32_t));
00409 int (*set_tx_recover) __P((DB_ENV *,
00410 int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops, void *)));
00411 int (*set_tx_timestamp) __P((DB_ENV *, time_t *));
00412 
00413 #ifdef CONFIG_TEST
00414 #define DB_TEST_PREOPEN 1 /* before CDB___os_open */
00415 #define DB_TEST_POSTOPEN 2 /* after CDB___os_open */
00416 #define DB_TEST_POSTLOGMETA 3 /* after logging meta in btree */
00417 #define DB_TEST_POSTLOG 4 /* after logging all pages */
00418 #define DB_TEST_POSTSYNC 5 /* after syncing the log */
00419 #define DB_TEST_PRERENAME 6 /* before CDB___os_rename */
00420 #define DB_TEST_POSTRENAME 7 /* after CDB___os_rename */
00421 int test_abort; /* Abort value for testing. */
00422 int test_copy; /* Copy value for testing. */
00423 #endif
00424 
00425 #define DB_ENV_CDB 0x00001 /* DB_INIT_CDB. */
00426 #define DB_ENV_CREATE 0x00002 /* DB_CREATE set. */
00427 #define DB_ENV_DBLOCAL 0x00004 /* DB_ENV allocated for private DB. */
00428 #define DB_ENV_LOCKDOWN 0x00008 /* DB_LOCKDOWN set. */
00429 #define DB_ENV_NOMMAP 0x00010 /* DB_NOMMAP set. */
00430 #define DB_ENV_OPEN_CALLED 0x00020 /* DBENV->open called (paths valid). */
00431 #define DB_ENV_PRIVATE 0x00040 /* DB_PRIVATE set. */
00432 #define DB_ENV_RPCCLIENT 0x00080 /* DB_CLIENT set. */
00433 #define DB_ENV_STANDALONE 0x00100 /* Test: freestanding environment. */
00434 #define DB_ENV_SYSTEM_MEM 0x00200 /* DB_SYSTEM_MEM set. */
00435 #define DB_ENV_THREAD 0x00400 /* DB_THREAD set. */
00436 #define DB_ENV_TXN_NOSYNC 0x00800 /* DB_TXN_NOSYNC set. */
00437 #define DB_ENV_USER_ALLOC 0x01000 /* User allocated the structure. */
00438 #define DB_ENV_CMPR 0x02000 /* Compression active. */
00439 u_int32_t flags; /* Flags. */
00440 };
00441 
00442 /*******************************************************
00443  * Access methods.
00444  *******************************************************/
00445 /*
00446  * !!!
00447  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
00448  */
00449 typedef enum {
00450 DB_BTREE=1,
00451 DB_HASH,
00452 DB_RECNO,
00453 DB_QUEUE,
00454 DB_UNKNOWN /* Figure it out on open. */
00455 } DBTYPE;
00456 
00457 #define DB_BTREEVERSION 8 /* Current btree version. */
00458 #define DB_BTREEOLDVER 6 /* Oldest btree version supported. */
00459 #define DB_BTREEMAGIC 0x053162
00460 
00461 #define DB_HASHVERSION 7 /* Current hash version. */
00462 #define DB_HASHOLDVER 4 /* Oldest hash version supported. */
00463 #define DB_HASHMAGIC 0x061561
00464 
00465 #define DB_QAMVERSION 2 /* Current queue version. */
00466 #define DB_QAMOLDVER 1 /* Oldest queue version supported. */
00467 #define DB_QAMMAGIC 0x042253
00468 
00469 #define DB_LOGVERSION 2 /* Current log version. */
00470 #define DB_LOGOLDVER 2 /* Oldest log version supported. */
00471 #define DB_LOGMAGIC 0x040988
00472 
00473 /*
00474  * DB access method and cursor operation values. Each value is an operation
00475  * code to which additional bit flags are added.
00476  */
00477 #define DB_AFTER 1 /* c_put() */
00478 #define DB_APPEND 2 /* put() */
00479 #define DB_BEFORE 3 /* c_put() */
00480 #define DB_CACHED_COUNTS 4 /* stat() */
00481 #define DB_CHECKPOINT 5 /* CDB_log_put(), CDB_log_get() */
00482 #define DB_CONSUME 6 /* c_get() */
00483 #define DB_CURLSN 7 /* CDB_log_put() */
00484 #define DB_CURRENT 8 /* c_get(), c_put(), CDB_log_get() */
00485 #define DB_FIRST 9 /* c_get(), CDB_log_get() */
00486 #define DB_FLUSH 10 /* CDB_log_put() */
00487 #define DB_GET_BOTH 11 /* get(), c_get() */
00488 #define DB_GET_BOTHC 12 /* c_get() (internal) */
00489 #define DB_GET_RECNO 13 /* c_get() */
00490 #define DB_JOIN_ITEM 14 /* c_get(); do not do primary lookup */
00491 #define DB_KEYFIRST 15 /* c_put() */
00492 #define DB_KEYLAST 16 /* c_put() */
00493 #define DB_LAST 17 /* c_get(), CDB_log_get() */
00494 #define DB_NEXT 18 /* c_get(), CDB_log_get() */
00495 #define DB_NEXT_DUP 19 /* c_get() */
00496 #define DB_NEXT_NODUP 20 /* c_get() */
00497 #define DB_NODUPDATA 21 /* put(), c_put() */
00498 #define DB_NOOVERWRITE 22 /* put() */
00499 #define DB_NOSYNC 23 /* close() */
00500 #define DB_POSITION 24 /* c_dup() */
00501 #define DB_POSITIONI 25 /* c_dup() (internal) */
00502 #define DB_PREV 26 /* c_get(), CDB_log_get() */
00503 #define DB_PREV_NODUP 27 /* c_get(), CDB_log_get() */
00504 #define DB_RECORDCOUNT 28 /* stat() */
00505 #define DB_SET 29 /* c_get(), CDB_log_get() */
00506 #define DB_SET_RANGE 30 /* c_get() */
00507 #define DB_SET_RECNO 31 /* get(), c_get() */
00508 #define DB_WRITECURSOR 32 /* cursor() */
00509 #define DB_WRITELOCK 33 /* cursor() (internal) */
00510 
00511 /* This has to change when the max opcode hits 255. */
00512 #define DB_OPFLAGS_MASK 0x000000ff /* Mask for operations flags. */
00513 #define DB_RMW 0x80000000 /* Acquire write flag immediately. */
00514 
00515 /*
00516  * DB (user visible) error return codes.
00517  *
00518  * !!!
00519  * Changes to any of the user visible error return codes must be reflected
00520  * in java/src/com/sleepycat/db/Db.java.
00521  *
00522  * !!!
00523  * For source compatibility with DB 2.X deadlock return (EAGAIN), use the
00524  * following:
00525  * #include <errno.h>
00526  * #define DB_LOCK_DEADLOCK EAGAIN
00527  *
00528  * !!!
00529  * We don't want our error returns to conflict with other packages where
00530  * possible, so pick a base error value that's hopefully not common.
00531  */
00532 #define DB_INCOMPLETE (-30999)/* Sync didn't finish. */
00533 #define DB_KEYEMPTY (-30998)/* Key/data deleted or never created. */
00534 #define DB_KEYEXIST (-30997)/* The key/data pair already exists. */
00535 #define DB_LOCK_DEADLOCK (-30996)/* Deadlock. */
00536 #define DB_LOCK_NOTGRANTED (-30995)/* Lock unavailable. */
00537 #define DB_NOSERVER (-30994)/* Server panic return. */
00538 #define DB_NOSERVER_HOME (-30993)/* Bad home sent to server. */
00539 #define DB_NOSERVER_ID (-30992)/* Bad ID sent to server. */
00540 #define DB_NOTFOUND (-30991)/* Key/data pair not found (EOF). */
00541 #define DB_OLD_VERSION (-30990)/* Out-of-date version. */
00542 #define DB_RUNRECOVERY (-30989)/* Panic return. */
00543 #define DB_VERIFY_BAD (-30988)/* Verify failed; bad format. */
00544 
00545 /* DB (private) error return codes. */
00546 #define DB_DELETED (-30899)/* Recovery file marked deleted. */
00547 #define DB_NEEDSPLIT (-30898)/* Page needs to be split. */
00548 #define DB_SWAPBYTES (-30897)/* Database needs byte swapping. */
00549 #define DB_TXN_CKP (-30896)/* Encountered ckp record in log. */
00550 #define DB_VERIFY_FATAL (-30895)/* Fatal: DB->verify cannot proceed. */
00551 
00552 #define DB_FILE_ID_LEN 20 /* DB file ID length. */
00553 
00554 /* DB access method description structure. */
00555 struct __db {
00556 /*******************************************************
00557  * Public: owned by the application.
00558  *******************************************************/
00559 u_int32_t pgsize; /* Database logical page size. */
00560 
00561 /* Callbacks. */
00562 void (*db_feedback) __P((DB *, int, int));
00563 void *(*db_malloc) __P((size_t));
00564 void *(*db_realloc) __P((void *, size_t));
00565 int (*dup_compare) __P((const DBT *, const DBT *));
00566 
00567 /*******************************************************
00568  * Private: owned by DB.
00569  *******************************************************/
00570 DB_ENV *dbenv; /* Backing environment. */
00571 
00572 DBTYPE type; /* DB access method type. */
00573 
00574 DB_MPOOLFILE *mpf; /* Backing buffer pool. */
00575 
00576 void *mutexp; /* Synchronization for free threading */
00577 
00578 u_int8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */
00579 
00580 #define DB_LOGFILEID_INVALID -1
00581 int32_t log_fileid; /* File's unique ID for logging. */
00582 db_pgno_t meta_pgno; /* Meta page number */
00583 DB_TXN *open_txn; /* Transaction to protect creates. */
00584 
00585 long cl_id; /* RPC: remote client id. */
00586 
00587 /*
00588  * !!!
00589  * Some applications use DB but implement their own locking outside of
00590  * DB. If they're using fcntl(2) locking on the underlying database
00591  * file, and we open and close a file descriptor for that file, we will
00592  * discard their locks. The DB_FCNTL_LOCKING flag to DB->open is an
00593  * undocumented interface to support this CDB_usage which leaves any file
00594  * descriptors we open until DB->close. This will only work with the
00595  * DB->open interface and simple caches, e.g., creating a transaction
00596  * thread may open/close file descriptors this flag doesn't protect.
00597  * Locking with fcntl(2) on a file that you don't own is a very, very
00598  * unsafe thing to do. 'Nuff said.
00599  */
00600 DB_FH *saved_open_fhp; /* Saved file handle. */
00601 
00602 /*
00603  * Linked list of DBP's, used in the log's dbentry table
00604  * to keep track of all open db handles for a given log id.
00605  * !!!
00606  * Explicit representations of structures in queue.h.
00607  *
00608  * TAILQ_ENTRY(__db) links;
00609  */
00610 struct {
00611 struct __db *tqe_next;
00612 struct __db **tqe_prev;
00613 } links;
00614 
00615 /*
00616  * Cursor queues.
00617  *
00618  * !!!
00619  * Explicit representations of structures in queue.h.
00620  *
00621  * TAILQ_HEAD(free_queue, __dbc);
00622  * TAILQ_HEAD(active_queue, __dbc);
00623  * TAILQ_HEAD(join_queue, __dbc);
00624  */
00625 struct {
00626 struct __dbc *tqh_first;
00627 struct __dbc **tqh_last;
00628 } free_queue;
00629 struct {
00630 struct __dbc *tqh_first;
00631 struct __dbc **tqh_last;
00632 } active_queue;
00633 struct {
00634 struct __dbc *tqh_first;
00635 struct __dbc **tqh_last;
00636 } join_queue;
00637 
00638 void *bt_internal; /* Btree/Recno access method private. */
00639 void *cj_internal; /* C++/Java private. */
00640 void *h_internal; /* Hash access method private. */
00641 void *q_internal; /* Queue access method private. */
00642 void *xa_internal; /* XA private. */
00643 
00644 /* Methods. */
00645 int (*close) __P((DB *, u_int32_t));
00646 int (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
00647 int (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
00648 void (*err) __P((DB *, int, const char *, ...));
00649 void (*errx) __P((DB *, const char *, ...));
00650 int (*fd) __P((DB *, int *));
00651 int (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
00652 int (*get_byteswapped) __P((DB *));
00653 DBTYPE
00654 (*get_type) __P((DB *));
00655 int (*join) __P((DB *, DBC **, DBC **, u_int32_t));
00656 int (*key_range) __P((DB *,
00657 DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t));
00658 int (*open) __P((DB *,
00659 const char *, const char *, DBTYPE, u_int32_t, int));
00660 int (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
00661 int (*remove) __P((DB *, const char *, const char *, u_int32_t));
00662 int (*rename) __P((DB *,
00663 const char *, const char *, const char *, u_int32_t));
00664 int (*set_cachesize) __P((DB *, u_int32_t, u_int32_t, int));
00665 int (*set_dup_compare) __P((DB *, int (*)(const DBT *, const DBT *)));
00666 void (*set_errcall) __P((DB *, void (*)(const char *, char *)));
00667 void (*set_errfile) __P((DB *, FILE *));
00668 void (*set_errpfx) __P((DB *, const char *));
00669 int (*set_feedback) __P((DB *, void (*)(DB *, int, int)));
00670 int (*set_flags) __P((DB *, u_int32_t));
00671 int (*set_lorder) __P((DB *, int));
00672 int (*set_malloc) __P((DB *, void *(*)(size_t)));
00673 int (*set_pagesize) __P((DB *, u_int32_t));
00674 int (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int)));
00675 int (*set_realloc) __P((DB *, void *(*)(void *, size_t)));
00676 int (*stat) __P((DB *, void *, void *(*)(size_t), u_int32_t));
00677 int (*sync) __P((DB *, u_int32_t));
00678 int (*upgrade) __P((DB *, const char *, u_int32_t));
00679 int (*verify) __P((DB *,
00680 const char *, const char *, FILE *, u_int32_t));
00681 
00682 int (*set_bt_compare) __P((DB *, int (*)(const DBT *, const DBT *)));
00683 int (*set_bt_maxkey) __P((DB *, u_int32_t));
00684 int (*set_bt_minkey) __P((DB *, u_int32_t));
00685 int (*set_bt_prefix) __P((DB *, size_t (*)(const DBT *, const DBT *)));
00686 
00687 int (*set_h_ffactor) __P((DB *, u_int32_t));
00688 int (*set_h_hash) __P((DB *, u_int32_t (*)(const void *, u_int32_t)));
00689 int (*set_h_nelem) __P((DB *, u_int32_t));
00690 
00691 int (*set_re_delim) __P((DB *, int));
00692 int (*set_re_len) __P((DB *, u_int32_t));
00693 int (*set_re_pad) __P((DB *, int));
00694 int (*set_re_source) __P((DB *, const char *));
00695 
00696 #define DB_OK_BTREE 0x01
00697 #define DB_OK_HASH 0x02
00698 #define DB_OK_QUEUE 0x04
00699 #define DB_OK_RECNO 0x08
00700 u_int32_t am_ok; /* Legal AM choices. */
00701 
00702 #define DB_AM_DISCARD 0x00001 /* Discard any cached pages. */
00703 #define DB_AM_DUP 0x00002 /* DB_DUP. */
00704 #define DB_AM_DUPSORT 0x00004 /* DB_DUPSORT. */
00705 #define DB_AM_INMEM 0x00008 /* In-memory; no sync on close. */
00706 #define DB_AM_PGDEF 0x00010 /* Page size was defaulted. */
00707 #define DB_AM_RDONLY 0x00020 /* Database is readonly. */
00708 #define DB_AM_RECOVER 0x00040 /* DBP opened by recovery routine. */
00709 #define DB_AM_SUBDB 0x00080 /* Subdatabases supported. */
00710 #define DB_AM_SWAP 0x00100 /* Pages need to be byte-swapped. */
00711 #define DB_BT_RECNUM 0x00200 /* DB_RECNUM. */
00712 #define DB_BT_REVSPLIT 0x00400 /* DB_REVSPLITOFF. */
00713 #define DB_DBM_ERROR 0x00800 /* Error in DBM/NDBM database. */
00714 #define DB_OPEN_CALLED 0x01000 /* DB->open called. */
00715 #define DB_RE_DELIMITER 0x02000 /* Variablen length delimiter set. */
00716 #define DB_RE_FIXEDLEN 0x04000 /* Fixed-length records. */
00717 #define DB_RE_PAD 0x08000 /* Fixed-length record pad. */
00718 #define DB_RE_RENUMBER 0x10000 /* DB_RENUMBER. */
00719 #define DB_RE_SNAPSHOT 0x20000 /* DB_SNAPSHOT. */
00720 #define DB_AM_CMPR 0x40000 /* Transparent I/O compression */
00721 u_int32_t flags;
00722 u_int8_t tags; /* User defined tag, 0xf0 in page */
00723 };
00724 
00725 /*
00726  * DB_LOCK_ILOCK --
00727  * Internal DB access method lock.
00728  */
00729 struct __db_ilock {
00730 db_pgno_t pgno; /* Page being locked. */
00731 u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
00732 #define DB_RECORD_LOCK 1
00733 #define DB_PAGE_LOCK 2
00734 u_int8_t type; /* Record or Page lock */
00735 };
00736 
00737 /*
00738  * DB_LOCK --
00739  * The structure is allocated by the caller and filled in during a
00740  * CDB_lock_get request (or a CDB_lock_vec/DB_LOCK_GET).
00741  */
00742 struct __db_lock_u {
00743 size_t off; /* Offset of the lock in the region */
00744 u_int32_t ndx; /* Index of the object referenced by
00745  * this lock; used for locking. */
00746 u_int32_t gen; /* Generation number of this lock. */
00747 };
00748 
00749 /* Cursor description structure. */
00750 struct __dbc {
00751 DB *dbp; /* Related DB access method. */
00752 DB_TXN *txn; /* Associated transaction. */
00753 
00754 /*
00755  * !!!
00756  * Explicit representations of structures in queue.h.
00757  *
00758  * TAILQ_ENTRY(__dbc) links; Active/free cursor queues.
00759  */
00760 struct {
00761 DBC *tqe_next;
00762 DBC **tqe_prev;
00763 } links;
00764 
00765 DBC *opd; /* Off-page duplicate cursor. */
00766 
00767 DBT rkey; /* Returned key. */
00768 DBT rdata; /* Returned data. */
00769 
00770 u_int32_t lid; /* Default process' locker id. */
00771 u_int32_t locker; /* Locker for this operation. */
00772 DBT lock_dbt; /* DBT referencing lock. */
00773 DB_LOCK_ILOCK lock; /* Object to be locked. */
00774 DB_LOCK mylock; /* Lock held on this cursor. */
00775 
00776 long cl_id; /* Remote client id. */
00777 
00778 DBTYPE dbtype; /* Cursor type. */
00779 
00780 DBC_INTERNAL *internal; /* Access method private. */
00781 
00782 int (*c_close) __P((DBC *)); /* Methods: public. */
00783 int (*c_count) __P((DBC *, db_recno_t *, u_int32_t));
00784 int (*c_del) __P((DBC *, u_int32_t));
00785 int (*c_dup) __P((DBC *, DBC **, u_int32_t));
00786 int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
00787 int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
00788 
00789 /* Methods: private. */
00790 int (*c_am_close) __P((DBC *, db_pgno_t, int *));
00791 int (*c_am_del) __P((DBC *));
00792 int (*c_am_destroy) __P((DBC *));
00793 int (*c_am_get) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
00794 int (*c_am_put) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
00795 int (*c_am_writelock) __P((DBC *));
00796 
00797 #define DBC_ACTIVE 0x001 /* Cursor is being used. */
00798 #define DBC_OPD 0x002 /* Cursor references off-page dups. */
00799 #define DBC_RECOVER 0x004 /* Cursor created by recovery routine
00800  * (do not log or lock).
00801  */
00802 #define DBC_RMW 0x008 /* Acquire write flag in read op. */
00803 #define DBC_WRITECURSOR 0x010 /* Cursor may be used to write (CDB). */
00804 #define DBC_WRITEDUP 0x020 /* idup'ed DBC_WRITECURSOR (CDB). */
00805 #define DBC_WRITER 0x040 /* Cursor immediately writing (CDB). */
00806 #define DBC_TRANSIENT 0x080 /* Cursor is transient. */
00807 u_int32_t flags;
00808 };
00809 
00810 /* Key range statistics structure */
00811 struct __key_range {
00812 double less;
00813 double equal;
00814 double greater;
00815 };
00816 
00817 /* Btree/Recno statistics structure. */
00818 struct __db_bt_stat {
00819 u_int32_t bt_magic; /* Magic number. */
00820 u_int32_t bt_version; /* Version number. */
00821 u_int32_t bt_metaflags; /* Metadata flags. */
00822 u_int32_t bt_nkeys; /* Number of unique keys. */
00823 u_int32_t bt_ndata; /* Number of data items. */
00824 u_int32_t bt_pagesize; /* Page size. */
00825 u_int32_t bt_maxkey; /* Maxkey value. */
00826 u_int32_t bt_minkey; /* Minkey value. */
00827 u_int32_t bt_re_len; /* Fixed-length record length. */
00828 u_int32_t bt_re_pad; /* Fixed-length record pad. */
00829 u_int32_t bt_levels; /* Tree levels. */
00830 u_int32_t bt_int_pg; /* Internal pages. */
00831 u_int32_t bt_leaf_pg; /* Leaf pages. */
00832 u_int32_t bt_dup_pg; /* Duplicate pages. */
00833 u_int32_t bt_over_pg; /* Overflow pages. */
00834 u_int32_t bt_free; /* Pages on the free list. */
00835 u_int32_t bt_int_pgfree; /* Bytes free in internal pages. */
00836 u_int32_t bt_leaf_pgfree; /* Bytes free in leaf pages. */
00837 u_int32_t bt_dup_pgfree; /* Bytes free in duplicate pages. */
00838 u_int32_t bt_over_pgfree; /* Bytes free in overflow pages. */
00839 };
00840 
00841 /* Queue statistics structure. */
00842 struct __db_qam_stat {
00843 u_int32_t qs_magic; /* Magic number. */
00844 u_int32_t qs_version; /* Version number. */
00845 u_int32_t qs_metaflags; /* Metadata flags. */
00846 u_int32_t qs_nkeys; /* Number of unique keys. */
00847 u_int32_t qs_ndata; /* Number of data items. */
00848 u_int32_t qs_pagesize; /* Page size. */
00849 u_int32_t qs_pages; /* Data pages. */
00850 u_int32_t qs_re_len; /* Fixed-length record length. */
00851 u_int32_t qs_re_pad; /* Fixed-length record pad. */
00852 u_int32_t qs_pgfree; /* Bytes free in data pages. */
00853 u_int32_t qs_start; /* Start offset. */
00854 u_int32_t qs_first_recno; /* First not deleted record. */
00855 u_int32_t qs_cur_recno; /* Last allocated record number. */
00856 };
00857 
00858 /* Hash statistics structure. */
00859 struct __db_h_stat {
00860 u_int32_t hash_magic; /* Magic number. */
00861 u_int32_t hash_version; /* Version number. */
00862 u_int32_t hash_metaflags; /* Metadata flags. */
00863 u_int32_t hash_nkeys; /* Number of unique keys. */
00864 u_int32_t hash_ndata; /* Number of data items. */
00865 u_int32_t hash_pagesize; /* Page size. */
00866 u_int32_t hash_nelem; /* Original nelem specified. */
00867 u_int32_t hash_ffactor; /* Fill factor specified at create. */
00868 u_int32_t hash_buckets; /* Number of hash buckets. */
00869 u_int32_t hash_free; /* Pages on the free list. */
00870 u_int32_t hash_bfree; /* Bytes free on bucket pages. */
00871 u_int32_t hash_bigpages; /* Number of big key/data pages. */
00872 u_int32_t hash_big_bfree; /* Bytes free on big item pages. */
00873 u_int32_t hash_overflows; /* Number of overflow pages. */
00874 u_int32_t hash_ovfl_free; /* Bytes free on ovfl pages. */
00875 u_int32_t hash_dup; /* Number of dup pages. */
00876 u_int32_t hash_dup_free; /* Bytes free on duplicate pages. */
00877 };
00878 
00879 int CDB_db_create __P((DB **, DB_ENV *, u_int32_t));
00880 int CDB_db_env_create __P((DB_ENV **, u_int32_t));
00881 int CDB_db_env_set_func_close __P((int (*)(int)));
00882 int CDB_db_env_set_func_dirfree __P((void (*)(char **, int)));
00883 int CDB_db_env_set_func_dirlist __P((int (*)(const char *, char ***, int *)));
00884 int CDB_db_env_set_func_exists __P((int (*)(const char *, int *)));
00885 int CDB_db_env_set_func_free __P((void (*)(void *)));
00886 int CDB_db_env_set_func_fsync __P((int (*)(int)));
00887 int CDB_db_env_set_func_ioinfo __P((int (*)(const char *,
00888 int, u_int32_t *, u_int32_t *, u_int32_t *)));
00889 int CDB_db_env_set_func_malloc __P((void *(*)(size_t)));
00890 int CDB_db_env_set_func_map __P((int (*)(char *, size_t, int, int, void **)));
00891 int CDB_db_env_set_func_open __P((int (*)(const char *, int, ...)));
00892 int CDB_db_env_set_func_read __P((ssize_t (*)(int, void *, size_t)));
00893 int CDB_db_env_set_func_realloc __P((void *(*)(void *, size_t)));
00894 int CDB_db_env_set_func_rename __P((int (*)(const char *, const char *)));
00895 int CDB_db_env_set_func_seek
00896 __P((int (*)(int, size_t, db_pgno_t, u_int32_t, int, int)));
00897 int CDB_db_env_set_func_sleep __P((int (*)(u_long, u_long)));
00898 int CDB_db_env_set_func_unlink __P((int (*)(const char *)));
00899 int CDB_db_env_set_func_unmap __P((int (*)(void *, size_t)));
00900 int CDB_db_env_set_func_write __P((ssize_t (*)(int, const void *, size_t)));
00901 int CDB_db_env_set_func_yield __P((int (*)(void)));
00902 int CDB_db_env_set_mutexlocks __P((int));
00903 int CDB_db_env_set_pageyield __P((int));
00904 int CDB_db_env_set_panicstate __P((int));
00905 int CDB_db_env_set_region_init __P((int));
00906 int CDB_db_env_set_tas_spins __P((u_int32_t));
00907 char *CDB_db_strerror __P((int));
00908 char *CDB_db_version __P((int *, int *, int *));
00909 
00910 /*******************************************************
00911  * Locking
00912  *******************************************************/
00913 #define DB_LOCKVERSION 1
00914 
00915 /* Flag values for CDB_lock_vec(), CDB_lock_get(). */
00916 #define DB_LOCK_NOWAIT 0x01 /* Don't wait on unavailable lock. */
00917 #define DB_LOCK_RECORD 0x02 /* Internal: record lock. */
00918 #define DB_LOCK_UPGRADE 0x04 /* Internal: upgrade existing lock. */
00919 
00920 /* Flag values for CDB_lock_detect(). */
00921 #define DB_LOCK_CONFLICT 0x01 /* Run on any conflict. */
00922 
00923 /*
00924  * Request types.
00925  *
00926  * !!!
00927  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
00928  */
00929 typedef enum {
00930 DB_LOCK_DUMP=0, /* Display held locks. */
00931 DB_LOCK_GET, /* Get the lock. */
00932 DB_LOCK_INHERIT, /* Pass locks to parent. */
00933 DB_LOCK_PUT, /* Release the lock. */
00934 DB_LOCK_PUT_ALL, /* Release locker's locks. */
00935 DB_LOCK_PUT_OBJ /* Release locker's locks on obj. */
00936 } db_lockop_t;
00937 
00938 /*
00939  * Simple R/W lock modes and for multi-granularity intention locking.
00940  *
00941  * !!!
00942  * These values are NOT random, as they are used as an index into the lock
00943  * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
00944  * must be == 4.
00945  *
00946  * !!!
00947  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
00948  */
00949 typedef enum {
00950 DB_LOCK_NG=0, /* Not granted. */
00951 DB_LOCK_READ, /* Shared/read. */
00952 DB_LOCK_WRITE, /* Exclusive/write. */
00953 DB_LOCK_IWRITE, /* Intent exclusive/write. */
00954 DB_LOCK_IREAD, /* Intent to share/read. */
00955 DB_LOCK_IWR /* Intent to read and write. */
00956 } db_lockmode_t;
00957 
00958 /*
00959  * Status of a lock.
00960  */
00961 typedef enum {
00962 DB_LSTAT_ABORTED, /* Lock belongs to an aborted txn. */
00963 DB_LSTAT_ERR, /* Lock is bad. */
00964 DB_LSTAT_FREE, /* Lock is unallocated. */
00965 DB_LSTAT_HELD, /* Lock is currently held. */
00966 DB_LSTAT_NOGRANT, /* Lock was not granted. */
00967 DB_LSTAT_PENDING, /* Lock was waiting and has been
00968  * promoted; waiting for the owner
00969  * to run and upgrade it to held. */
00970 DB_LSTAT_WAITING /* Lock is on the wait queue. */
00971 } db_status_t;
00972 
00973 /* Lock request structure. */
00974 struct __db_lockreq {
00975 db_lockop_t op; /* Operation. */
00976 db_lockmode_t mode; /* Requested mode. */
00977 u_int32_t locker; /* Locker identity. */
00978 DBT *obj; /* Object being locked. */
00979 DB_LOCK lock; /* Lock returned. */
00980 };
00981 
00982 /*
00983  * Commonly used conflict matrices.
00984  *
00985  * Standard Read/Write (or exclusive/shared) locks.
00986  */
00987 #define DB_LOCK_RW_N 3
00988 extern const u_int8_t CDB_db_rw_conflicts[];
00989 
00990 /* Multi-granularity locking. */
00991 #define DB_LOCK_RIW_N 6
00992 extern const u_int8_t CDB_db_riw_conflicts[];
00993 
00994 struct __db_lock_stat {
00995 u_int32_t st_lastid; /* Last allocated locker ID. */
00996 u_int32_t st_maxlocks; /* Maximum number of locks in table. */
00997 u_int32_t st_nmodes; /* Number of lock modes. */
00998 u_int32_t st_nlockers; /* Number of lockers. */
00999 u_int32_t st_maxnlockers; /* Maximum number of lockers. */
01000 u_int32_t st_nconflicts; /* Number of lock conflicts. */
01001 u_int32_t st_nrequests; /* Number of lock gets. */
01002 u_int32_t st_nreleases; /* Number of lock puts. */
01003 u_int32_t st_nnowaits; /* Number of requests that would have
01004  waited, but NOWAIT was set. */
01005 u_int32_t st_ndeadlocks; /* Number of lock deadlocks. */
01006 u_int32_t st_region_wait; /* Region lock granted after wait. */
01007 u_int32_t st_region_nowait; /* Region lock granted without wait. */
01008 u_int32_t st_regsize; /* Region size. */
01009 };
01010 
01011 int CDB_lock_detect __P((DB_ENV *, u_int32_t, u_int32_t, int *));
01012 int CDB_lock_get __P((DB_ENV *,
01013 u_int32_t, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
01014 int CDB_lock_id __P((DB_ENV *, u_int32_t *));
01015 int CDB_lock_put __P((DB_ENV *, DB_LOCK *));
01016 int CDB_lock_stat __P((DB_ENV *, DB_LOCK_STAT **, void *(*)(size_t)));
01017 int CDB_lock_vec __P((DB_ENV *,
01018 u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
01019 
01020 /*******************************************************
01021  * Logging.
01022  *******************************************************/
01023 /* Flag values for CDB_log_archive(). */
01024 #define DB_ARCH_ABS 0x001 /* Absolute pathnames. */
01025 #define DB_ARCH_DATA 0x002 /* Data files. */
01026 #define DB_ARCH_LOG 0x004 /* Log files. */
01027 
01028 /*
01029  * A DB_LSN has two parts, a fileid which identifies a specific file, and an
01030  * offset within that file. The fileid is an unsigned 4-byte quantity that
01031  * uniquely identifies a file within the log directory -- currently a simple
01032  * counter inside the log. The offset is also an unsigned 4-byte value. The
01033  * log manager guarantees the offset is never more than 4 bytes by switching
01034  * to a new log file before the maximum length imposed by an unsigned 4-byte
01035  * offset is reached.
01036  */
01037 struct __db_lsn {
01038 u_int32_t file; /* File ID. */
01039 u_int32_t offset; /* File offset. */
01040 };
01041 
01042 /* Log statistics structure. */
01043 struct __db_log_stat {
01044 u_int32_t st_magic; /* Log file magic number. */
01045 u_int32_t st_version; /* Log file version number. */
01046 int st_mode; /* Log file mode. */
01047 u_int32_t st_lg_bsize; /* Log buffer size. */
01048 u_int32_t st_lg_max; /* Maximum log file size. */
01049 u_int32_t st_w_bytes; /* Bytes to log. */
01050 u_int32_t st_w_mbytes; /* Megabytes to log. */
01051 u_int32_t st_wc_bytes; /* Bytes to log since checkpoint. */
01052 u_int32_t st_wc_mbytes; /* Megabytes to log since checkpoint. */
01053 u_int32_t st_wcount; /* Total writes to the log. */
01054 u_int32_t st_wcount_fill; /* Overflow writes to the log. */
01055 u_int32_t st_scount; /* Total syncs to the log. */
01056 u_int32_t st_region_wait; /* Region lock granted after wait. */
01057 u_int32_t st_region_nowait; /* Region lock granted without wait. */
01058 u_int32_t st_cur_file; /* Current log file number. */
01059 u_int32_t st_cur_offset; /* Current log file offset. */
01060 u_int32_t st_regsize; /* Region size. */
01061 };
01062 
01063 int CDB_log_archive __P((DB_ENV *, char **[], u_int32_t, void *(*)(size_t)));
01064 int CDB_log_compare __P((const DB_LSN *, const DB_LSN *));
01065 int CDB_log_file __P((DB_ENV *, const DB_LSN *, char *, size_t));
01066 int CDB_log_flush __P((DB_ENV *, const DB_LSN *));
01067 int CDB_log_get __P((DB_ENV *, DB_LSN *, DBT *, u_int32_t));
01068 int CDB_log_put __P((DB_ENV *, DB_LSN *, const DBT *, u_int32_t));
01069 int CDB_log_register __P((DB_ENV *, DB *, const char *));
01070 int CDB_log_stat __P((DB_ENV *, DB_LOG_STAT **, void *(*)(size_t)));
01071 int CDB_log_unregister __P((DB_ENV *, DB *));
01072 
01073 /*******************************************************
01074  * Mpool
01075  *******************************************************/
01076 /* Flag values for CDB_memp_fget(). */
01077 #define DB_MPOOL_CREATE 0x001 /* Create a page. */
01078 #define DB_MPOOL_LAST 0x002 /* Return the last page. */
01079 #define DB_MPOOL_NEW 0x004 /* Create a new page. */
01080 #define DB_MPOOL_NEW_GROUP 0x008 /* Create a group of pages. */
01081 
01082 /* Flag values for CDB_memp_fput(), CDB_memp_fset(). */
01083 #define DB_MPOOL_CLEAN 0x001 /* Page is not modified. */
01084 #define DB_MPOOL_DIRTY 0x002 /* Page is modified. */
01085 #define DB_MPOOL_DISCARD 0x004 /* Don't cache the page. */
01086 
01087 /* Mpool statistics structure. */
01088 struct __db_mpool_stat {
01089 u_int32_t st_cache_hit; /* Pages found in the cache. */
01090 u_int32_t st_cache_miss; /* Pages not found in the cache. */
01091 u_int32_t st_map; /* Pages from mapped files. */
01092 u_int32_t st_page_create; /* Pages created in the cache. */
01093 u_int32_t st_page_in; /* Pages read in. */
01094 u_int32_t st_page_out; /* Pages written out. */
01095 u_int32_t st_ro_evict; /* Clean pages forced from the cache. */
01096 u_int32_t st_rw_evict; /* Dirty pages forced from the cache. */
01097 u_int32_t st_hash_buckets; /* Number of hash buckets. */
01098 u_int32_t st_hash_searches; /* Total hash chain searches. */
01099 u_int32_t st_hash_longest; /* Longest hash chain searched. */
01100 u_int32_t st_hash_examined; /* Total hash entries searched. */
01101 u_int32_t st_page_clean; /* Clean pages. */
01102 u_int32_t st_page_dirty; /* Dirty pages. */
01103 u_int32_t st_page_trickle; /* Pages written by CDB_memp_trickle. */
01104 u_int32_t st_region_wait; /* Region lock granted after wait. */
01105 u_int32_t st_region_nowait; /* Region lock granted without wait. */
01106 u_int32_t st_gbytes; /* Total cache size: GB. */
01107 u_int32_t st_bytes; /* Total cache size: B. */
01108 u_int32_t st_ncache; /* Number of caches. */
01109 u_int32_t st_regsize; /* Cache size. */
01110 };
01111 
01112 /* Mpool file open information structure. */
01113 struct __db_mpool_finfo {
01114 int ftype; /* File type. */
01115 DBT *pgcookie; /* Byte-string passed to pgin/pgout. */
01116 u_int8_t *fileid; /* Unique file ID. */
01117 int32_t lsn_offset; /* LSN offset in page. */
01118 u_int32_t clear_len; /* Cleared length on created pages. */
01119 };
01120 
01121 /* Mpool file statistics structure. */
01122 struct __db_mpool_fstat {
01123 char *file_name; /* File name. */
01124 size_t st_pagesize; /* Page size. */
01125 u_int32_t st_cache_hit; /* Pages found in the cache. */
01126 u_int32_t st_cache_miss; /* Pages not found in the cache. */
01127 u_int32_t st_map; /* Pages from mapped files. */
01128 u_int32_t st_page_create; /* Pages created in the cache. */
01129 u_int32_t st_page_in; /* Pages read in. */
01130 u_int32_t st_page_out; /* Pages written out. */
01131 };
01132 
01133 int CDB_memp_fclose __P((DB_MPOOLFILE *));
01134 int CDB_memp_fget __P((DB_MPOOLFILE *, db_pgno_t *, u_int32_t, void *));
01135 int CDB_memp_fopen __P((DB_ENV *, const char *,
01136 u_int32_t, int, size_t, DB_MPOOL_FINFO *, DB_MPOOLFILE **));
01137 int CDB_memp_fput __P((DB_MPOOLFILE *, void *, u_int32_t));
01138 int CDB_memp_fset __P((DB_MPOOLFILE *, void *, u_int32_t));
01139 int CDB_memp_fsync __P((DB_MPOOLFILE *));
01140 int CDB_memp_register __P((DB_ENV *, int,
01141 int (*)(DB_ENV *, db_pgno_t, void *, DBT *),
01142 int (*)(DB_ENV *, db_pgno_t, void *, DBT *)));
01143 int CDB_memp_stat __P((DB_ENV *,
01144 DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, void *(*)(size_t)));
01145 int CDB_memp_sync __P((DB_ENV *, DB_LSN *));
01146 int CDB_memp_trickle __P((DB_ENV *, int, int *));
01147 
01148 /*******************************************************
01149  * Transactions.
01150  *******************************************************/
01151 #define DB_TXNVERSION 1
01152 
01153 /* Operations values to the tx_recover() function. */
01154 #define DB_TXN_BACKWARD_ROLL 1 /* Read the log backwards. */
01155 #define DB_TXN_FORWARD_ROLL 2 /* Read the log forwards. */
01156 #define DB_TXN_OPENFILES 3 /* Read for open files. */
01157 #define DB_TXN_REDO 4 /* Redo the operation. */
01158 #define DB_TXN_UNDO 5 /* Undo the operation. */
01159 
01160 /* Internal transaction status values. */
01161 
01162 /* Transaction statistics structure. */
01163 struct __db_txn_active {
01164 u_int32_t txnid; /* Transaction ID */
01165 u_int32_t parentid; /* Transaction ID of parent */
01166 DB_LSN lsn; /* Lsn of the begin record */
01167 };
01168 
01169 struct __db_txn_stat {
01170 DB_LSN st_last_ckp; /* lsn of the last checkpoint */
01171 DB_LSN st_pending_ckp; /* last checkpoint did not finish */
01172 time_t st_time_ckp; /* time of last checkpoint */
01173 u_int32_t st_last_txnid; /* last transaction id given out */
01174 u_int32_t st_maxtxns; /* maximum txns possible */
01175 u_int32_t st_naborts; /* number of aborted transactions */
01176 u_int32_t st_nbegins; /* number of begun transactions */
01177 u_int32_t st_ncommits; /* number of committed transactions */
01178 u_int32_t st_nactive; /* number of active transactions */
01179 u_int32_t st_maxnactive; /* maximum active transactions */
01180 DB_TXN_ACTIVE
01181 *st_txnarray; /* array of active transactions */
01182 u_int32_t st_region_wait; /* Region lock granted after wait. */
01183 u_int32_t st_region_nowait; /* Region lock granted without wait. */
01184 u_int32_t st_regsize; /* Region size. */
01185 };
01186 
01187 int CDB_txn_abort __P((DB_TXN *));
01188 int CDB_txn_begin __P((DB_ENV *, DB_TXN *, DB_TXN **, u_int32_t));
01189 int CDB_txn_checkpoint __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
01190 int CDB_txn_commit __P((DB_TXN *, u_int32_t));
01191 u_int32_t CDB_txn_id __P((DB_TXN *));
01192 int CDB_txn_prepare __P((DB_TXN *));
01193 int CDB_txn_stat __P((DB_ENV *, DB_TXN_STAT **, void *(*)(size_t)));
01194 
01195 #ifndef DB_DBM_HSEARCH
01196 #define DB_DBM_HSEARCH 0 /* No historic interfaces by default. */
01197 #endif
01198 #if DB_DBM_HSEARCH != 0
01199 /*******************************************************
01200  * Dbm/Ndbm historic interfaces.
01201  *******************************************************/
01202 #define DBM_INSERT 0 /* Flags to dbm_store(). */
01203 #define DBM_REPLACE 1
01204 
01205 /*
01206  * The DB support for ndbm(3) always appends this suffix to the
01207  * file name to avoid overwriting the user's original database.
01208  */
01209 #define DBM_SUFFIX ".db"
01210 
01211 #if defined(_XPG4_2)
01212 typedef struct {
01213 char *dptr;
01214 size_t dsize;
01215 } datum;
01216 #else
01217 typedef struct {
01218 char *dptr;
01219 int dsize;
01220 } datum;
01221 #endif
01222 
01223 /*
01224  * Translate DBM calls into DB calls so that DB doesn't step on the
01225  * application's name space.
01226  *
01227  * The global variables dbrdonly, dirf and pagf were not retained when 4BSD
01228  * replaced the dbm interface with ndbm, and are not supported here.
01229  */
01230 #define dbminit(a) __db_dbm_init(a)
01231 #define dbmclose __db_dbm_close
01232 #if !defined(__cplusplus)
01233 #define delete(a) __db_dbm_delete(a)
01234 #endif
01235 #define fetch(a) __db_dbm_fetch(a)
01236 #define firstkey __db_dbm_firstkey
01237 #define nextkey(a) __db_dbm_nextkey(a)
01238 #define store(a, b) __db_dbm_store(a, b)
01239 
01240 /* Prototype the DB calls. */
01241 int __db_dbm_close __P((void));
01242 int __db_dbm_dbrdonly __P((void));
01243 int __db_dbm_delete __P((datum));
01244 int __db_dbm_dirf __P((void));
01245 datum __db_dbm_fetch __P((datum));
01246 datum __db_dbm_firstkey __P((void));
01247 int __db_dbm_init __P((char *));
01248 datum __db_dbm_nextkey __P((datum));
01249 int __db_dbm_pagf __P((void));
01250 int __db_dbm_store __P((datum, datum));
01251 
01252 /*
01253  * Translate NDBM calls into DB calls so that DB doesn't step on the
01254  * application's name space.
01255  */
01256 #define dbm_clearerr(a) __db_ndbm_clearerr(a)
01257 #define dbm_close(a) __db_ndbm_close(a)
01258 #define dbm_delete(a, b) __db_ndbm_delete(a, b)
01259 #define dbm_dirfno(a) __db_ndbm_dirfno(a)
01260 #define dbm_error(a) __db_ndbm_error(a)
01261 #define dbm_fetch(a, b) __db_ndbm_fetch(a, b)
01262 #define dbm_firstkey(a) __db_ndbm_firstkey(a)
01263 #define dbm_nextkey(a) __db_ndbm_nextkey(a)
01264 #define dbm_open(a, b, c) __db_ndbm_open(a, b, c)
01265 #define dbm_pagfno(a) __db_ndbm_pagfno(a)
01266 #define dbm_rdonly(a) __db_ndbm_rdonly(a)
01267 #define dbm_store(a, b, c, d) __db_ndbm_store(a, b, c, d)
01268 
01269 /* Prototype the DB calls. */
01270 int __db_ndbm_clearerr __P((DBM *));
01271 void __db_ndbm_close __P((DBM *));
01272 int __db_ndbm_delete __P((DBM *, datum));
01273 int __db_ndbm_dirfno __P((DBM *));
01274 int __db_ndbm_error __P((DBM *));
01275 datum __db_ndbm_fetch __P((DBM *, datum));
01276 datum __db_ndbm_firstkey __P((DBM *));
01277 datum __db_ndbm_nextkey __P((DBM *));
01278 DBM *__db_ndbm_open __P((const char *, int, int));
01279 int __db_ndbm_pagfno __P((DBM *));
01280 int __db_ndbm_rdonly __P((DBM *));
01281 int __db_ndbm_store __P((DBM *, datum, datum, int));
01282 
01283 /*******************************************************
01284  * Hsearch historic interface.
01285  *******************************************************/
01286 typedef enum {
01287 FIND, ENTER
01288 } ACTION;
01289 
01290 typedef struct entry {
01291 char *key;
01292 char *data;
01293 } ENTRY;
01294 
01295 /*
01296  * Translate HSEARCH calls into DB calls so that DB doesn't step on the
01297  * application's name space.
01298  */
01299 #define hcreate(a) __db_hcreate(a)
01300 #define hdestroy __db_hdestroy
01301 #define hsearch(a, b) __db_hsearch(a, b)
01302 
01303 /* Prototype the DB calls. */
01304 int __db_hcreate __P((size_t));
01305 void __db_hdestroy __P((void));
01306 ENTRY *__db_hsearch __P((ENTRY, ACTION));
01307 #endif /* DB_DBM_HSEARCH */
01308 
01309 /*
01310  * XXX
01311  * MacOS: Reset Metrowerks C enum sizes.
01312  */
01313 #ifdef __MWERKS__
01314 #pragma enumsalwaysint reset
01315 #endif
01316 
01317 #if defined(__cplusplus)
01318 }
01319 #endif
01320 
01321 #endif /* !_DB_H_ */

Generated on Sun Jun 8 10:56:36 2008 for GNUmifluz by doxygen 1.5.5

AltStyle によって変換されたページ (->オリジナル) /