db.src
Upload User: tsgydb
Upload Date: 2007-04-14
Package Size: 10674k
Code Size: 50k
Category:

MySQL

Development Platform:

Visual C++

  1. /*-
  2.  * See the file LICENSE for redistribution information.
  3.  *
  4.  * Copyright (c) 1996, 1997, 1998, 1999, 2000
  5.  * Sleepycat Software.  All rights reserved.
  6.  *
  7.  * $Id: db.src,v 11.121 2001/01/10 15:43:08 sue Exp $
  8.  */
  9. #ifndef _DB_H_
  10. #define _DB_H_
  11. #ifndef __NO_SYSTEM_INCLUDES
  12. #include <sys/types.h>
  13. #include <stdio.h>
  14. #endif
  15. #if defined(__cplusplus)
  16. extern "C" {
  17. #endif
  18. /*
  19.  * XXX
  20.  * Handle function prototypes and the keyword "const".  This steps on name
  21.  * space that DB doesn't control, but all of the other solutions are worse.
  22.  *
  23.  * XXX
  24.  * While Microsoft's compiler is ANSI C compliant, it doesn't have _STDC_
  25.  * defined by default, you specify a command line flag or #pragma to turn
  26.  * it on.  Don't do that, however, because some of Microsoft's own header
  27.  * files won't compile.
  28.  */
  29. #undef __P
  30. #if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER)
  31. #define __P(protos) protos /* ANSI C prototypes */
  32. #else
  33. #define const
  34. #define __P(protos) () /* K&R C preprocessor */
  35. #endif
  36. /*
  37.  * !!!
  38.  * DB needs basic information about specifically sized types.  If they're
  39.  * not provided by the system, typedef them here.
  40.  *
  41.  * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
  42.  * as does BIND and Kerberos, since we don't know for sure what #include
  43.  * files the user is using.
  44.  *
  45.  * !!!
  46.  * We also provide the standard u_int, u_long etc., if they're not provided
  47.  * by the system.
  48.  */
  49. #ifndef __BIT_TYPES_DEFINED__
  50. #define __BIT_TYPES_DEFINED__
  51. @u_int8_decl@
  52. @int16_decl@
  53. @u_int16_decl@
  54. @int32_decl@
  55. @u_int32_decl@
  56. #endif
  57. @u_char_decl@
  58. @u_short_decl@
  59. @u_int_decl@
  60. @u_long_decl@
  61. @ssize_t_decl@
  62. #define DB_VERSION_MAJOR @DB_VERSION_MAJOR@
  63. #define DB_VERSION_MINOR @DB_VERSION_MINOR@
  64. #define DB_VERSION_PATCH @DB_VERSION_PATCH@
  65. #define DB_VERSION_STRING @DB_VERSION_STRING@
  66. typedef u_int32_t db_pgno_t; /* Page number type. */
  67. typedef u_int16_t db_indx_t; /* Page offset type. */
  68. #define DB_MAX_PAGES 0xffffffff /* >= # of pages in a file */
  69. typedef u_int32_t db_recno_t; /* Record number type. */
  70. #define DB_MAX_RECORDS 0xffffffff /* >= # of records in a tree */
  71. /* Forward structure declarations, so applications get type checking. */
  72. struct __db; typedef struct __db DB;
  73. #ifdef DB_DBM_HSEARCH
  74. typedef struct __db DBM;
  75. #endif
  76. struct __db_bt_stat; typedef struct __db_bt_stat DB_BTREE_STAT;
  77. struct __db_dbt; typedef struct __db_dbt DBT;
  78. struct __db_env; typedef struct __db_env DB_ENV;
  79. struct __db_h_stat; typedef struct __db_h_stat DB_HASH_STAT;
  80. struct __db_ilock; typedef struct __db_ilock DB_LOCK_ILOCK;
  81. struct __db_lock_stat; typedef struct __db_lock_stat DB_LOCK_STAT;
  82. struct __db_lock_u; typedef struct __db_lock_u DB_LOCK;
  83. struct __db_lockreq; typedef struct __db_lockreq DB_LOCKREQ;
  84. struct __db_log_stat; typedef struct __db_log_stat DB_LOG_STAT;
  85. struct __db_lsn; typedef struct __db_lsn DB_LSN;
  86. struct __db_mpool_finfo;typedef struct __db_mpool_finfo DB_MPOOL_FINFO;
  87. struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
  88. struct __db_mpool_stat; typedef struct __db_mpool_stat DB_MPOOL_STAT;
  89. struct __db_mpoolfile; typedef struct __db_mpoolfile DB_MPOOLFILE;
  90. struct __db_qam_stat; typedef struct __db_qam_stat DB_QUEUE_STAT;
  91. struct __db_txn; typedef struct __db_txn DB_TXN;
  92. struct __db_txn_active; typedef struct __db_txn_active DB_TXN_ACTIVE;
  93. struct __db_txn_stat; typedef struct __db_txn_stat DB_TXN_STAT;
  94. struct __dbc; typedef struct __dbc DBC;
  95. struct __dbc_internal; typedef struct __dbc_internal DBC_INTERNAL;
  96. struct __fh_t; typedef struct __fh_t DB_FH;
  97. struct __key_range; typedef struct __key_range DB_KEY_RANGE;
  98. /* Key/data structure -- a Data-Base Thang. */
  99. struct __db_dbt {
  100. /*
  101.  * data/size must be fields 1 and 2 for DB 1.85 compatibility.
  102.  */
  103. void  *data; /* Key/data */
  104. u_int32_t size; /* key/data length */
  105. u_int32_t ulen; /* RO: length of user buffer. */
  106. u_int32_t dlen; /* RO: get/put record length. */
  107. u_int32_t doff; /* RO: get/put record offset. */
  108. #define DB_DBT_ISSET 0x001 /* Lower level calls set value. */
  109. #define DB_DBT_MALLOC 0x002 /* Return in malloc'd memory. */
  110. #define DB_DBT_PARTIAL 0x004 /* Partial put/get. */
  111. #define DB_DBT_REALLOC 0x008 /* Return in realloc'd memory. */
  112. #define DB_DBT_USERMEM 0x010 /* Return in user's memory. */
  113. #define DB_DBT_DUPOK 0x020 /* Insert if duplicate. */
  114. u_int32_t flags;
  115. };
  116. /*
  117.  * Common flags --
  118.  * Interfaces which use any of these common flags should never have
  119.  * interface specific flags in this range.
  120.  */
  121. #define DB_CREATE       0x000001 /* Create file as necessary. */
  122. #define DB_CXX_NO_EXCEPTIONS  0x000002 /* C++: return error values. */
  123. #define DB_FORCE       0x000004 /* Force (anything). */
  124. #define DB_NOMMAP       0x000008 /* Don't mmap underlying file. */
  125. #define DB_RDONLY       0x000010 /* Read-only (O_RDONLY). */
  126. #define DB_RECOVER       0x000020 /* Run normal recovery. */
  127. #define DB_THREAD       0x000040 /* Applications are threaded. */
  128. #define DB_TXN_NOSYNC       0x000080 /* Do not sync log on commit. */
  129. #define DB_USE_ENVIRON       0x000100 /* Use the environment. */
  130. #define DB_USE_ENVIRON_ROOT   0x000200 /* Use the environment if root. */
  131. /*
  132.  * Flags private to db_env_create.
  133.  */
  134. #define DB_CLIENT       0x000400 /* Open for a client environment. */
  135. /*
  136.  * Flags private to db_create.
  137.  */
  138. #define DB_XA_CREATE       0x000400 /* Open in an XA environment. */
  139. /*
  140.  * Flags private to DBENV->open.
  141.  */
  142. #define DB_INIT_CDB       0x000400 /* Concurrent Access Methods. */
  143. #define DB_INIT_LOCK       0x000800 /* Initialize locking. */
  144. #define DB_INIT_LOG       0x001000 /* Initialize logging. */
  145. #define DB_INIT_MPOOL       0x002000 /* Initialize mpool. */
  146. #define DB_INIT_TXN       0x004000 /* Initialize transactions. */
  147. #define DB_JOINENV       0x008000  /* Initialize all subsystems present. */
  148. #define DB_LOCKDOWN       0x010000 /* Lock memory into physical core. */
  149. #define DB_PRIVATE       0x020000 /* DB_ENV is process local. */
  150. #define DB_RECOVER_FATAL      0x040000 /* Run catastrophic recovery. */
  151. #define DB_SYSTEM_MEM       0x080000 /* Use system-backed memory. */
  152. /*
  153.  * Flags private to DB->open.
  154.  */
  155. #define DB_EXCL       0x000400 /* Exclusive open (O_EXCL). */
  156. #define DB_FCNTL_LOCKING      0x000800 /* UNDOC: fcntl(2) locking. */
  157. #define DB_ODDFILESIZE       0x001000  /* UNDOC: truncate to N * pgsize. */
  158. #define DB_RDWRMASTER       0x002000  /* UNDOC: allow subdb master open R/W */
  159. #define DB_TRUNCATE       0x004000 /* Discard existing DB (O_TRUNC). */
  160. #define DB_EXTENT       0x008000  /* UNDOC: dealing with an extent. */
  161. /*
  162.  * Flags private to DBENV->txn_begin.
  163.  */
  164. #define DB_TXN_NOWAIT       0x000400 /* Do not wait for locks in this TXN. */
  165. #define DB_TXN_SYNC       0x000800 /* Always sync log on commit. */
  166. /*
  167.  * Flags private to DBENV->set_flags.
  168.  */
  169. #define DB_CDB_ALLDB       0x000400 /* In CDB, lock across environment. */
  170. /*
  171.  * Flags private to DB->set_feedback's callback.
  172.  */
  173. #define DB_UPGRADE       0x000400 /* Upgrading. */
  174. #define DB_VERIFY       0x000800  /* Verifying. */
  175. /*
  176.  * Flags private to DB->set_flags.
  177.  *
  178.  * DB->set_flags does not share common flags and so values start at 0x01.
  179.  */
  180. #define DB_DUP 0x0001 /* Btree, Hash: duplicate keys. */
  181. #define DB_DUPSORT 0x0002 /* Btree, Hash: duplicate keys. */
  182. #define DB_RECNUM 0x0004 /* Btree: record numbers. */
  183. #define DB_RENUMBER 0x0008 /* Recno: renumber on insert/delete. */
  184. #define DB_REVSPLITOFF 0x0010 /* Btree: turn off reverse splits. */
  185. #define DB_SNAPSHOT 0x0020 /* Recno: snapshot the input. */
  186. /*
  187.  * Flags private to DB->join.
  188.  *
  189.  * DB->join does not share common flags and so values start at 0x01.
  190.  */
  191. #define DB_JOIN_NOSORT 0x0001  /* Don't try to optimize join. */
  192. /*
  193.  * Flags private to DB->verify.
  194.  *
  195.  * DB->verify does not share common flags and so values start at 0x01.
  196.  */
  197. #define DB_AGGRESSIVE       0x0001  /* Salvage anything which might be data.*/
  198. #define DB_NOORDERCHK       0x0002  /* Skip order check; subdb w/ user func */
  199. #define DB_ORDERCHKONLY       0x0004  /* Only perform an order check on subdb */
  200. #define DB_PR_PAGE       0x0008  /* Show page contents (-da). */
  201. #define DB_PR_HEADERS       0x0010  /* Show only page headers (-dh). */
  202. #define DB_PR_RECOVERYTEST    0x0020  /* Recovery test (-dr). */
  203. #define DB_SALVAGE       0x0040  /* Salvage what looks like data. */
  204. /*
  205.  * !!!
  206.  * These must not go over 0x8000, or they will collide with the flags
  207.  * used by __bam_vrfy_subtree.
  208.  */
  209. #define DB_VRFY_FLAGMASK      0xffff  /* For masking above flags. */
  210. /*
  211.  * Deadlock detector modes; used in the DBENV structure to configure the
  212.  * locking subsystem.
  213.  */
  214. #define DB_LOCK_NORUN 0
  215. #define DB_LOCK_DEFAULT 1 /* Default policy. */
  216. #define DB_LOCK_OLDEST 2 /* Abort oldest transaction. */
  217. #define DB_LOCK_RANDOM 3 /* Abort random transaction. */
  218. #define DB_LOCK_YOUNGEST 4 /* Abort youngest transaction. */
  219. /*******************************************************
  220.  * Environment.
  221.  *******************************************************/
  222. #define DB_REGION_MAGIC 0x120897 /* Environment magic number. */
  223. typedef enum {
  224. DB_NOTICE_LOGFILE_CHANGED
  225. /* DB_NOTICE_DISK_LOW */
  226. } db_notices;
  227. typedef enum {
  228. DB_TXN_ABORT,
  229. DB_TXN_BACKWARD_ROLL,
  230. DB_TXN_FORWARD_ROLL,
  231. DB_TXN_OPENFILES
  232. } db_recops;
  233. #define DB_UNDO(op) ((op) == DB_TXN_ABORT || (op) == DB_TXN_BACKWARD_ROLL)
  234. #define DB_REDO(op) ((op) == DB_TXN_FORWARD_ROLL)
  235. struct __db_env {
  236. /*******************************************************
  237.  * Public: owned by the application.
  238.  *******************************************************/
  239. FILE *db_errfile; /* Error message file stream. */
  240. const char *db_errpfx; /* Error message prefix. */
  241. /* Callbacks. */
  242. void (*db_errcall) __P((const char *, char *));
  243. void (*db_feedback) __P((DB_ENV *, int, int));
  244. void (*db_noticecall) __P((DB_ENV *, db_notices));
  245. void (*db_paniccall) __P((DB_ENV *, int));
  246. int  (*db_recovery_init) __P((DB_ENV *));
  247. /*
  248.  * Currently, the verbose list is a bit field with room for 32
  249.  * entries.  There's no reason that it needs to be limited, if
  250.  * there are ever more than 32 entries, convert to a bit array.
  251.  */
  252. #define DB_VERB_CHKPOINT 0x0001 /* List checkpoints. */
  253. #define DB_VERB_DEADLOCK 0x0002 /* Deadlock detection information. */
  254. #define DB_VERB_RECOVERY 0x0004 /* Recovery information. */
  255. #define DB_VERB_WAITSFOR 0x0008 /* Dump waits-for table. */
  256. u_int32_t  verbose; /* Verbose output. */
  257. void *app_private; /* Application-private handle. */
  258. /* Locking. */
  259. u_int8_t *lk_conflicts; /* Two dimensional conflict matrix. */
  260. u_int32_t  lk_modes; /* Number of lock modes in table. */
  261. u_int32_t  lk_max; /* Maximum number of locks. */
  262. u_int32_t  lk_max_lockers;/* Maximum number of lockers. */
  263. u_int32_t  lk_max_objects;/* Maximum number of locked objects. */
  264. u_int32_t  lk_detect; /* Deadlock detect on all conflicts. */
  265. /* Logging. */
  266. u_int32_t  lg_bsize; /* Buffer size. */
  267. u_int32_t  lg_max; /* Maximum file size. */
  268. /* Memory pool. */
  269. u_int32_t  mp_gbytes; /* Cachesize: GB. */
  270. u_int32_t  mp_bytes; /* Cachesize: Bytes. */
  271. size_t  mp_size; /* DEPRECATED: Cachesize: bytes. */
  272. int  mp_ncache; /* Number of cache regions. */
  273. size_t  mp_mmapsize; /* Maximum file size for mmap. */
  274. /* Transactions. */
  275. u_int32_t  tx_max; /* Maximum number of transactions. */
  276. time_t  tx_timestamp; /* Recover to specific timestamp. */
  277. int (*tx_recover) /* Dispatch function for recovery. */
  278.     __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
  279. /*******************************************************
  280.  * Private: owned by DB.
  281.  *******************************************************/
  282. int  db_panic; /* Panic causing errno. */
  283. /* User files, paths. */
  284. char *db_home; /* Database home. */
  285. char *db_log_dir; /* Database log file directory. */
  286. char *db_tmp_dir; /* Database tmp file directory. */
  287. char        **db_data_dir; /* Database data file directories. */
  288. int  data_cnt; /* Database data file slots. */
  289. int  data_next; /* Next Database data file slot. */
  290. int  db_mode; /* Default open permissions. */
  291. void *reginfo; /* REGINFO structure reference. */
  292. DB_FH *lockfhp; /* fcntl(2) locking file handle. */
  293. long  shm_key; /* shmget(2) key. */
  294. void *lg_handle; /* Log handle. */
  295. void *lk_handle; /* Lock handle. */
  296. void *mp_handle; /* Mpool handle. */
  297. void *tx_handle; /* Txn handle. */
  298. int       (**dtab) /* Dispatch table */
  299.     __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
  300. size_t  dtab_size; /* Slots in the dispatch table. */
  301. void *cl_handle; /* RPC: remote client handle. */
  302. long  cl_id; /* RPC: Remote client env id. */
  303. int  dblocal_ref; /* DB_ENV_DBLOCAL: reference count. */
  304. u_int32_t  db_mutexlocks; /* db_set_mutexlocks */
  305. /*
  306.  * List of open DB handles for this DB_ENV, used for cursor
  307.  * adjustment.  Must be protected for multi-threaded support.
  308.  *
  309.  * !!!
  310.  * As this structure is allocated in per-process memory, the
  311.  * mutex may need to be stored elsewhere on architectures unable
  312.  * to support mutexes in heap memory, e.g. HP/UX 9.
  313.  */
  314. void *dblist_mutexp; /* Mutex. */
  315. /*
  316.  * !!!
  317.  * Explicit representation of structure in queue.h.
  318.  * LIST_HEAD(dblist, __db);
  319.  */
  320. struct {
  321. struct __db *lh_first;
  322. } dblist;
  323. /*
  324.  * XA support.
  325.  *
  326.  * !!!
  327.  * Explicit representations of structures in queue.h.
  328.  *
  329.  * TAILQ_ENTRY(__db_env);
  330.  */
  331. struct {
  332. struct __db_env *tqe_next;
  333. struct __db_env **tqe_prev;
  334. } links;
  335. int  xa_rmid; /* XA Resource Manager ID. */
  336. DB_TXN *xa_txn; /* XA Current transaction. */
  337. void *cj_internal; /* C++/Java private. */
  338. /* Methods. */
  339. int  (*close) __P((DB_ENV *, u_int32_t));
  340. void (*err) __P((const DB_ENV *, int, const char *, ...));
  341. void (*errx) __P((const DB_ENV *, const char *, ...));
  342. int  (*open) __P((DB_ENV *, const char *, u_int32_t, int));
  343. int  (*remove) __P((DB_ENV *, const char *, u_int32_t));
  344. int  (*set_data_dir) __P((DB_ENV *, const char *));
  345. void (*set_errcall) __P((DB_ENV *, void (*)(const char *, char *)));
  346. void (*set_errfile) __P((DB_ENV *, FILE *));
  347. void (*set_errpfx) __P((DB_ENV *, const char *));
  348. int  (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
  349. int  (*set_flags) __P((DB_ENV *, u_int32_t, int));
  350. int  (*set_mutexlocks) __P((DB_ENV *, int));
  351. void (*set_noticecall) __P((DB_ENV *, void (*)(DB_ENV *, db_notices)));
  352. int  (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int)));
  353. int  (*set_recovery_init) __P((DB_ENV *, int (*)(DB_ENV *)));
  354. int  (*set_server) __P((DB_ENV *, char *, long, long, u_int32_t));
  355. int  (*set_shm_key) __P((DB_ENV *, long));
  356. int  (*set_tmp_dir) __P((DB_ENV *, const char *));
  357. int  (*set_verbose) __P((DB_ENV *, u_int32_t, int));
  358. int  (*set_lg_bsize) __P((DB_ENV *, u_int32_t));
  359. int  (*set_lg_dir) __P((DB_ENV *, const char *));
  360. int  (*set_lg_max) __P((DB_ENV *, u_int32_t));
  361. int  (*set_lk_conflicts) __P((DB_ENV *, u_int8_t *, int));
  362. int  (*set_lk_detect) __P((DB_ENV *, u_int32_t));
  363. int  (*set_lk_max) __P((DB_ENV *, u_int32_t));
  364. int  (*set_lk_max_locks) __P((DB_ENV *, u_int32_t));
  365. int  (*set_lk_max_lockers) __P((DB_ENV *, u_int32_t));
  366. int  (*set_lk_max_objects) __P((DB_ENV *, u_int32_t));
  367. int  (*set_mp_mmapsize) __P((DB_ENV *, size_t));
  368. int  (*set_cachesize) __P((DB_ENV *, u_int32_t, u_int32_t, int));
  369. int  (*set_tx_max) __P((DB_ENV *, u_int32_t));
  370. int  (*set_tx_recover) __P((DB_ENV *,
  371. int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops)));
  372. int  (*set_tx_timestamp) __P((DB_ENV *, time_t *));
  373. #ifdef CONFIG_TEST
  374. #define DB_TEST_PREOPEN  1 /* before __os_open */
  375. #define DB_TEST_POSTOPEN  2 /* after __os_open */
  376. #define DB_TEST_POSTLOGMETA  3 /* after logging meta in btree */
  377. #define DB_TEST_POSTLOG  4 /* after logging all pages */
  378. #define DB_TEST_POSTSYNC  5 /* after syncing the log */
  379. #define DB_TEST_PRERENAME  6 /* before __os_rename */
  380. #define DB_TEST_POSTRENAME  7 /* after __os_rename */
  381. int  test_abort; /* Abort value for testing. */
  382. int  test_copy; /* Copy value for testing. */
  383. #endif
  384. #define DB_ENV_CDB 0x00001 /* DB_INIT_CDB. */
  385. #define DB_ENV_CDB_ALLDB 0x00002 /* CDB environment wide locking. */
  386. #define DB_ENV_CREATE 0x00004 /* DB_CREATE set. */
  387. #define DB_ENV_DBLOCAL 0x00008 /* DB_ENV allocated for private DB. */
  388. #define DB_ENV_LOCKDOWN 0x00010 /* DB_LOCKDOWN set. */
  389. #define DB_ENV_NOMMAP 0x00020 /* DB_NOMMAP set. */
  390. #define DB_ENV_OPEN_CALLED 0x00040 /* DBENV->open called (paths valid). */
  391. #define DB_ENV_PRIVATE 0x00080 /* DB_PRIVATE set. */
  392. #define DB_ENV_RPCCLIENT 0x00100 /* DB_CLIENT set. */
  393. #define DB_ENV_STANDALONE 0x00200 /* Test: freestanding environment. */
  394. #define DB_ENV_SYSTEM_MEM 0x00400 /* DB_SYSTEM_MEM set. */
  395. #define DB_ENV_THREAD 0x00800 /* DB_THREAD set. */
  396. #define DB_ENV_TXN_NOSYNC 0x01000 /* DB_TXN_NOSYNC set. */
  397. #define DB_ENV_USER_ALLOC 0x02000 /* User allocated the structure. */
  398. u_int32_t  flags; /* Flags. */
  399. };
  400. /*******************************************************
  401.  * Access methods.
  402.  *******************************************************/
  403. /*
  404.  * !!!
  405.  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
  406.  */
  407. typedef enum {
  408. DB_BTREE=1,
  409. DB_HASH,
  410. DB_RECNO,
  411. DB_QUEUE,
  412. DB_UNKNOWN /* Figure it out on open. */
  413. } DBTYPE;
  414. #define DB_BTREEVERSION 8 /* Current btree version. */
  415. #define DB_BTREEOLDVER 6 /* Oldest btree version supported. */
  416. #define DB_BTREEMAGIC 0x053162
  417. #define DB_HASHVERSION 7 /* Current hash version. */
  418. #define DB_HASHOLDVER 4 /* Oldest hash version supported. */
  419. #define DB_HASHMAGIC 0x061561
  420. #define DB_QAMVERSION 3 /* Current queue version. */
  421. #define DB_QAMOLDVER 1 /* Oldest queue version supported. */
  422. #define DB_QAMMAGIC 0x042253
  423. #define DB_LOGVERSION 3 /* Current log version. */
  424. #define DB_LOGOLDVER 3 /* Oldest log version supported. */
  425. #define DB_LOGMAGIC 0x040988
  426. /*
  427.  * DB access method and cursor operation values.  Each value is an operation
  428.  * code to which additional bit flags are added.
  429.  */
  430. #define DB_AFTER  1 /* c_put() */
  431. #define DB_APPEND  2 /* put() */
  432. #define DB_BEFORE  3 /* c_put() */
  433. #define DB_CACHED_COUNTS 4 /* stat() */
  434. #define DB_CHECKPOINT  5 /* log_put(), log_get() */
  435. #define DB_CONSUME  6 /* get() */
  436. #define DB_CONSUME_WAIT  7 /* get() */
  437. #define DB_CURLSN  8 /* log_put() */
  438. #define DB_CURRENT  9 /* c_get(), c_put(), log_get() */
  439. #define DB_FIRST 10 /* c_get(), log_get() */
  440. #define DB_FLUSH 11 /* log_put() */
  441. #define DB_GET_BOTH 12 /* get(), c_get() */
  442. #define DB_GET_BOTHC 13 /* c_get() (internal) */
  443. #define DB_GET_RECNO 14 /* c_get() */
  444. #define DB_JOIN_ITEM 15 /* c_get(); do not do primary lookup */
  445. #define DB_KEYFIRST 16 /* c_put() */
  446. #define DB_KEYLAST 17 /* c_put() */
  447. #define DB_LAST 18 /* c_get(), log_get() */
  448. #define DB_NEXT 19 /* c_get(), log_get() */
  449. #define DB_NEXT_DUP 20 /* c_get() */
  450. #define DB_NEXT_NODUP 21 /* c_get() */
  451. #define DB_NODUPDATA 22 /* put(), c_put() */
  452. #define DB_NOOVERWRITE 23 /* put() */
  453. #define DB_NOSYNC 24 /* close() */
  454. #define DB_POSITION 25 /* c_dup() */
  455. #define DB_POSITIONI 26 /* c_dup() (internal) */
  456. #define DB_PREV 27 /* c_get(), log_get() */
  457. #define DB_PREV_NODUP 28 /* c_get(), log_get() */
  458. #define DB_RECORDCOUNT 29 /* stat() */
  459. #define DB_SET 30 /* c_get(), log_get() */
  460. #define DB_SET_RANGE 31 /* c_get() */
  461. #define DB_SET_RECNO 32 /* get(), c_get() */
  462. #define DB_WRITECURSOR 33 /* cursor() */
  463. #define DB_WRITELOCK 34 /* cursor() (internal) */
  464. /* This has to change when the max opcode hits 255. */
  465. #define DB_OPFLAGS_MASK 0x000000ff /* Mask for operations flags. */
  466. #define DB_RMW 0x80000000 /* Acquire write flag immediately. */
  467. /*
  468.  * DB (user visible) error return codes.
  469.  *
  470.  * !!!
  471.  * Changes to any of the user visible error return codes must be reflected
  472.  * in java/src/com/sleepycat/db/Db.java.
  473.  *
  474.  * !!!
  475.  * For source compatibility with DB 2.X deadlock return (EAGAIN), use the
  476.  * following:
  477.  * #include <errno.h>
  478.  * #define DB_LOCK_DEADLOCK EAGAIN
  479.  *
  480.  * !!!
  481.  * We don't want our error returns to conflict with other packages where
  482.  * possible, so pick a base error value that's hopefully not common.  We
  483.  * document that we own the error name space from -30,800 to -30,999.
  484.  */
  485. /* Public error return codes. */
  486. #define DB_INCOMPLETE (-30999)/* Sync didn't finish. */
  487. #define DB_KEYEMPTY (-30998)/* Key/data deleted or never created. */
  488. #define DB_KEYEXIST (-30997)/* The key/data pair already exists. */
  489. #define DB_LOCK_DEADLOCK (-30996)/* Deadlock. */
  490. #define DB_LOCK_NOTGRANTED (-30995)/* Lock unavailable. */
  491. #define DB_NOSERVER (-30994)/* Server panic return. */
  492. #define DB_NOSERVER_HOME (-30993)/* Bad home sent to server. */
  493. #define DB_NOSERVER_ID (-30992)/* Bad ID sent to server. */
  494. #define DB_NOTFOUND (-30991)/* Key/data pair not found (EOF). */
  495. #define DB_OLD_VERSION (-30990)/* Out-of-date version. */
  496. #define DB_RUNRECOVERY (-30989)/* Panic return. */
  497. #define DB_VERIFY_BAD (-30988)/* Verify failed; bad format. */
  498. /* DB (private) error return codes. */
  499. #define DB_ALREADY_ABORTED (-30899)
  500. #define DB_DELETED (-30898)/* Recovery file marked deleted. */
  501. #define DB_JAVA_CALLBACK (-30897)/* Exception during a java callback. */
  502. #define DB_NEEDSPLIT (-30896)/* Page needs to be split. */
  503. #define DB_SWAPBYTES (-30895)/* Database needs byte swapping. */
  504. #define DB_TXN_CKP (-30894)/* Encountered ckp record in log. */
  505. #define DB_VERIFY_FATAL (-30893)/* Fatal: DB->verify cannot proceed. */
  506. #define DB_FILE_ID_LEN 20 /* DB file ID length. */
  507. /* DB access method description structure. */
  508. struct __db {
  509. /*******************************************************
  510.  * Public: owned by the application.
  511.  *******************************************************/
  512. u_int32_t pgsize; /* Database logical page size. */
  513. /* Callbacks. */
  514. int (*db_append_recno) __P((DB *, DBT *, db_recno_t));
  515. void (*db_feedback) __P((DB *, int, int));
  516. void *(*db_malloc) __P((size_t));
  517. void *(*db_realloc) __P((void *, size_t));
  518. int (*dup_compare) __P((DB *, const DBT *, const DBT *));
  519. void *app_private; /* Application-private handle. */
  520. /*******************************************************
  521.  * Private: owned by DB.
  522.  *******************************************************/
  523. DB_ENV  *dbenv; /* Backing environment. */
  524. DBTYPE  type; /* DB access method type. */
  525. DB_MPOOLFILE *mpf; /* Backing buffer pool. */
  526. void *mutexp; /* Synchronization for free threading */
  527. u_int8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */
  528. u_int32_t adj_fileid; /* File's unique ID for curs. adj. */
  529. #define DB_LOGFILEID_INVALID -1
  530. int32_t  log_fileid; /* File's unique ID for logging. */
  531. db_pgno_t meta_pgno; /* Meta page number */
  532. DB_TXN *open_txn; /* Transaction to protect creates. */
  533. long  cl_id; /* RPC: remote client id. */
  534. /*
  535.  * !!!
  536.  * Some applications use DB but implement their own locking outside of
  537.  * DB.  If they're using fcntl(2) locking on the underlying database
  538.  * file, and we open and close a file descriptor for that file, we will
  539.  * discard their locks.  The DB_FCNTL_LOCKING flag to DB->open is an
  540.  * undocumented interface to support this usage which leaves any file
  541.  * descriptors we open until DB->close.  This will only work with the
  542.  * DB->open interface and simple caches, e.g., creating a transaction
  543.  * thread may open/close file descriptors this flag doesn't protect.
  544.  * Locking with fcntl(2) on a file that you don't own is a very, very
  545.  * unsafe thing to do.  'Nuff said.
  546.  */
  547. DB_FH *saved_open_fhp; /* Saved file handle. */
  548. /*
  549.  * Linked list of DBP's, used in the log's dbentry table
  550.  * to keep track of all open db handles for a given log id.
  551.  * !!!
  552.  * Explicit representations of structures in queue.h.
  553.  *
  554.  * TAILQ_ENTRY(__db) links;
  555.  */
  556. struct {
  557. struct __db *tqe_next;
  558. struct __db **tqe_prev;
  559. } links;
  560. /*
  561.  * Linked list of DBP's, linked from the DB_ENV, used to
  562.  * keep track of all open db handles for cursor adjustment.
  563.  *
  564.  * XXX
  565.  * Eventually, this should be merged with "links" above.
  566.  *
  567.  * !!!
  568.  * Explicit representations of structures in queue.h.
  569.  *
  570.  * LIST_ENTRY(__db) dblistlinks;
  571.  */
  572. struct {
  573. struct __db *le_next;
  574. struct __db **le_prev;
  575. } dblistlinks;
  576. /*
  577.  * Cursor queues.
  578.  *
  579.  * !!!
  580.  * Explicit representations of structures in queue.h.
  581.  *
  582.  * TAILQ_HEAD(free_queue, __dbc);
  583.  * TAILQ_HEAD(active_queue, __dbc);
  584.  * TAILQ_HEAD(join_queue, __dbc);
  585.  */
  586. struct {
  587. struct __dbc *tqh_first;
  588. struct __dbc **tqh_last;
  589. } free_queue;
  590. struct {
  591. struct __dbc *tqh_first;
  592. struct __dbc **tqh_last;
  593. } active_queue;
  594. struct {
  595. struct __dbc *tqh_first;
  596. struct __dbc **tqh_last;
  597. } join_queue;
  598. void *bt_internal; /* Btree/Recno access method private. */
  599. void *cj_internal; /* C++/Java private. */
  600. void *h_internal; /* Hash access method private. */
  601. void *q_internal; /* Queue access method private. */
  602. void *xa_internal; /* XA private. */
  603. /* Methods. */
  604. int  (*close) __P((DB *, u_int32_t));
  605. int  (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
  606. int  (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
  607. void (*err) __P((DB *, int, const char *, ...));
  608. void (*errx) __P((DB *, const char *, ...));
  609. int  (*fd) __P((DB *, int *));
  610. int  (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
  611. int  (*get_byteswapped) __P((DB *));
  612. DBTYPE
  613.      (*get_type) __P((DB *));
  614. int  (*join) __P((DB *, DBC **, DBC **, u_int32_t));
  615. int  (*key_range) __P((DB *,
  616. DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t));
  617. int  (*open) __P((DB *,
  618. const char *, const char *, DBTYPE, u_int32_t, int));
  619. int  (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
  620. int  (*remove) __P((DB *, const char *, const char *, u_int32_t));
  621. int  (*rename) __P((DB *,
  622.     const char *, const char *, const char *, u_int32_t));
  623. int  (*set_append_recno) __P((DB *, int (*)(DB *, DBT *, db_recno_t)));
  624. int  (*set_cachesize) __P((DB *, u_int32_t, u_int32_t, int));
  625. int  (*set_dup_compare) __P((DB *,
  626.     int (*)(DB *, const DBT *, const DBT *)));
  627. void (*set_errcall) __P((DB *, void (*)(const char *, char *)));
  628. void (*set_errfile) __P((DB *, FILE *));
  629. void (*set_errpfx) __P((DB *, const char *));
  630. int  (*set_feedback) __P((DB *, void (*)(DB *, int, int)));
  631. int  (*set_flags) __P((DB *, u_int32_t));
  632. int  (*set_lorder) __P((DB *, int));
  633. int  (*set_malloc) __P((DB *, void *(*)(size_t)));
  634. int  (*set_pagesize) __P((DB *, u_int32_t));
  635. int  (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int)));
  636. int  (*set_realloc) __P((DB *, void *(*)(void *, size_t)));
  637. int  (*stat) __P((DB *, void *, void *(*)(size_t), u_int32_t));
  638. int  (*sync) __P((DB *, u_int32_t));
  639. int  (*upgrade) __P((DB *, const char *, u_int32_t));
  640. int  (*verify) __P((DB *,
  641.     const char *, const char *, FILE *, u_int32_t));
  642. int  (*set_bt_compare) __P((DB *,
  643.     int (*)(DB *, const DBT *, const DBT *)));
  644. int  (*set_bt_maxkey) __P((DB *, u_int32_t));
  645. int  (*set_bt_minkey) __P((DB *, u_int32_t));
  646. int  (*set_bt_prefix) __P((DB *,
  647.     size_t (*)(DB *, const DBT *, const DBT *)));
  648. int  (*set_h_ffactor) __P((DB *, u_int32_t));
  649. int  (*set_h_hash) __P((DB *,
  650.     u_int32_t (*)(DB *, const void *, u_int32_t)));
  651. int  (*set_h_nelem) __P((DB *, u_int32_t));
  652. int  (*set_re_delim) __P((DB *, int));
  653. int  (*set_re_len) __P((DB *, u_int32_t));
  654. int  (*set_re_pad) __P((DB *, int));
  655. int  (*set_re_source) __P((DB *, const char *));
  656. int  (*set_q_extentsize) __P((DB *, u_int32_t));
  657. int  (*db_am_remove) __P((DB *, const char *,
  658.     const char *, DB_LSN *, int (**)(DB *, void*), void **));
  659. int  (*db_am_rename) __P((DB *,
  660.     const char *, const char *, const char *));
  661. #define DB_OK_BTREE 0x01
  662. #define DB_OK_HASH 0x02
  663. #define DB_OK_QUEUE 0x04
  664. #define DB_OK_RECNO 0x08
  665. u_int32_t am_ok; /* Legal AM choices. */
  666. #define DB_AM_DISCARD 0x00001 /* Discard any cached pages. */
  667. #define DB_AM_DUP 0x00002 /* DB_DUP. */
  668. #define DB_AM_DUPSORT 0x00004 /* DB_DUPSORT. */
  669. #define DB_AM_INMEM 0x00008 /* In-memory; no sync on close. */
  670. #define DB_AM_PGDEF 0x00010 /* Page size was defaulted. */
  671. #define DB_AM_RDONLY 0x00020 /* Database is readonly. */
  672. #define DB_AM_RECOVER 0x00040 /* DBP opened by recovery routine. */
  673. #define DB_AM_SUBDB 0x00080 /* Subdatabases supported. */
  674. #define DB_AM_SWAP 0x00100 /* Pages need to be byte-swapped. */
  675. #define DB_AM_TXN 0x00200 /* DBP was in a transaction. */
  676. #define DB_AM_VERIFYING 0x00400 /* DB handle is in the verifier. */
  677. #define DB_BT_RECNUM 0x00800 /* DB_RECNUM. */
  678. #define DB_BT_REVSPLIT 0x01000 /* DB_REVSPLITOFF. */
  679. #define DB_DBM_ERROR 0x02000 /* Error in DBM/NDBM database. */
  680. #define DB_OPEN_CALLED 0x04000 /* DB->open called. */
  681. #define DB_RE_DELIMITER 0x08000 /* Variablen length delimiter set. */
  682. #define DB_RE_FIXEDLEN 0x10000 /* Fixed-length records. */
  683. #define DB_RE_PAD 0x20000 /* Fixed-length record pad. */
  684. #define DB_RE_RENUMBER 0x40000 /* DB_RENUMBER. */
  685. #define DB_RE_SNAPSHOT 0x80000 /* DB_SNAPSHOT. */
  686. u_int32_t flags;
  687. };
  688. /*
  689.  * DB_LOCK_ILOCK --
  690.  * Internal DB access method lock.
  691.  */
  692. struct __db_ilock {
  693. db_pgno_t pgno; /* Page being locked. */
  694. u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
  695. #define DB_RECORD_LOCK 1
  696. #define DB_PAGE_LOCK 2
  697. u_int8_t type; /* Record or Page lock */
  698. };
  699. /*
  700.  * DB_LOCK --
  701.  * The structure is allocated by the caller and filled in during a
  702.  * lock_get request (or a lock_vec/DB_LOCK_GET).
  703.  */
  704. struct __db_lock_u {
  705. size_t off; /* Offset of the lock in the region */
  706. u_int32_t ndx; /* Index of the object referenced by
  707.  * this lock; used for locking. */
  708. u_int32_t gen; /* Generation number of this lock. */
  709. };
  710. /* Cursor description structure. */
  711. struct __dbc {
  712. DB *dbp; /* Related DB access method. */
  713. DB_TXN  *txn; /* Associated transaction. */
  714. /*
  715.  * !!!
  716.  * Explicit representations of structures in queue.h.
  717.  *
  718.  * TAILQ_ENTRY(__dbc) links; Active/free cursor queues.
  719.  */
  720. struct {
  721. DBC *tqe_next;
  722. DBC **tqe_prev;
  723. } links;
  724. DBT   rkey; /* Returned key. */
  725. DBT   rdata; /* Returned data. */
  726. u_int32_t lid; /* Default process' locker id. */
  727. u_int32_t locker; /* Locker for this operation. */
  728. DBT   lock_dbt; /* DBT referencing lock. */
  729. DB_LOCK_ILOCK lock; /* Object to be locked. */
  730. DB_LOCK   mylock; /* Lock held on this cursor. */
  731. long   cl_id; /* Remote client id. */
  732. DBTYPE   dbtype; /* Cursor type. */
  733. DBC_INTERNAL *internal; /* Access method private. */
  734. int (*c_close) __P((DBC *)); /* Methods: public. */
  735. int (*c_count) __P((DBC *, db_recno_t *, u_int32_t));
  736. int (*c_del) __P((DBC *, u_int32_t));
  737. int (*c_dup) __P((DBC *, DBC **, u_int32_t));
  738. int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
  739. int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
  740. /* Methods: private. */
  741. int (*c_am_close) __P((DBC *, db_pgno_t, int *));
  742. int (*c_am_del) __P((DBC *));
  743. int (*c_am_destroy) __P((DBC *));
  744. int (*c_am_get) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
  745. int (*c_am_put) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
  746. int (*c_am_writelock) __P((DBC *));
  747. #define DBC_ACTIVE 0x001 /* Cursor is being used. */
  748. #define DBC_OPD 0x002 /* Cursor references off-page dups. */
  749. #define DBC_RECOVER 0x004 /* Cursor created by  recovery routine
  750.  * (do not log or lock).
  751.  */
  752. #define DBC_RMW 0x008 /* Acquire write flag in read op. */
  753. #define DBC_WRITECURSOR 0x010 /* Cursor may be used to write (CDB). */
  754. #define DBC_WRITEDUP 0x020 /* idup'ed DBC_WRITECURSOR (CDB). */
  755. #define DBC_WRITER 0x040 /* Cursor immediately writing (CDB). */
  756. #define DBC_TRANSIENT 0x080 /* Cursor is transient. */
  757. #define DBC_COMPENSATE 0x100 /* Cursor is doing compensation
  758.  * do not lock.
  759.  */
  760. u_int32_t flags;
  761. };
  762. /* Key range statistics structure */
  763. struct __key_range {
  764. double less;
  765. double equal;
  766. double greater;
  767. };
  768. /* Btree/Recno statistics structure. */
  769. struct __db_bt_stat {
  770. u_int32_t bt_magic; /* Magic number. */
  771. u_int32_t bt_version; /* Version number. */
  772. u_int32_t bt_metaflags; /* Metadata flags. */
  773. u_int32_t bt_nkeys; /* Number of unique keys. */
  774. u_int32_t bt_ndata; /* Number of data items. */
  775. u_int32_t bt_pagesize; /* Page size. */
  776. u_int32_t bt_maxkey; /* Maxkey value. */
  777. u_int32_t bt_minkey; /* Minkey value. */
  778. u_int32_t bt_re_len; /* Fixed-length record length. */
  779. u_int32_t bt_re_pad; /* Fixed-length record pad. */
  780. u_int32_t bt_levels; /* Tree levels. */
  781. u_int32_t bt_int_pg; /* Internal pages. */
  782. u_int32_t bt_leaf_pg; /* Leaf pages. */
  783. u_int32_t bt_dup_pg; /* Duplicate pages. */
  784. u_int32_t bt_over_pg; /* Overflow pages. */
  785. u_int32_t bt_free; /* Pages on the free list. */
  786. u_int32_t bt_int_pgfree; /* Bytes free in internal pages. */
  787. u_int32_t bt_leaf_pgfree; /* Bytes free in leaf pages. */
  788. u_int32_t bt_dup_pgfree; /* Bytes free in duplicate pages. */
  789. u_int32_t bt_over_pgfree; /* Bytes free in overflow pages. */
  790. };
  791. /* Queue statistics structure. */
  792. struct __db_qam_stat {
  793. u_int32_t qs_magic; /* Magic number. */
  794. u_int32_t qs_version; /* Version number. */
  795. u_int32_t qs_metaflags; /* Metadata flags. */
  796. u_int32_t qs_nkeys; /* Number of unique keys. */
  797. u_int32_t qs_ndata; /* Number of data items. */
  798. u_int32_t qs_pagesize; /* Page size. */
  799. u_int32_t qs_pages; /* Data pages. */
  800. u_int32_t qs_re_len; /* Fixed-length record length. */
  801. u_int32_t qs_re_pad; /* Fixed-length record pad. */
  802. u_int32_t qs_pgfree; /* Bytes free in data pages. */
  803. u_int32_t qs_first_recno; /* First not deleted record. */
  804. u_int32_t qs_cur_recno; /* Last allocated record number. */
  805. };
  806. /* Hash statistics structure. */
  807. struct __db_h_stat {
  808. u_int32_t hash_magic; /* Magic number. */
  809. u_int32_t hash_version; /* Version number. */
  810. u_int32_t hash_metaflags; /* Metadata flags. */
  811. u_int32_t hash_nkeys; /* Number of unique keys. */
  812. u_int32_t hash_ndata; /* Number of data items. */
  813. u_int32_t hash_pagesize; /* Page size. */
  814. u_int32_t hash_nelem; /* Original nelem specified. */
  815. u_int32_t hash_ffactor; /* Fill factor specified at create. */
  816. u_int32_t hash_buckets; /* Number of hash buckets. */
  817. u_int32_t hash_free; /* Pages on the free list. */
  818. u_int32_t hash_bfree; /* Bytes free on bucket pages. */
  819. u_int32_t hash_bigpages; /* Number of big key/data pages. */
  820. u_int32_t hash_big_bfree; /* Bytes free on big item pages. */
  821. u_int32_t hash_overflows; /* Number of overflow pages. */
  822. u_int32_t hash_ovfl_free; /* Bytes free on ovfl pages. */
  823. u_int32_t hash_dup; /* Number of dup pages. */
  824. u_int32_t hash_dup_free; /* Bytes free on duplicate pages. */
  825. };
  826. int   db_create __P((DB **, DB_ENV *, u_int32_t));
  827. int   db_env_create __P((DB_ENV **, u_int32_t));
  828. int   db_env_set_func_close __P((int (*)(int)));
  829. int   db_env_set_func_dirfree __P((void (*)(char **, int)));
  830. int   db_env_set_func_dirlist __P((int (*)(const char *, char ***, int *)));
  831. int   db_env_set_func_exists __P((int (*)(const char *, int *)));
  832. int   db_env_set_func_free __P((void (*)(void *)));
  833. int   db_env_set_func_fsync __P((int (*)(int)));
  834. int   db_env_set_func_ioinfo __P((int (*)(const char *,
  835.   int, u_int32_t *, u_int32_t *, u_int32_t *)));
  836. int   db_env_set_func_malloc __P((void *(*)(size_t)));
  837. int   db_env_set_func_map __P((int (*)(char *, size_t, int, int, void **)));
  838. int   db_env_set_func_open __P((int (*)(const char *, int, ...)));
  839. int   db_env_set_func_read __P((ssize_t (*)(int, void *, size_t)));
  840. int   db_env_set_func_realloc __P((void *(*)(void *, size_t)));
  841. int   db_env_set_func_rename __P((int (*)(const char *, const char *)));
  842. int   db_env_set_func_seek
  843.   __P((int (*)(int, size_t, db_pgno_t, u_int32_t, int, int)));
  844. int   db_env_set_func_sleep __P((int (*)(u_long, u_long)));
  845. int   db_env_set_func_unlink __P((int (*)(const char *)));
  846. int   db_env_set_func_unmap __P((int (*)(void *, size_t)));
  847. int   db_env_set_func_write __P((ssize_t (*)(int, const void *, size_t)));
  848. int   db_env_set_func_yield __P((int (*)(void)));
  849. int   db_env_set_pageyield __P((int));
  850. int   db_env_set_panicstate __P((int));
  851. int   db_env_set_region_init __P((int));
  852. int   db_env_set_tas_spins __P((u_int32_t));
  853. char *db_strerror __P((int));
  854. char *db_version __P((int *, int *, int *));
  855. /*******************************************************
  856.  * Locking
  857.  *******************************************************/
  858. #define DB_LOCKVERSION 1
  859. /* Flag values for lock_vec(), lock_get(). */
  860. #define DB_LOCK_NOWAIT 0x01 /* Don't wait on unavailable lock. */
  861. #define DB_LOCK_RECORD 0x02 /* Internal: record lock. */
  862. #define DB_LOCK_UPGRADE 0x04 /* Internal: upgrade existing lock. */
  863. #define DB_LOCK_SWITCH 0x08 /* Internal: switch existing lock. */
  864. /* Flag values for lock_detect(). */
  865. #define DB_LOCK_CONFLICT 0x01 /* Run on any conflict. */
  866. /*
  867.  * Request types.
  868.  *
  869.  * !!!
  870.  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
  871.  */
  872. typedef enum {
  873. DB_LOCK_DUMP=0, /* Display held locks. */
  874. DB_LOCK_GET, /* Get the lock. */
  875. DB_LOCK_INHERIT, /* Pass locks to parent. */
  876. DB_LOCK_PUT, /* Release the lock. */
  877. DB_LOCK_PUT_ALL, /* Release locker's locks. */
  878. DB_LOCK_PUT_OBJ /* Release locker's locks on obj. */
  879. } db_lockop_t;
  880. /*
  881.  * Simple R/W lock modes and for multi-granularity intention locking.
  882.  *
  883.  * !!!
  884.  * These values are NOT random, as they are used as an index into the lock
  885.  * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
  886.  * must be == 4.
  887.  *
  888.  * !!!
  889.  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
  890.  */
  891. typedef enum {
  892. DB_LOCK_NG=0, /* Not granted. */
  893. DB_LOCK_READ, /* Shared/read. */
  894. DB_LOCK_WRITE, /* Exclusive/write. */
  895. DB_LOCK_WAIT, /* Wait for event */
  896. DB_LOCK_IWRITE, /* Intent exclusive/write. */
  897. DB_LOCK_IREAD, /* Intent to share/read. */
  898. DB_LOCK_IWR /* Intent to read and write. */
  899. } db_lockmode_t;
  900. /*
  901.  * Status of a lock.
  902.  */
  903. typedef enum {
  904. DB_LSTAT_ABORTED, /* Lock belongs to an aborted txn. */
  905. DB_LSTAT_ERR, /* Lock is bad. */
  906. DB_LSTAT_FREE, /* Lock is unallocated. */
  907. DB_LSTAT_HELD, /* Lock is currently held. */
  908. DB_LSTAT_NOGRANT, /* Lock was not granted. */
  909. DB_LSTAT_PENDING, /* Lock was waiting and has been
  910.  * promoted; waiting for the owner
  911.  * to run and upgrade it to held. */
  912. DB_LSTAT_WAITING /* Lock is on the wait queue. */
  913. } db_status_t;
  914. /* Lock request structure. */
  915. struct __db_lockreq {
  916. db_lockop_t  op; /* Operation. */
  917. db_lockmode_t  mode; /* Requested mode. */
  918. u_int32_t  locker; /* Locker identity. */
  919. DBT *obj; /* Object being locked. */
  920. DB_LOCK  lock; /* Lock returned. */
  921. };
  922. /*
  923.  * Commonly used conflict matrices.
  924.  *
  925.  */
  926. /* Multi-granularity locking. */
  927. #define DB_LOCK_RIW_N 7
  928. extern const u_int8_t db_riw_conflicts[];
  929. struct __db_lock_stat {
  930. u_int32_t st_lastid; /* Last allocated locker ID. */
  931. u_int32_t st_maxlocks; /* Maximum number of locks in table. */
  932. u_int32_t st_maxlockers; /* Maximum number of lockers in table. */
  933. u_int32_t st_maxobjects; /* Maximum number of objects in table. */
  934. u_int32_t st_nmodes; /* Number of lock modes. */
  935. u_int32_t st_nlocks; /* Current number of locks. */
  936. u_int32_t st_maxnlocks; /* Maximum number of locks so far. */
  937. u_int32_t st_nlockers; /* Current number of lockers. */
  938. u_int32_t st_maxnlockers; /* Maximum number of lockers so far. */
  939. u_int32_t st_nobjects; /* Current number of objects. */
  940. u_int32_t st_maxnobjects; /* Maximum number of objects so far. */
  941. u_int32_t st_nconflicts; /* Number of lock conflicts. */
  942. u_int32_t st_nrequests; /* Number of lock gets. */
  943. u_int32_t st_nreleases; /* Number of lock puts. */
  944. u_int32_t st_nnowaits; /* Number of requests that would have
  945.    waited, but NOWAIT was set. */
  946. u_int32_t st_ndeadlocks; /* Number of lock deadlocks. */
  947. u_int32_t st_region_wait; /* Region lock granted after wait. */
  948. u_int32_t st_region_nowait; /* Region lock granted without wait. */
  949. u_int32_t st_regsize; /* Region size. */
  950. };
  951. int   lock_detect __P((DB_ENV *, u_int32_t, u_int32_t, int *));
  952. int   lock_get __P((DB_ENV *,
  953.     u_int32_t, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
  954. int   lock_id __P((DB_ENV *, u_int32_t *));
  955. int   lock_put __P((DB_ENV *, DB_LOCK *));
  956. int   lock_stat __P((DB_ENV *, DB_LOCK_STAT **, void *(*)(size_t)));
  957. int   lock_vec __P((DB_ENV *,
  958.     u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
  959. /*******************************************************
  960.  * Logging.
  961.  *******************************************************/
  962. /* Flag values for log_archive(). */
  963. #define DB_ARCH_ABS 0x001 /* Absolute pathnames. */
  964. #define DB_ARCH_DATA 0x002 /* Data files. */
  965. #define DB_ARCH_LOG 0x004 /* Log files. */
  966. /*
  967.  * A DB_LSN has two parts, a fileid which identifies a specific file, and an
  968.  * offset within that file.  The fileid is an unsigned 4-byte quantity that
  969.  * uniquely identifies a file within the log directory -- currently a simple
  970.  * counter inside the log.  The offset is also an unsigned 4-byte value.  The
  971.  * log manager guarantees the offset is never more than 4 bytes by switching
  972.  * to a new log file before the maximum length imposed by an unsigned 4-byte
  973.  * offset is reached.
  974.  */
  975. struct __db_lsn {
  976. u_int32_t file; /* File ID. */
  977. u_int32_t offset; /* File offset. */
  978. };
  979. /* Log statistics structure. */
  980. struct __db_log_stat {
  981. u_int32_t st_magic; /* Log file magic number. */
  982. u_int32_t st_version; /* Log file version number. */
  983. int st_mode; /* Log file mode. */
  984. u_int32_t st_lg_bsize; /* Log buffer size. */
  985. u_int32_t st_lg_max; /* Maximum log file size. */
  986. u_int32_t st_w_bytes; /* Bytes to log. */
  987. u_int32_t st_w_mbytes; /* Megabytes to log. */
  988. u_int32_t st_wc_bytes; /* Bytes to log since checkpoint. */
  989. u_int32_t st_wc_mbytes; /* Megabytes to log since checkpoint. */
  990. u_int32_t st_wcount; /* Total writes to the log. */
  991. u_int32_t st_wcount_fill; /* Overflow writes to the log. */
  992. u_int32_t st_scount; /* Total syncs to the log. */
  993. u_int32_t st_region_wait; /* Region lock granted after wait. */
  994. u_int32_t st_region_nowait; /* Region lock granted without wait. */
  995. u_int32_t st_cur_file; /* Current log file number. */
  996. u_int32_t st_cur_offset; /* Current log file offset. */
  997. u_int32_t st_regsize; /* Region size. */
  998. };
  999. int  log_archive __P((DB_ENV *, char **[], u_int32_t, void *(*)(size_t)));
  1000. int  log_compare __P((const DB_LSN *, const DB_LSN *));
  1001. int  log_file __P((DB_ENV *, const DB_LSN *, char *, size_t));
  1002. int  log_flush __P((DB_ENV *, const DB_LSN *));
  1003. int  log_get __P((DB_ENV *, DB_LSN *, DBT *, u_int32_t));
  1004. int  log_put __P((DB_ENV *, DB_LSN *, const DBT *, u_int32_t));
  1005. int  log_register __P((DB_ENV *, DB *, const char *));
  1006. int  log_stat __P((DB_ENV *, DB_LOG_STAT **, void *(*)(size_t)));
  1007. int  log_unregister __P((DB_ENV *, DB *));
  1008. /*******************************************************
  1009.  * Mpool
  1010.  *******************************************************/
  1011. /* Flag values for memp_fget(). */
  1012. #define DB_MPOOL_CREATE 0x001 /* Create a page. */
  1013. #define DB_MPOOL_LAST 0x002 /* Return the last page. */
  1014. #define DB_MPOOL_NEW 0x004 /* Create a new page. */
  1015. #define DB_MPOOL_NEW_GROUP 0x008 /* Create a group of pages. */
  1016. #define DB_MPOOL_EXTENT 0x010 /* Get for an extent. */
  1017. /* Flag values for memp_fput(), memp_fset(). */
  1018. #define DB_MPOOL_CLEAN 0x001 /* Page is not modified. */
  1019. #define DB_MPOOL_DIRTY 0x002 /* Page is modified. */
  1020. #define DB_MPOOL_DISCARD 0x004 /* Don't cache the page. */
  1021. /* Mpool statistics structure. */
  1022. struct __db_mpool_stat {
  1023. u_int32_t st_cache_hit; /* Pages found in the cache. */
  1024. u_int32_t st_cache_miss; /* Pages not found in the cache. */
  1025. u_int32_t st_map; /* Pages from mapped files. */
  1026. u_int32_t st_page_create; /* Pages created in the cache. */
  1027. u_int32_t st_page_in; /* Pages read in. */
  1028. u_int32_t st_page_out; /* Pages written out. */
  1029. u_int32_t st_ro_evict; /* Clean pages forced from the cache. */
  1030. u_int32_t st_rw_evict; /* Dirty pages forced from the cache. */
  1031. u_int32_t st_hash_buckets; /* Number of hash buckets. */
  1032. u_int32_t st_hash_searches; /* Total hash chain searches. */
  1033. u_int32_t st_hash_longest; /* Longest hash chain searched. */
  1034. u_int32_t st_hash_examined; /* Total hash entries searched. */
  1035. u_int32_t st_page_clean; /* Clean pages. */
  1036. u_int32_t st_page_dirty; /* Dirty pages. */
  1037. u_int32_t st_page_trickle; /* Pages written by memp_trickle. */
  1038. u_int32_t st_region_wait; /* Region lock granted after wait. */
  1039. u_int32_t st_region_nowait; /* Region lock granted without wait. */
  1040. u_int32_t st_gbytes; /* Total cache size: GB. */
  1041. u_int32_t st_bytes; /* Total cache size: B. */
  1042. u_int32_t st_ncache; /* Number of caches. */
  1043. u_int32_t st_regsize; /* Cache size. */
  1044. };
  1045. /* Mpool file open information structure. */
  1046. struct __db_mpool_finfo {
  1047. int    ftype; /* File type. */
  1048. DBT   *pgcookie; /* Byte-string passed to pgin/pgout. */
  1049. u_int8_t  *fileid; /* Unique file ID. */
  1050. int32_t    lsn_offset; /* LSN offset in page. */
  1051. u_int32_t  clear_len; /* Cleared length on created pages. */
  1052. };
  1053. /* Mpool file statistics structure. */
  1054. struct __db_mpool_fstat {
  1055. char *file_name; /* File name. */
  1056. size_t st_pagesize; /* Page size. */
  1057. u_int32_t st_cache_hit; /* Pages found in the cache. */
  1058. u_int32_t st_cache_miss; /* Pages not found in the cache. */
  1059. u_int32_t st_map; /* Pages from mapped files. */
  1060. u_int32_t st_page_create; /* Pages created in the cache. */
  1061. u_int32_t st_page_in; /* Pages read in. */
  1062. u_int32_t st_page_out; /* Pages written out. */
  1063. };
  1064. int memp_fclose __P((DB_MPOOLFILE *));
  1065. int memp_fget __P((DB_MPOOLFILE *, db_pgno_t *, u_int32_t, void *));
  1066. int memp_fopen __P((DB_ENV *, const char *,
  1067.     u_int32_t, int, size_t, DB_MPOOL_FINFO *, DB_MPOOLFILE **));
  1068. int memp_fput __P((DB_MPOOLFILE *, void *, u_int32_t));
  1069. int memp_fset __P((DB_MPOOLFILE *, void *, u_int32_t));
  1070. int memp_fsync __P((DB_MPOOLFILE *));
  1071. int memp_register __P((DB_ENV *, int,
  1072.     int (*)(DB_ENV *, db_pgno_t, void *, DBT *),
  1073.     int (*)(DB_ENV *, db_pgno_t, void *, DBT *)));
  1074. int memp_stat __P((DB_ENV *,
  1075.     DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, void *(*)(size_t)));
  1076. int memp_sync __P((DB_ENV *, DB_LSN *));
  1077. int memp_trickle __P((DB_ENV *, int, int *));
  1078. /*******************************************************
  1079.  * Transactions.
  1080.  *******************************************************/
  1081. #define DB_TXNVERSION 1
  1082. /* Operations values to the tx_recover() function. */
  1083. #define DB_TXN_BACKWARD_ROLL 1 /* Read the log backwards. */
  1084. #define DB_TXN_FORWARD_ROLL 2 /* Read the log forwards. */
  1085. #define DB_TXN_OPENFILES 3 /* Read for open files. */
  1086. #define DB_TXN_REDO 4 /* Redo the operation. */
  1087. #define DB_TXN_UNDO 5 /* Undo the operation. */
  1088. /* Internal transaction status values. */
  1089. /* Transaction statistics structure. */
  1090. struct __db_txn_active {
  1091. u_int32_t txnid; /* Transaction ID */
  1092. u_int32_t parentid; /* Transaction ID of parent */
  1093. DB_LSN lsn; /* Lsn of the begin record */
  1094. };
  1095. struct __db_txn_stat {
  1096. DB_LSN   st_last_ckp; /* lsn of the last checkpoint */
  1097. DB_LSN   st_pending_ckp; /* last checkpoint did not finish */
  1098. time_t   st_time_ckp; /* time of last checkpoint */
  1099. u_int32_t st_last_txnid; /* last transaction id given out */
  1100. u_int32_t st_maxtxns; /* maximum txns possible */
  1101. u_int32_t st_naborts; /* number of aborted transactions */
  1102. u_int32_t st_nbegins; /* number of begun transactions */
  1103. u_int32_t st_ncommits; /* number of committed transactions */
  1104. u_int32_t st_nactive; /* number of active transactions */
  1105. u_int32_t st_maxnactive; /* maximum active transactions */
  1106. DB_TXN_ACTIVE
  1107.  *st_txnarray; /* array of active transactions */
  1108. u_int32_t st_region_wait; /* Region lock granted after wait. */
  1109. u_int32_t st_region_nowait; /* Region lock granted without wait. */
  1110. u_int32_t st_regsize; /* Region size. */
  1111. };
  1112. int   txn_abort __P((DB_TXN *));
  1113. int   txn_begin __P((DB_ENV *, DB_TXN *, DB_TXN **, u_int32_t));
  1114. int   txn_checkpoint __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
  1115. int   txn_commit __P((DB_TXN *, u_int32_t));
  1116. u_int32_t txn_id __P((DB_TXN *));
  1117. int   txn_prepare __P((DB_TXN *));
  1118. int   txn_stat __P((DB_ENV *, DB_TXN_STAT **, void *(*)(size_t)));
  1119. #ifndef DB_DBM_HSEARCH
  1120. #define DB_DBM_HSEARCH 0 /* No historic interfaces by default. */
  1121. #endif
  1122. #if DB_DBM_HSEARCH != 0
  1123. /*******************************************************
  1124.  * Dbm/Ndbm historic interfaces.
  1125.  *******************************************************/
  1126. #define DBM_INSERT 0 /* Flags to dbm_store(). */
  1127. #define DBM_REPLACE 1
  1128. /*
  1129.  * The DB support for ndbm(3) always appends this suffix to the
  1130.  * file name to avoid overwriting the user's original database.
  1131.  */
  1132. #define DBM_SUFFIX ".db"
  1133. #if defined(_XPG4_2)
  1134. typedef struct {
  1135. char *dptr;
  1136. size_t dsize;
  1137. } datum;
  1138. #else
  1139. typedef struct {
  1140. char *dptr;
  1141. int dsize;
  1142. } datum;
  1143. #endif
  1144. /*
  1145.  * Translate DBM calls into DB calls so that DB doesn't step on the
  1146.  * application's name space.
  1147.  *
  1148.  * The global variables dbrdonly, dirf and pagf were not retained when 4BSD
  1149.  * replaced the dbm interface with ndbm, and are not supported here.
  1150.  */
  1151. #define dbminit(a) __db_dbm_init(a)
  1152. #define dbmclose __db_dbm_close
  1153. #if !defined(__cplusplus)
  1154. #define delete(a) __db_dbm_delete(a)
  1155. #endif
  1156. #define fetch(a) __db_dbm_fetch(a)
  1157. #define firstkey __db_dbm_firstkey
  1158. #define nextkey(a) __db_dbm_nextkey(a)
  1159. #define store(a, b) __db_dbm_store(a, b)
  1160. /* Prototype the DB calls. */
  1161. int  __db_dbm_close __P((void));
  1162. int  __db_dbm_dbrdonly __P((void));
  1163. int  __db_dbm_delete __P((datum));
  1164. int  __db_dbm_dirf __P((void));
  1165. datum  __db_dbm_fetch __P((datum));
  1166. datum  __db_dbm_firstkey __P((void));
  1167. int  __db_dbm_init __P((char *));
  1168. datum  __db_dbm_nextkey __P((datum));
  1169. int  __db_dbm_pagf __P((void));
  1170. int  __db_dbm_store __P((datum, datum));
  1171. /*
  1172.  * Translate NDBM calls into DB calls so that DB doesn't step on the
  1173.  * application's name space.
  1174.  */
  1175. #define dbm_clearerr(a) __db_ndbm_clearerr(a)
  1176. #define dbm_close(a) __db_ndbm_close(a)
  1177. #define dbm_delete(a, b) __db_ndbm_delete(a, b)
  1178. #define dbm_dirfno(a) __db_ndbm_dirfno(a)
  1179. #define dbm_error(a) __db_ndbm_error(a)
  1180. #define dbm_fetch(a, b) __db_ndbm_fetch(a, b)
  1181. #define dbm_firstkey(a) __db_ndbm_firstkey(a)
  1182. #define dbm_nextkey(a) __db_ndbm_nextkey(a)
  1183. #define dbm_open(a, b, c) __db_ndbm_open(a, b, c)
  1184. #define dbm_pagfno(a) __db_ndbm_pagfno(a)
  1185. #define dbm_rdonly(a) __db_ndbm_rdonly(a)
  1186. #define dbm_store(a, b, c, d) __db_ndbm_store(a, b, c, d)
  1187. /* Prototype the DB calls. */
  1188. int  __db_ndbm_clearerr __P((DBM *));
  1189. void  __db_ndbm_close __P((DBM *));
  1190. int  __db_ndbm_delete __P((DBM *, datum));
  1191. int  __db_ndbm_dirfno __P((DBM *));
  1192. int  __db_ndbm_error __P((DBM *));
  1193. datum  __db_ndbm_fetch __P((DBM *, datum));
  1194. datum  __db_ndbm_firstkey __P((DBM *));
  1195. datum  __db_ndbm_nextkey __P((DBM *));
  1196. DBM *__db_ndbm_open __P((const char *, int, int));
  1197. int  __db_ndbm_pagfno __P((DBM *));
  1198. int  __db_ndbm_rdonly __P((DBM *));
  1199. int  __db_ndbm_store __P((DBM *, datum, datum, int));
  1200. /*******************************************************
  1201.  * Hsearch historic interface.
  1202.  *******************************************************/
  1203. typedef enum {
  1204. FIND, ENTER
  1205. } ACTION;
  1206. typedef struct entry {
  1207. char *key;
  1208. char *data;
  1209. } ENTRY;
  1210. /*
  1211.  * Translate HSEARCH calls into DB calls so that DB doesn't step on the
  1212.  * application's name space.
  1213.  */
  1214. #define hcreate(a) __db_hcreate(a)
  1215. #define hdestroy __db_hdestroy
  1216. #define hsearch(a, b) __db_hsearch(a, b)
  1217. /* Prototype the DB calls. */
  1218. int  __db_hcreate __P((size_t));
  1219. void  __db_hdestroy __P((void));
  1220. ENTRY *__db_hsearch __P((ENTRY, ACTION));
  1221. #endif /* DB_DBM_HSEARCH */
  1222. /*
  1223.  * XXX
  1224.  * MacOS: Reset Metrowerks C enum sizes.
  1225.  */
  1226. #ifdef __MWERKS__
  1227. #pragma enumsalwaysint reset
  1228. #endif
  1229. #if defined(__cplusplus)
  1230. }
  1231. #endif
  1232. #endif /* !_DB_H_ */