1/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3/*
4 * See the file LICENSE for redistribution information.
5 *
6 * Copyright (c) 1996,2007 Oracle. All rights reserved.
7 *
8 * $Id$
9 *
10 * db.h include file layout:
11 * General.
12 * Database Environment.
13 * Locking subsystem.
14 * Logging subsystem.
15 * Shared buffer cache (mpool) subsystem.
16 * Transaction subsystem.
17 * Access methods.
18 * Access method cursors.
19 * Dbm/Ndbm, Hsearch historic interfaces.
20 */
21
22#ifndef _DB_H_
23#define _DB_H_
24
25#ifndef __NO_SYSTEM_INCLUDES
26#include <sys/types.h>
27#include <inttypes.h>
28#include <stdint.h>
29#include <stddef.h>
30#include <stdio.h>
31#include <unistd.h>
32#include <pthread.h>
33#endif
34
35
36#if defined(__cplusplus)
37extern "C" {
38#endif
39
40
41#undef __P
42#define __P(protos) protos
43
44/*
45 * Berkeley DB version information.
46 */
47#define DB_VERSION_MAJOR 4
48#define DB_VERSION_MINOR 6
49#define DB_VERSION_PATCH 19
50#define DB_VERSION_STRING "Berkeley DB 4.6.19: (August 10, 2007)"
51
52/*
53 * !!!
54 * Berkeley DB uses specifically sized types. If they're not provided by
55 * the system, typedef them here.
56 *
57 * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
58 * as does BIND and Kerberos, since we don't know for sure what #include
59 * files the user is using.
60 *
61 * !!!
62 * We also provide the standard u_int, u_long etc., if they're not provided
63 * by the system.
64 */
65#ifndef __BIT_TYPES_DEFINED__
66#define __BIT_TYPES_DEFINED__
67
68
69
70
71
72
73
74#endif
75
76
77
78
79
80
81/*
82 * Missing ANSI types.
83 *
84 * uintmax_t --
85 * Largest unsigned type, used to align structures in memory. We don't store
86 * floating point types in structures, so integral types should be sufficient
87 * (and we don't have to worry about systems that store floats in other than
88 * power-of-2 numbers of bytes). Additionally this fixes compilers that rewrite
89 * structure assignments and ANSI C memcpy calls to be in-line instructions
90 * that happen to require alignment.
91 *
92 * uintptr_t --
93 * Unsigned type that's the same size as a pointer. There are places where
94 * DB modifies pointers by discarding the bottom bits to guarantee alignment.
95 * We can't use uintmax_t, it may be larger than the pointer, and compilers
96 * get upset about that. So far we haven't run on any machine where there's
97 * no unsigned type the same size as a pointer -- here's hoping.
98 */
99
100
101
102
103
104
105
106
107
108
109/*
110 * Sequences are only available on machines with 64-bit integral types.
111 */
112typedef int64_t db_seq_t;
113
114/* Thread and process identification. */
115typedef pthread_t db_threadid_t;
116
117/* Basic types that are exported or quasi-exported. */
118typedef uint32_t db_pgno_t; /* Page number type. */
119typedef uint16_t db_indx_t; /* Page offset type. */
120#define DB_MAX_PAGES 0xffffffff /* >= # of pages in a file */
121
122typedef uint32_t db_recno_t; /* Record number type. */
123#define DB_MAX_RECORDS 0xffffffff /* >= # of records in a tree */
124
125typedef uint32_t db_timeout_t; /* Type of a timeout. */
126
127/*
128 * Region offsets are the difference between a pointer in a region and the
129 * region's base address. With private environments, both addresses are the
130 * result of calling malloc, and we can't assume anything about what malloc
131 * will return, so region offsets have to be able to hold differences between
132 * arbitrary pointers.
133 */
134typedef uintptr_t roff_t;
135
136/*
137 * Forward structure declarations, so we can declare pointers and
138 * applications can get type checking.
139 */
140struct __db; typedef struct __db DB;
141struct __db_bt_stat; typedef struct __db_bt_stat DB_BTREE_STAT;
142struct __db_cipher; typedef struct __db_cipher DB_CIPHER;
143struct __db_compact; typedef struct __db_compact DB_COMPACT;
144struct __db_dbt; typedef struct __db_dbt DBT;
145struct __db_env; typedef struct __db_env DB_ENV;
146struct __db_h_stat; typedef struct __db_h_stat DB_HASH_STAT;
147struct __db_ilock; typedef struct __db_ilock DB_LOCK_ILOCK;
148struct __db_lock_stat; typedef struct __db_lock_stat DB_LOCK_STAT;
149struct __db_lock_hstat; typedef struct __db_lock_hstat DB_LOCK_HSTAT;
150struct __db_lock_u; typedef struct __db_lock_u DB_LOCK;
151struct __db_locker; typedef struct __db_locker DB_LOCKER;
152struct __db_lockreq; typedef struct __db_lockreq DB_LOCKREQ;
153struct __db_locktab; typedef struct __db_locktab DB_LOCKTAB;
154struct __db_log; typedef struct __db_log DB_LOG;
155struct __db_log_cursor; typedef struct __db_log_cursor DB_LOGC;
156struct __db_log_stat; typedef struct __db_log_stat DB_LOG_STAT;
157struct __db_lsn; typedef struct __db_lsn DB_LSN;
158struct __db_mpool; typedef struct __db_mpool DB_MPOOL;
159struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
160struct __db_mpool_stat; typedef struct __db_mpool_stat DB_MPOOL_STAT;
161struct __db_mpoolfile; typedef struct __db_mpoolfile DB_MPOOLFILE;
162struct __db_mutex_stat; typedef struct __db_mutex_stat DB_MUTEX_STAT;
163struct __db_mutex_t; typedef struct __db_mutex_t DB_MUTEX;
164struct __db_mutexmgr; typedef struct __db_mutexmgr DB_MUTEXMGR;
165struct __db_preplist; typedef struct __db_preplist DB_PREPLIST;
166struct __db_qam_stat; typedef struct __db_qam_stat DB_QUEUE_STAT;
167struct __db_rep; typedef struct __db_rep DB_REP;
168struct __db_rep_stat; typedef struct __db_rep_stat DB_REP_STAT;
169struct __db_repmgr_site; \
170 typedef struct __db_repmgr_site DB_REPMGR_SITE;
171struct __db_repmgr_stat; \
172 typedef struct __db_repmgr_stat DB_REPMGR_STAT;
173struct __db_seq_record; typedef struct __db_seq_record DB_SEQ_RECORD;
174struct __db_seq_stat; typedef struct __db_seq_stat DB_SEQUENCE_STAT;
175struct __db_sequence; typedef struct __db_sequence DB_SEQUENCE;
176struct __db_txn; typedef struct __db_txn DB_TXN;
177struct __db_txn_active; typedef struct __db_txn_active DB_TXN_ACTIVE;
178struct __db_txn_stat; typedef struct __db_txn_stat DB_TXN_STAT;
179struct __db_txnmgr; typedef struct __db_txnmgr DB_TXNMGR;
180struct __dbc; typedef struct __dbc DBC;
181struct __dbc_internal; typedef struct __dbc_internal DBC_INTERNAL;
182struct __fh_t; typedef struct __fh_t DB_FH;
183struct __fname; typedef struct __fname FNAME;
184struct __key_range; typedef struct __key_range DB_KEY_RANGE;
185struct __mpoolfile; typedef struct __mpoolfile MPOOLFILE;
186
187/* Key/data structure -- a Data-Base Thang. */
188struct __db_dbt {
189 void *data; /* Key/data */
190 uint32_t size; /* key/data length */
191
192 uint32_t ulen; /* RO: length of user buffer. */
193 uint32_t dlen; /* RO: get/put record length. */
194 uint32_t doff; /* RO: get/put record offset. */
195
196 void *app_data;
197
198#define DB_DBT_APPMALLOC 0x001 /* Callback allocated memory. */
199#define DB_DBT_DUPOK 0x002 /* Insert if duplicate. */
200#define DB_DBT_ISSET 0x004 /* Lower level calls set value. */
201#define DB_DBT_MALLOC 0x008 /* Return in malloc'd memory. */
202#define DB_DBT_MULTIPLE 0x010 /* References multiple records. */
203#define DB_DBT_PARTIAL 0x020 /* Partial put/get. */
204#define DB_DBT_REALLOC 0x040 /* Return in realloc'd memory. */
205#define DB_DBT_USERCOPY 0x080 /* Use the user-supplied callback. */
206#define DB_DBT_USERMEM 0x100 /* Return in user's memory. */
207 uint32_t flags;
208};
209
210/*
211 * Common flags --
212 * Interfaces which use any of these common flags should never have
213 * interface specific flags in this range.
214 */
215#define DB_CREATE 0x0000001 /* Create file as necessary. */
216#define DB_DURABLE_UNKNOWN 0x0000002 /* Durability on open (internal). */
217#define DB_FORCE 0x0000004 /* Force (anything). */
218#define DB_MULTIVERSION 0x0000008 /* Multiversion concurrency control. */
219#define DB_NOMMAP 0x0000010 /* Don't mmap underlying file. */
220#define DB_RDONLY 0x0000020 /* Read-only (O_RDONLY). */
221#define DB_RECOVER 0x0000040 /* Run normal recovery. */
222#define DB_THREAD 0x0000080 /* Applications are threaded. */
223#define DB_TRUNCATE 0x0000100 /* Discard existing DB (O_TRUNC). */
224#define DB_TXN_NOSYNC 0x0000200 /* Do not sync log on commit. */
225#define DB_TXN_NOWAIT 0x0000400 /* Do not wait for locks. */
226#define DB_TXN_NOT_DURABLE 0x0000800 /* Do not log changes. */
227#define DB_TXN_WRITE_NOSYNC 0x0001000 /* Write the log but don't sync. */
228#define DB_SPARE_FLAG 0x0002000 /* Spare. */
229
230/*
231 * Common flags --
232 * Interfaces which use any of these common flags should never have
233 * interface specific flags in this range.
234 *
235 * DB_AUTO_COMMIT:
236 * DB_ENV->set_flags, DB->open
237 * (Note: until the 4.3 release, legal to DB->associate, DB->del,
238 * DB->put, DB->remove, DB->rename and DB->truncate, and others.)
239 * DB_READ_COMMITTED:
240 * DB->cursor, DB->get, DB->join, DBcursor->get, DB_ENV->txn_begin
241 * DB_READ_UNCOMMITTED:
242 * DB->cursor, DB->get, DB->join, DB->open, DBcursor->get,
243 * DB_ENV->txn_begin
244 * DB_TXN_SNAPSHOT:
245 * DB_ENV->set_flags, DB_ENV->txn_begin, DB->cursor
246 *
247 * !!!
248 * The DB_READ_COMMITTED and DB_READ_UNCOMMITTED bit masks can't be changed
249 * without also changing the masks for the flags that can be OR'd into DB
250 * access method and cursor operation values.
251 */
252#define DB_IGNORE_LEASE 0x01000000/* Ignore leases. */
253#define DB_AUTO_COMMIT 0x02000000/* Implied transaction. */
254
255#define DB_READ_COMMITTED 0x04000000/* Degree 2 isolation. */
256#define DB_DEGREE_2 0x04000000/* Historic name. */
257
258#define DB_READ_UNCOMMITTED 0x08000000/* Degree 1 isolation. */
259#define DB_DIRTY_READ 0x08000000/* Historic name. */
260
261#define DB_TXN_SNAPSHOT 0x10000000/* Snapshot isolation. */
262
263/*
264 * Flags common to db_env_create and db_create.
265 */
266#define DB_CXX_NO_EXCEPTIONS 0x0000001 /* C++: return error values. */
267
268/*
269 * Flags private to db_env_create.
270 * Shared flags up to 0x0000001 */
271#define DB_RPCCLIENT 0x0000002 /* An RPC client environment. */
272
273/*
274 * Flags private to db_create.
275 * Shared flags up to 0x0000001 */
276#define DB_XA_CREATE 0x0000002 /* Open in an XA environment. */
277
278/*
279 * Flags shared by DB_ENV->remove and DB_ENV->open.
280 * Shared flags up to 0x0002000 */
281#define DB_USE_ENVIRON 0x0004000 /* Use the environment. */
282#define DB_USE_ENVIRON_ROOT 0x0008000 /* Use the environment if root. */
283/*
284 * Flags private to DB_ENV->open.
285 */
286#define DB_INIT_CDB 0x0010000 /* Concurrent Access Methods. */
287#define DB_INIT_LOCK 0x0020000 /* Initialize locking. */
288#define DB_INIT_LOG 0x0040000 /* Initialize logging. */
289#define DB_INIT_MPOOL 0x0080000 /* Initialize mpool. */
290#define DB_INIT_REP 0x0100000 /* Initialize replication. */
291#define DB_INIT_TXN 0x0200000 /* Initialize transactions. */
292#define DB_LOCKDOWN 0x0400000 /* Lock memory into physical core. */
293#define DB_PRIVATE 0x0800000 /* DB_ENV is process local. */
294#define DB_RECOVER_FATAL 0x1000000 /* Run catastrophic recovery. */
295#define DB_REGISTER 0x2000000 /* Multi-process registry. */
296#define DB_SYSTEM_MEM 0x4000000 /* Use system-backed memory. */
297
298#define DB_JOINENV 0x0 /* Compatibility. */
299
300/*
301 * Flags private to DB->open.
302 * Shared flags up to 0x0002000 */
303#define DB_EXCL 0x0004000 /* Exclusive open (O_EXCL). */
304#define DB_FCNTL_LOCKING 0x0008000 /* UNDOC: fcntl(2) locking. */
305#define DB_NO_AUTO_COMMIT 0x0010000 /* Override env-wide AUTOCOMMIT. */
306#define DB_RDWRMASTER 0x0020000 /* UNDOC: allow subdb master open R/W */
307#define DB_WRITEOPEN 0x0040000 /* UNDOC: open with write lock. */
308
309/*
310 * Flags private to DB->associate.
311 * Shared flags up to 0x0002000 */
312#define DB_IMMUTABLE_KEY 0x0004000 /* Secondary key is immutable. */
313/* Shared flags at 0x1000000 */
314
315/*
316 * Flags private to DB_ENV->txn_begin.
317 * Shared flags up to 0x0002000 */
318#define DB_TXN_SYNC 0x0004000 /* Always sync log on commit. */
319#define DB_TXN_WAIT 0x0008000 /* Always wait for locks in this TXN. */
320
321/*
322 * Flags private to DB_ENV->txn_checkpoint.
323 * Shared flags up to 0x0002000 */
324#define DB_CKP_INTERNAL 0x0004000 /* Internally generated checkpoint. */
325
326/*
327 * Flags private to DB_ENV->set_encrypt.
328 */
329#define DB_ENCRYPT_AES 0x0000001 /* AES, assumes SHA1 checksum */
330
331/*
332 * Flags private to DB_ENV->set_flags.
333 * Shared flags up to 0x00002000 */
334#define DB_CDB_ALLDB 0x00004000/* Set CDB locking per environment. */
335#define DB_DIRECT_DB 0x00008000/* Don't buffer databases in the OS. */
336#define DB_DIRECT_LOG 0x00010000/* Don't buffer log files in the OS. */
337#define DB_DSYNC_DB 0x00020000/* Set O_DSYNC on the databases. */
338#define DB_DSYNC_LOG 0x00040000/* Set O_DSYNC on the log. */
339#define DB_LOG_AUTOREMOVE 0x00080000/* Automatically remove log files. */
340#define DB_LOG_INMEMORY 0x00100000/* Store logs in buffers in memory. */
341#define DB_NOLOCKING 0x00200000/* Set locking/mutex behavior. */
342#define DB_NOPANIC 0x00400000/* Set panic state per DB_ENV. */
343#define DB_OVERWRITE 0x00800000/* Overwrite unlinked region files. */
344#define DB_PANIC_ENVIRONMENT 0x01000000/* Set panic state per environment. */
345/* Shared flags at 0x02000000 */
346/* Shared flags at 0x04000000 */
347/* Shared flags at 0x08000000 */
348/* Shared flags at 0x10000000 */
349#define DB_REGION_INIT 0x20000000/* Page-fault regions on open. */
350#define DB_TIME_NOTGRANTED 0x40000000/* Return NOTGRANTED on timeout. */
351#define DB_YIELDCPU 0x80000000/* Yield the CPU (a lot). */
352
353/*
354 * Flags private to DB->set_feedback's callback.
355 */
356#define DB_UPGRADE 0x0000001 /* Upgrading. */
357#define DB_VERIFY 0x0000002 /* Verifying. */
358
359/*
360 * Flags private to DB->compact.
361 * Shared flags up to 0x00002000
362 */
363#define DB_FREELIST_ONLY 0x00004000 /* Just sort and truncate. */
364#define DB_FREE_SPACE 0x00008000 /* Free space . */
365#define DB_COMPACT_FLAGS \
366 (DB_FREELIST_ONLY | DB_FREE_SPACE)
367
368/*
369 * Flags private to DB_MPOOLFILE->open.
370 * Shared flags up to 0x0002000 */
371#define DB_DIRECT 0x0004000 /* Don't buffer the file in the OS. */
372#define DB_EXTENT 0x0008000 /* internal: dealing with an extent. */
373#define DB_ODDFILESIZE 0x0010000 /* Truncate file to N * pgsize. */
374
375/*
376 * Flags private to DB->set_flags.
377 * Shared flags up to 0x00002000 */
378#define DB_CHKSUM 0x00004000 /* Do checksumming */
379#define DB_DUP 0x00008000 /* Btree, Hash: duplicate keys. */
380#define DB_DUPSORT 0x00010000 /* Btree, Hash: duplicate keys. */
381#define DB_ENCRYPT 0x00020000 /* Btree, Hash: duplicate keys. */
382#define DB_INORDER 0x00040000 /* Queue: strict ordering on consume */
383#define DB_RECNUM 0x00080000 /* Btree: record numbers. */
384#define DB_RENUMBER 0x00100000 /* Recno: renumber on insert/delete. */
385#define DB_REVSPLITOFF 0x00200000 /* Btree: turn off reverse splits. */
386#define DB_SNAPSHOT 0x00400000 /* Recno: snapshot the input. */
387
388/*
389 * Flags private to the DB_ENV->stat_print, DB->stat and DB->stat_print methods.
390 */
391#define DB_FAST_STAT 0x0000001 /* Don't traverse the database. */
392#define DB_STAT_ALL 0x0000002 /* Print: Everything. */
393#define DB_STAT_CLEAR 0x0000004 /* Clear stat after returning values. */
394#define DB_STAT_LOCK_CONF 0x0000008 /* Print: Lock conflict matrix. */
395#define DB_STAT_LOCK_LOCKERS 0x0000010 /* Print: Lockers. */
396#define DB_STAT_LOCK_OBJECTS 0x0000020 /* Print: Lock objects. */
397#define DB_STAT_LOCK_PARAMS 0x0000040 /* Print: Lock parameters. */
398#define DB_STAT_MEMP_HASH 0x0000080 /* Print: Mpool hash buckets. */
399#define DB_STAT_NOERROR 0x0000100 /* Internal: continue on error. */
400#define DB_STAT_SUBSYSTEM 0x0000200 /* Print: Subsystems too. */
401
402/*
403 * Flags private to DB->join.
404 */
405#define DB_JOIN_NOSORT 0x0000001 /* Don't try to optimize join. */
406
407/*
408 * Flags private to DB->verify.
409 */
410#define DB_AGGRESSIVE 0x0000001 /* Salvage whatever could be data.*/
411#define DB_NOORDERCHK 0x0000002 /* Skip sort order/hashing check. */
412#define DB_ORDERCHKONLY 0x0000004 /* Only perform the order check. */
413#define DB_PR_PAGE 0x0000008 /* Show page contents (-da). */
414#define DB_PR_RECOVERYTEST 0x0000010 /* Recovery test (-dr). */
415#define DB_PRINTABLE 0x0000020 /* Use printable format for salvage. */
416#define DB_SALVAGE 0x0000040 /* Salvage what looks like data. */
417#define DB_UNREF 0x0000080 /* Report unreferenced pages. */
418/*
419 * !!!
420 * These must not go over 0x8000, or they will collide with the flags
421 * used by __bam_vrfy_subtree.
422 */
423
424/*
425 * Flags private to DB->rep_set_transport's send callback.
426 */
427#define DB_REP_ANYWHERE 0x0000001 /* Message can be serviced anywhere. */
428#define DB_REP_NOBUFFER 0x0000002 /* Do not buffer this message. */
429#define DB_REP_PERMANENT 0x0000004 /* Important--app. may want to flush. */
430#define DB_REP_REREQUEST 0x0000008 /* This msg already been requested. */
431
432/*******************************************************
433 * Mutexes.
434 *******************************************************/
435typedef uint32_t db_mutex_t;
436
437/*
438 * Flag arguments for DbEnv.mutex_alloc, DbEnv.is_alive and for the
439 * DB_MUTEX structure.
440 */
441#define DB_MUTEX_ALLOCATED 0x01 /* Mutex currently allocated. */
442#define DB_MUTEX_LOCKED 0x02 /* Mutex currently locked. */
443#define DB_MUTEX_LOGICAL_LOCK 0x04 /* Mutex backs a database lock. */
444#define DB_MUTEX_PROCESS_ONLY 0x08 /* Mutex private to a process. */
445#define DB_MUTEX_SELF_BLOCK 0x10 /* Must be able to block self. */
446
447struct __db_mutex_stat {
448 /* The following fields are maintained in the region's copy. */
449 uint32_t st_mutex_align; /* Mutex alignment */
450 uint32_t st_mutex_tas_spins; /* Mutex test-and-set spins */
451 uint32_t st_mutex_cnt; /* Mutex count */
452 uint32_t st_mutex_free; /* Available mutexes */
453 uint32_t st_mutex_inuse; /* Mutexes in use */
454 uint32_t st_mutex_inuse_max; /* Maximum mutexes ever in use */
455
456 /* The following fields are filled-in from other places. */
457#ifndef __TEST_DB_NO_STATISTICS
458 uint32_t st_region_wait; /* Region lock granted after wait. */
459 uint32_t st_region_nowait; /* Region lock granted without wait. */
460 roff_t st_regsize; /* Region size. */
461#endif
462};
463
464/* This is the length of the buffer passed to DB_ENV->thread_id_string() */
465#define DB_THREADID_STRLEN 128
466
467/*******************************************************
468 * Locking.
469 *******************************************************/
470#define DB_LOCKVERSION 1
471
472#define DB_FILE_ID_LEN 20 /* Unique file ID length. */
473
474/*
475 * Deadlock detector modes; used in the DB_ENV structure to configure the
476 * locking subsystem.
477 */
478#define DB_LOCK_NORUN 0
479#define DB_LOCK_DEFAULT 1 /* Default policy. */
480#define DB_LOCK_EXPIRE 2 /* Only expire locks, no detection. */
481#define DB_LOCK_MAXLOCKS 3 /* Select locker with max locks. */
482#define DB_LOCK_MAXWRITE 4 /* Select locker with max writelocks. */
483#define DB_LOCK_MINLOCKS 5 /* Select locker with min locks. */
484#define DB_LOCK_MINWRITE 6 /* Select locker with min writelocks. */
485#define DB_LOCK_OLDEST 7 /* Select oldest locker. */
486#define DB_LOCK_RANDOM 8 /* Select random locker. */
487#define DB_LOCK_YOUNGEST 9 /* Select youngest locker. */
488
489/* Flag values for lock_vec(), lock_get(). */
490#define DB_LOCK_ABORT 0x001 /* Internal: Lock during abort. */
491#define DB_LOCK_NOWAIT 0x002 /* Don't wait on unavailable lock. */
492#define DB_LOCK_RECORD 0x004 /* Internal: record lock. */
493#define DB_LOCK_SET_TIMEOUT 0x008 /* Internal: set lock timeout. */
494#define DB_LOCK_SWITCH 0x010 /* Internal: switch existing lock. */
495#define DB_LOCK_UPGRADE 0x020 /* Internal: upgrade existing lock. */
496
497/* Flag values for DbEnv.set_timeout. */
498#define DB_SET_LOCK_TIMEOUT 1 /* Set lock timeout */
499#define DB_SET_TXN_NOW 2 /* Timeout lock now (internal) */
500#define DB_SET_TXN_TIMEOUT 3 /* Set transaction timeout */
501
502/*
503 * Simple R/W lock modes and for multi-granularity intention locking.
504 *
505 * !!!
506 * These values are NOT random, as they are used as an index into the lock
507 * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
508 * must be == 4.
509 */
510typedef enum {
511 DB_LOCK_NG=0, /* Not granted. */
512 DB_LOCK_READ=1, /* Shared/read. */
513 DB_LOCK_WRITE=2, /* Exclusive/write. */
514 DB_LOCK_WAIT=3, /* Wait for event */
515 DB_LOCK_IWRITE=4, /* Intent exclusive/write. */
516 DB_LOCK_IREAD=5, /* Intent to share/read. */
517 DB_LOCK_IWR=6, /* Intent to read and write. */
518 DB_LOCK_READ_UNCOMMITTED=7, /* Degree 1 isolation. */
519 DB_LOCK_WWRITE=8 /* Was Written. */
520} db_lockmode_t;
521
522/*
523 * Request types.
524 */
525typedef enum {
526 DB_LOCK_DUMP=0, /* Display held locks. */
527 DB_LOCK_GET=1, /* Get the lock. */
528 DB_LOCK_GET_TIMEOUT=2, /* Get lock with a timeout. */
529 DB_LOCK_INHERIT=3, /* Pass locks to parent. */
530 DB_LOCK_PUT=4, /* Release the lock. */
531 DB_LOCK_PUT_ALL=5, /* Release locker's locks. */
532 DB_LOCK_PUT_OBJ=6, /* Release locker's locks on obj. */
533 DB_LOCK_PUT_READ=7, /* Release locker's read locks. */
534 DB_LOCK_TIMEOUT=8, /* Force a txn to timeout. */
535 DB_LOCK_TRADE=9, /* Trade locker ids on a lock. */
536 DB_LOCK_UPGRADE_WRITE=10 /* Upgrade writes for dirty reads. */
537} db_lockop_t;
538
539/*
540 * Status of a lock.
541 */
542typedef enum {
543 DB_LSTAT_ABORTED=1, /* Lock belongs to an aborted txn. */
544 DB_LSTAT_EXPIRED=2, /* Lock has expired. */
545 DB_LSTAT_FREE=3, /* Lock is unallocated. */
546 DB_LSTAT_HELD=4, /* Lock is currently held. */
547 DB_LSTAT_PENDING=5, /* Lock was waiting and has been
548 * promoted; waiting for the owner
549 * to run and upgrade it to held. */
550 DB_LSTAT_WAITING=6 /* Lock is on the wait queue. */
551}db_status_t;
552
553/* Lock statistics structure. */
554struct __db_lock_stat {
555 uint32_t st_id; /* Last allocated locker ID. */
556 uint32_t st_cur_maxid; /* Current maximum unused ID. */
557 uint32_t st_maxlocks; /* Maximum number of locks in table. */
558 uint32_t st_maxlockers; /* Maximum num of lockers in table. */
559 uint32_t st_maxobjects; /* Maximum num of objects in table. */
560 int st_nmodes; /* Number of lock modes. */
561 uint32_t st_nlockers; /* Current number of lockers. */
562#ifndef __TEST_DB_NO_STATISTICS
563 uint32_t st_nlocks; /* Current number of locks. */
564 uint32_t st_maxnlocks; /* Maximum number of locks so far. */
565 uint32_t st_maxnlockers; /* Maximum number of lockers so far. */
566 uint32_t st_nobjects; /* Current number of objects. */
567 uint32_t st_maxnobjects; /* Maximum number of objects so far. */
568 uint32_t st_nrequests; /* Number of lock gets. */
569 uint32_t st_nreleases; /* Number of lock puts. */
570 uint32_t st_nupgrade; /* Number of lock upgrades. */
571 uint32_t st_ndowngrade; /* Number of lock downgrades. */
572 uint32_t st_lock_wait; /* Lock conflicts w/ subsequent wait */
573 uint32_t st_lock_nowait; /* Lock conflicts w/o subsequent wait */
574 uint32_t st_ndeadlocks; /* Number of lock deadlocks. */
575 db_timeout_t st_locktimeout; /* Lock timeout. */
576 uint32_t st_nlocktimeouts; /* Number of lock timeouts. */
577 db_timeout_t st_txntimeout; /* Transaction timeout. */
578 uint32_t st_ntxntimeouts; /* Number of transaction timeouts. */
579 uint32_t st_objs_wait; /* Object lock granted after wait. */
580 uint32_t st_objs_nowait; /* Object lock granted without wait. */
581 uint32_t st_lockers_wait; /* Locker lock granted after wait. */
582 uint32_t st_lockers_nowait; /* Locker lock granted without wait. */
583 uint32_t st_locks_wait; /* Lock lock granted after wait. */
584 uint32_t st_locks_nowait; /* Lock lock granted without wait. */
585 uint32_t st_region_wait; /* Region lock granted after wait. */
586 uint32_t st_region_nowait; /* Region lock granted without wait. */
587 uint32_t st_hash_len; /* Max length of bucket. */
588 roff_t st_regsize; /* Region size. */
589#endif
590};
591
592struct __db_lock_hstat {
593 uint32_t st_nrequests; /* Number of lock gets. */
594 uint32_t st_nreleases; /* Number of lock puts. */
595 uint32_t st_nupgrade; /* Number of lock upgrades. */
596 uint32_t st_ndowngrade; /* Number of lock downgrades. */
597 uint32_t st_lock_wait; /* Lock conflicts w/ subsequent wait */
598 uint32_t st_lock_nowait; /* Lock conflicts w/o subsequent wait */
599 uint32_t st_nlocktimeouts; /* Number of lock timeouts. */
600 uint32_t st_ntxntimeouts; /* Number of transaction timeouts. */
601 uint32_t st_hash_len; /* Max length of bucket. */
602};
603
604/*
605 * DB_LOCK_ILOCK --
606 * Internal DB access method lock.
607 */
608struct __db_ilock {
609 db_pgno_t pgno; /* Page being locked. */
610 uint8_t fileid[DB_FILE_ID_LEN];/* File id. */
611#define DB_HANDLE_LOCK 1
612#define DB_RECORD_LOCK 2
613#define DB_PAGE_LOCK 3
614 uint32_t type; /* Type of lock. */
615};
616
617/*
618 * DB_LOCK --
619 * The structure is allocated by the caller and filled in during a
620 * lock_get request (or a lock_vec/DB_LOCK_GET).
621 */
622struct __db_lock_u {
623 roff_t off; /* Offset of the lock in the region */
624 uint32_t ndx; /* Index of the object referenced by
625 * this lock; used for locking. */
626 uint32_t gen; /* Generation number of this lock. */
627 db_lockmode_t mode; /* mode of this lock. */
628};
629
630/* Lock request structure. */
631struct __db_lockreq {
632 db_lockop_t op; /* Operation. */
633 db_lockmode_t mode; /* Requested mode. */
634 db_timeout_t timeout; /* Time to expire lock. */
635 DBT *obj; /* Object being locked. */
636 DB_LOCK lock; /* Lock returned. */
637};
638
639/*******************************************************
640 * Logging.
641 *******************************************************/
642#define DB_LOGVERSION 13 /* Current log version. */
643#define DB_LOGOLDVER 8 /* Oldest log version supported. */
644#define DB_LOGMAGIC 0x040988
645
646/* Flag values for DB_ENV->log_archive(). */
647#define DB_ARCH_ABS 0x001 /* Absolute pathnames. */
648#define DB_ARCH_DATA 0x002 /* Data files. */
649#define DB_ARCH_LOG 0x004 /* Log files. */
650#define DB_ARCH_REMOVE 0x008 /* Remove log files. */
651
652/* Flag values for DB_ENV->log_put(). */
653#define DB_FLUSH 0x001 /* Flush data to disk (public). */
654#define DB_LOG_CHKPNT 0x002 /* Flush supports a checkpoint */
655#define DB_LOG_COMMIT 0x004 /* Flush supports a commit */
656#define DB_LOG_NOCOPY 0x008 /* Don't copy data */
657#define DB_LOG_NOT_DURABLE 0x010 /* Do not log; keep in memory */
658#define DB_LOG_WRNOSYNC 0x020 /* Write, don't sync log_put */
659
660/*
661 * A DB_LSN has two parts, a fileid which identifies a specific file, and an
662 * offset within that file. The fileid is an unsigned 4-byte quantity that
663 * uniquely identifies a file within the log directory -- currently a simple
664 * counter inside the log. The offset is also an unsigned 4-byte value. The
665 * log manager guarantees the offset is never more than 4 bytes by switching
666 * to a new log file before the maximum length imposed by an unsigned 4-byte
667 * offset is reached.
668 */
669struct __db_lsn {
670 uint32_t file; /* File ID. */
671 uint32_t offset; /* File offset. */
672};
673
674/*
675 * Application-specified log record types start at DB_user_BEGIN, and must not
676 * equal or exceed DB_debug_FLAG.
677 *
678 * DB_debug_FLAG is the high-bit of the uint32_t that specifies a log record
679 * type. If the flag is set, it's a log record that was logged for debugging
680 * purposes only, even if it reflects a database change -- the change was part
681 * of a non-durable transaction.
682 */
683#define DB_user_BEGIN 10000
684#define DB_debug_FLAG 0x80000000
685
686/*
687 * DB_LOGC --
688 * Log cursor.
689 */
690struct __db_log_cursor {
691 DB_ENV *dbenv; /* Enclosing dbenv. */
692
693 DB_FH *fhp; /* File handle. */
694 DB_LSN lsn; /* Cursor: LSN */
695 uint32_t len; /* Cursor: record length */
696 uint32_t prev; /* Cursor: previous record's offset */
697
698 DBT dbt; /* Return DBT. */
699 DB_LSN p_lsn; /* Persist LSN. */
700 uint32_t p_version; /* Persist version. */
701
702 uint8_t *bp; /* Allocated read buffer. */
703 uint32_t bp_size; /* Read buffer length in bytes. */
704 uint32_t bp_rlen; /* Read buffer valid data length. */
705 DB_LSN bp_lsn; /* Read buffer first byte LSN. */
706
707 uint32_t bp_maxrec; /* Max record length in the log file. */
708
709 /* DB_LOGC PUBLIC HANDLE LIST BEGIN */
710 int (*close) __P((DB_LOGC *, uint32_t));
711 int (*get) __P((DB_LOGC *, DB_LSN *, DBT *, uint32_t));
712 int (*version) __P((DB_LOGC *, uint32_t *, uint32_t));
713 /* DB_LOGC PUBLIC HANDLE LIST END */
714
715#define DB_LOG_DISK 0x01 /* Log record came from disk. */
716#define DB_LOG_LOCKED 0x02 /* Log region already locked */
717#define DB_LOG_SILENT_ERR 0x04 /* Turn-off error messages. */
718 uint32_t flags;
719};
720
721/* Log statistics structure. */
722struct __db_log_stat {
723 uint32_t st_magic; /* Log file magic number. */
724 uint32_t st_version; /* Log file version number. */
725 int st_mode; /* Log file permissions mode. */
726 uint32_t st_lg_bsize; /* Log buffer size. */
727 uint32_t st_lg_size; /* Log file size. */
728 uint32_t st_wc_bytes; /* Bytes to log since checkpoint. */
729 uint32_t st_wc_mbytes; /* Megabytes to log since checkpoint. */
730#ifndef __TEST_DB_NO_STATISTICS
731 uint32_t st_record; /* Records entered into the log. */
732 uint32_t st_w_bytes; /* Bytes to log. */
733 uint32_t st_w_mbytes; /* Megabytes to log. */
734 uint32_t st_wcount; /* Total I/O writes to the log. */
735 uint32_t st_wcount_fill; /* Overflow writes to the log. */
736 uint32_t st_rcount; /* Total I/O reads from the log. */
737 uint32_t st_scount; /* Total syncs to the log. */
738 uint32_t st_region_wait; /* Region lock granted after wait. */
739 uint32_t st_region_nowait; /* Region lock granted without wait. */
740 uint32_t st_cur_file; /* Current log file number. */
741 uint32_t st_cur_offset; /* Current log file offset. */
742 uint32_t st_disk_file; /* Known on disk log file number. */
743 uint32_t st_disk_offset; /* Known on disk log file offset. */
744 uint32_t st_maxcommitperflush; /* Max number of commits in a flush. */
745 uint32_t st_mincommitperflush; /* Min number of commits in a flush. */
746 roff_t st_regsize; /* Region size. */
747#endif
748};
749
750/*
751 * We need to record the first log record of a transaction. For user
752 * defined logging this macro returns the place to put that information,
753 * if it is need in rlsnp, otherwise it leaves it unchanged. We also
754 * need to track the last record of the transaction, this returns the
755 * place to put that info.
756 */
757#define DB_SET_TXN_LSNP(txn, blsnp, llsnp) \
758 ((txn)->set_txn_lsnp(txn, blsnp, llsnp))
759
760/*******************************************************
761 * Shared buffer cache (mpool).
762 *******************************************************/
763/* Flag values for DB_MPOOLFILE->get. */
764#define DB_MPOOL_CREATE 0x001 /* Create a page. */
765#define DB_MPOOL_DIRTY 0x002 /* Get page for an update. */
766#define DB_MPOOL_EDIT 0x004 /* Modify without copying. */
767#define DB_MPOOL_FREE 0x008 /* Free page if present. */
768#define DB_MPOOL_LAST 0x010 /* Return the last page. */
769#define DB_MPOOL_NEW 0x020 /* Create a new page. */
770
771/* Undocumented flag value for DB_MPOOLFILE->close. */
772#define DB_MPOOL_DISCARD 0x001 /* Discard file. */
773
774/* Flags values for DB_MPOOLFILE->set_flags. */
775#define DB_MPOOL_NOFILE 0x001 /* Never open a backing file. */
776#define DB_MPOOL_UNLINK 0x002 /* Unlink the file on last close. */
777
778/* Priority values for DB_MPOOLFILE->{put,set_priority}. */
779typedef enum {
780 DB_PRIORITY_UNCHANGED=0,
781 DB_PRIORITY_VERY_LOW=1,
782 DB_PRIORITY_LOW=2,
783 DB_PRIORITY_DEFAULT=3,
784 DB_PRIORITY_HIGH=4,
785 DB_PRIORITY_VERY_HIGH=5
786} DB_CACHE_PRIORITY;
787
788/* Per-process DB_MPOOLFILE information. */
789struct __db_mpoolfile {
790 DB_FH *fhp; /* Underlying file handle. */
791
792 /*
793 * !!!
794 * The ref, pinref and q fields are protected by the region lock.
795 */
796 uint32_t ref; /* Reference count. */
797
798 uint32_t pinref; /* Pinned block reference count. */
799
800 /*
801 * !!!
802 * Explicit representations of structures from queue.h.
803 * TAILQ_ENTRY(__db_mpoolfile) q;
804 */
805 struct {
806 struct __db_mpoolfile *tqe_next;
807 struct __db_mpoolfile **tqe_prev;
808 } q; /* Linked list of DB_MPOOLFILE's. */
809
810 /*
811 * !!!
812 * The rest of the fields (with the exception of the MP_FLUSH flag)
813 * are not thread-protected, even when they may be modified at any
814 * time by the application. The reason is the DB_MPOOLFILE handle
815 * is single-threaded from the viewpoint of the application, and so
816 * the only fields needing to be thread-protected are those accessed
817 * by checkpoint or sync threads when using DB_MPOOLFILE structures
818 * to flush buffers from the cache.
819 */
820 DB_ENV *dbenv; /* Overlying DB_ENV. */
821 MPOOLFILE *mfp; /* Underlying MPOOLFILE. */
822
823 uint32_t clear_len; /* Cleared length on created pages. */
824 uint8_t /* Unique file ID. */
825 fileid[DB_FILE_ID_LEN];
826 int ftype; /* File type. */
827 int32_t lsn_offset; /* LSN offset in page. */
828 uint32_t gbytes, bytes; /* Maximum file size. */
829 DBT *pgcookie; /* Byte-string passed to pgin/pgout. */
830 int32_t priority; /* Cache priority. */
831
832 void *addr; /* Address of mmap'd region. */
833 size_t len; /* Length of mmap'd region. */
834
835 uint32_t config_flags; /* Flags to DB_MPOOLFILE->set_flags. */
836
837 /* DB_MPOOLFILE PUBLIC HANDLE LIST BEGIN */
838 int (*close) __P((DB_MPOOLFILE *, uint32_t));
839 int (*get)
840 __P((DB_MPOOLFILE *, db_pgno_t *, DB_TXN *, uint32_t, void *));
841 int (*get_clear_len) __P((DB_MPOOLFILE *, uint32_t *));
842 int (*get_fileid) __P((DB_MPOOLFILE *, uint8_t *));
843 int (*get_flags) __P((DB_MPOOLFILE *, uint32_t *));
844 int (*get_ftype) __P((DB_MPOOLFILE *, int *));
845 int (*get_last_pgno) __P((DB_MPOOLFILE *, db_pgno_t *));
846 int (*get_lsn_offset) __P((DB_MPOOLFILE *, int32_t *));
847 int (*get_maxsize) __P((DB_MPOOLFILE *, uint32_t *, uint32_t *));
848 int (*get_pgcookie) __P((DB_MPOOLFILE *, DBT *));
849 int (*get_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY *));
850 int (*open) __P((DB_MPOOLFILE *, const char *, uint32_t, int, size_t));
851 int (*put) __P((DB_MPOOLFILE *, void *, DB_CACHE_PRIORITY, uint32_t));
852 int (*set_clear_len) __P((DB_MPOOLFILE *, uint32_t));
853 int (*set_fileid) __P((DB_MPOOLFILE *, uint8_t *));
854 int (*set_flags) __P((DB_MPOOLFILE *, uint32_t, int));
855 int (*set_ftype) __P((DB_MPOOLFILE *, int));
856 int (*set_lsn_offset) __P((DB_MPOOLFILE *, int32_t));
857 int (*set_maxsize) __P((DB_MPOOLFILE *, uint32_t, uint32_t));
858 int (*set_pgcookie) __P((DB_MPOOLFILE *, DBT *));
859 int (*set_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY));
860 int (*sync) __P((DB_MPOOLFILE *));
861 /* DB_MPOOLFILE PUBLIC HANDLE LIST END */
862
863 /*
864 * MP_FILEID_SET, MP_OPEN_CALLED and MP_READONLY do not need to be
865 * thread protected because they are initialized before the file is
866 * linked onto the per-process lists, and never modified.
867 *
868 * MP_FLUSH is thread protected because it is potentially read/set by
869 * multiple threads of control.
870 */
871#define MP_FILEID_SET 0x001 /* Application supplied a file ID. */
872#define MP_FLUSH 0x002 /* Was opened to flush a buffer. */
873#define MP_MULTIVERSION 0x004 /* Opened for multiversion access. */
874#define MP_OPEN_CALLED 0x008 /* File opened. */
875#define MP_READONLY 0x010 /* File is readonly. */
876 uint32_t flags;
877};
878
879/* Mpool statistics structure. */
880struct __db_mpool_stat {
881 uint32_t st_gbytes; /* Total cache size: GB. */
882 uint32_t st_bytes; /* Total cache size: B. */
883 uint32_t st_ncache; /* Number of cache regions. */
884 uint32_t st_max_ncache; /* Maximum number of regions. */
885 size_t st_mmapsize; /* Maximum file size for mmap. */
886 int st_maxopenfd; /* Maximum number of open fd's. */
887 int st_maxwrite; /* Maximum buffers to write. */
888 db_timeout_t st_maxwrite_sleep; /* Sleep after writing max buffers. */
889 uint32_t st_pages; /* Total number of pages. */
890#ifndef __TEST_DB_NO_STATISTICS
891 uint32_t st_map; /* Pages from mapped files. */
892 uint32_t st_cache_hit; /* Pages found in the cache. */
893 uint32_t st_cache_miss; /* Pages not found in the cache. */
894 uint32_t st_page_create; /* Pages created in the cache. */
895 uint32_t st_page_in; /* Pages read in. */
896 uint32_t st_page_out; /* Pages written out. */
897 uint32_t st_ro_evict; /* Clean pages forced from the cache. */
898 uint32_t st_rw_evict; /* Dirty pages forced from the cache. */
899 uint32_t st_page_trickle; /* Pages written by memp_trickle. */
900 uint32_t st_page_clean; /* Clean pages. */
901 uint32_t st_page_dirty; /* Dirty pages. */
902 uint32_t st_hash_buckets; /* Number of hash buckets. */
903 uint32_t st_hash_searches; /* Total hash chain searches. */
904 uint32_t st_hash_longest; /* Longest hash chain searched. */
905 uint32_t st_hash_examined; /* Total hash entries searched. */
906 uint32_t st_hash_nowait; /* Hash lock granted with nowait. */
907 uint32_t st_hash_wait; /* Hash lock granted after wait. */
908 uint32_t st_hash_max_nowait; /* Max hash lock granted with nowait. */
909 uint32_t st_hash_max_wait; /* Max hash lock granted after wait. */
910 uint32_t st_region_nowait; /* Region lock granted with nowait. */
911 uint32_t st_region_wait; /* Region lock granted after wait. */
912 uint32_t st_mvcc_frozen; /* Buffers frozen. */
913 uint32_t st_mvcc_thawed; /* Buffers thawed. */
914 uint32_t st_mvcc_freed; /* Frozen buffers freed. */
915 uint32_t st_alloc; /* Number of page allocations. */
916 uint32_t st_alloc_buckets; /* Buckets checked during allocation. */
917 uint32_t st_alloc_max_buckets; /* Max checked during allocation. */
918 uint32_t st_alloc_pages; /* Pages checked during allocation. */
919 uint32_t st_alloc_max_pages; /* Max checked during allocation. */
920 uint32_t st_io_wait; /* Thread waited on buffer I/O. */
921 roff_t st_regsize; /* Region size. */
922#endif
923};
924
925/* Mpool file statistics structure. */
926struct __db_mpool_fstat {
927 char *file_name; /* File name. */
928 uint32_t st_pagesize; /* Page size. */
929#ifndef __TEST_DB_NO_STATISTICS
930 uint32_t st_map; /* Pages from mapped files. */
931 uint32_t st_cache_hit; /* Pages found in the cache. */
932 uint32_t st_cache_miss; /* Pages not found in the cache. */
933 uint32_t st_page_create; /* Pages created in the cache. */
934 uint32_t st_page_in; /* Pages read in. */
935 uint32_t st_page_out; /* Pages written out. */
936#endif
937};
938
939/*******************************************************
940 * Transactions and recovery.
941 *******************************************************/
942#define DB_TXNVERSION 1
943
944typedef enum {
945 DB_TXN_ABORT=0, /* Public. */
946 DB_TXN_APPLY=1, /* Public. */
947 DB_TXN_BACKWARD_ALLOC=2, /* Internal. */
948 DB_TXN_BACKWARD_ROLL=3, /* Public. */
949 DB_TXN_FORWARD_ROLL=4, /* Public. */
950 DB_TXN_OPENFILES=5, /* Internal. */
951 DB_TXN_POPENFILES=6, /* Internal. */
952 DB_TXN_PRINT=7 /* Public. */
953} db_recops;
954
955/*
956 * BACKWARD_ALLOC is used during the forward pass to pick up any aborted
957 * allocations for files that were created during the forward pass.
958 * The main difference between _ALLOC and _ROLL is that the entry for
959 * the file not exist during the rollforward pass.
960 */
961#define DB_UNDO(op) ((op) == DB_TXN_ABORT || \
962 (op) == DB_TXN_BACKWARD_ROLL || (op) == DB_TXN_BACKWARD_ALLOC)
963#define DB_REDO(op) ((op) == DB_TXN_FORWARD_ROLL || (op) == DB_TXN_APPLY)
964
965struct __db_txn {
966 DB_TXNMGR *mgrp; /* Pointer to transaction manager. */
967 DB_TXN *parent; /* Pointer to transaction's parent. */
968
969 uint32_t txnid; /* Unique transaction id. */
970 char *name; /* Transaction name. */
971 DB_LOCKER *locker; /* Locker for this txn. */
972
973 db_threadid_t tid; /* Thread id for use in MT XA. */
974 void *td; /* Detail structure within region. */
975 db_timeout_t lock_timeout; /* Timeout for locks for this txn. */
976 db_timeout_t expire; /* Time transaction expires. */
977 void *txn_list; /* Undo information for parent. */
978
979 /*
980 * !!!
981 * Explicit representations of structures from queue.h.
982 * TAILQ_ENTRY(__db_txn) links;
983 * TAILQ_ENTRY(__db_txn) xalinks;
984 */
985 struct {
986 struct __db_txn *tqe_next;
987 struct __db_txn **tqe_prev;
988 } links; /* Links transactions off manager. */
989 struct {
990 struct __db_txn *tqe_next;
991 struct __db_txn **tqe_prev;
992 } xalinks; /* Links active XA transactions. */
993
994 /*
995 * !!!
996 * Explicit representations of structures from queue.h.
997 * TAILQ_HEAD(__kids, __db_txn) kids;
998 */
999 struct __kids {
1000 struct __db_txn *tqh_first;
1001 struct __db_txn **tqh_last;
1002 } kids;
1003
1004 /*
1005 * !!!
1006 * Explicit representations of structures from queue.h.
1007 * TAILQ_HEAD(__events, __txn_event) events;
1008 */
1009 struct {
1010 struct __txn_event *tqh_first;
1011 struct __txn_event **tqh_last;
1012 } events; /* Links deferred events. */
1013
1014 /*
1015 * !!!
1016 * Explicit representations of structures from queue.h.
1017 * STAILQ_HEAD(__logrec, __txn_logrec) logs;
1018 */
1019 struct {
1020 struct __txn_logrec *stqh_first;
1021 struct __txn_logrec **stqh_last;
1022 } logs; /* Links in memory log records. */
1023
1024 /*
1025 * !!!
1026 * Explicit representations of structures from queue.h.
1027 * TAILQ_ENTRY(__db_txn) klinks;
1028 */
1029 struct {
1030 struct __db_txn *tqe_next;
1031 struct __db_txn **tqe_prev;
1032 } klinks;
1033
1034 void *api_internal; /* C++ API private. */
1035 void *xml_internal; /* XML API private. */
1036
1037 uint32_t cursors; /* Number of cursors open for txn */
1038
1039 /* DB_TXN PUBLIC HANDLE LIST BEGIN */
1040 int (*abort) __P((DB_TXN *));
1041 int (*commit) __P((DB_TXN *, uint32_t));
1042 int (*discard) __P((DB_TXN *, uint32_t));
1043 int (*get_name) __P((DB_TXN *, const char **));
1044 uint32_t (*id) __P((DB_TXN *));
1045 int (*prepare) __P((DB_TXN *, uint8_t *));
1046 int (*set_name) __P((DB_TXN *, const char *));
1047 int (*set_timeout) __P((DB_TXN *, db_timeout_t, uint32_t));
1048 /* DB_TXN PUBLIC HANDLE LIST END */
1049
1050 /* DB_TXN PRIVATE HANDLE LIST BEGIN */
1051 void (*set_txn_lsnp) __P((DB_TXN *txn, DB_LSN **, DB_LSN **));
1052 /* DB_TXN PRIVATE HANDLE LIST END */
1053
1054#define TXN_CHILDCOMMIT 0x0001 /* Txn has committed. */
1055#define TXN_CDSGROUP 0x0002 /* CDS group handle. */
1056#define TXN_COMPENSATE 0x0004 /* Compensating transaction. */
1057#define TXN_DEADLOCK 0x0008 /* Txn has deadlocked. */
1058#define TXN_LOCKTIMEOUT 0x0010 /* Txn has a lock timeout. */
1059#define TXN_MALLOC 0x0020 /* Structure allocated by TXN system. */
1060#define TXN_NOSYNC 0x0040 /* Do not sync on prepare and commit. */
1061#define TXN_NOWAIT 0x0080 /* Do not wait on locks. */
1062#define TXN_PRIVATE 0x0100 /* Txn owned by cursor.. */
1063#define TXN_READ_COMMITTED 0x0200 /* Txn has degree 2 isolation. */
1064#define TXN_READ_UNCOMMITTED 0x0400 /* Txn has degree 1 isolation. */
1065#define TXN_RESTORED 0x0800 /* Txn has been restored. */
1066#define TXN_SNAPSHOT 0x1000 /* Snapshot Isolation. */
1067#define TXN_SYNC 0x2000 /* Write and sync on prepare/commit. */
1068#define TXN_WRITE_NOSYNC 0x4000 /* Write only on prepare/commit. */
1069 uint32_t flags;
1070};
1071
1072#define TXN_SYNC_FLAGS (TXN_SYNC | TXN_NOSYNC | TXN_WRITE_NOSYNC)
1073
1074/*
1075 * Structure used for two phase commit interface. Berkeley DB support for two
1076 * phase commit is compatible with the X/Open XA interface.
1077 *
1078 * The XA #define XIDDATASIZE defines the size of a global transaction ID. We
1079 * have our own version here (for name space reasons) which must have the same
1080 * value.
1081 */
1082#define DB_XIDDATASIZE 128
1083struct __db_preplist {
1084 DB_TXN *txn;
1085 uint8_t gid[DB_XIDDATASIZE];
1086};
1087
1088/* Transaction statistics structure. */
1089struct __db_txn_active {
1090 uint32_t txnid; /* Transaction ID */
1091 uint32_t parentid; /* Transaction ID of parent */
1092 pid_t pid; /* Process owning txn ID */
1093 db_threadid_t tid; /* Thread owning txn ID */
1094
1095 DB_LSN lsn; /* LSN when transaction began */
1096
1097 DB_LSN read_lsn; /* Read LSN for MVCC */
1098 uint32_t mvcc_ref; /* MVCC reference count */
1099
1100#define TXN_ABORTED 1
1101#define TXN_COMMITTED 2
1102#define TXN_PREPARED 3
1103#define TXN_RUNNING 4
1104 uint32_t status; /* Status of the transaction */
1105
1106#define TXN_XA_ABORTED 1
1107#define TXN_XA_DEADLOCKED 2
1108#define TXN_XA_ENDED 3
1109#define TXN_XA_PREPARED 4
1110#define TXN_XA_STARTED 5
1111#define TXN_XA_SUSPENDED 6
1112 uint32_t xa_status; /* XA status */
1113
1114 uint8_t xid[DB_XIDDATASIZE]; /* Global transaction ID */
1115 char name[51]; /* 50 bytes of name, nul termination */
1116};
1117
1118struct __db_txn_stat {
1119 uint32_t st_nrestores; /* number of restored transactions
1120 after recovery. */
1121#ifndef __TEST_DB_NO_STATISTICS
1122 DB_LSN st_last_ckp; /* lsn of the last checkpoint */
1123 time_t st_time_ckp; /* time of last checkpoint */
1124 uint32_t st_last_txnid; /* last transaction id given out */
1125 uint32_t st_maxtxns; /* maximum txns possible */
1126 uint32_t st_naborts; /* number of aborted transactions */
1127 uint32_t st_nbegins; /* number of begun transactions */
1128 uint32_t st_ncommits; /* number of committed transactions */
1129 uint32_t st_nactive; /* number of active transactions */
1130 uint32_t st_nsnapshot; /* number of snapshot transactions */
1131 uint32_t st_maxnactive; /* maximum active transactions */
1132 uint32_t st_maxnsnapshot; /* maximum snapshot transactions */
1133 DB_TXN_ACTIVE *st_txnarray; /* array of active transactions */
1134 uint32_t st_region_wait; /* Region lock granted after wait. */
1135 uint32_t st_region_nowait; /* Region lock granted without wait. */
1136 roff_t st_regsize; /* Region size. */
1137#endif
1138};
1139
1140/*******************************************************
1141 * Replication.
1142 *******************************************************/
1143/* Special, out-of-band environment IDs. */
1144#define DB_EID_BROADCAST -1
1145#define DB_EID_INVALID -2
1146
1147/* rep_config flag values. */
1148#define DB_REP_CONF_BULK 0x0001 /* Bulk transfer. */
1149#define DB_REP_CONF_DELAYCLIENT 0x0002 /* Delay client synchronization. */
1150#define DB_REP_CONF_NOAUTOINIT 0x0004 /* No automatic client init. */
1151#define DB_REP_CONF_NOWAIT 0x0008 /* Don't wait, return error. */
1152
1153/*
1154 * Operation code values for rep_start and/or repmgr_start. Just one of the
1155 * following values should be passed in the flags parameter. (If we ever need
1156 * additional, independent bit flags for these methods, we can start allocating
1157 * them from the high-order byte of the flags word, as we currently do elsewhere
1158 * for DB_AFTER through DB_WRITELOCK and DB_AUTO_COMMIT, etc.)
1159 */
1160#define DB_REP_CLIENT 1
1161#define DB_REP_ELECTION 2
1162#define DB_REP_MASTER 3
1163
1164#define DB_REPFLAGS_MASK 0x000000ff /* Mask for rep modes. */
1165
1166#define DB_REP_DEFAULT_PRIORITY 100
1167
1168/* Acknowledgement policies. */
1169#define DB_REPMGR_ACKS_ALL 1
1170#define DB_REPMGR_ACKS_ALL_PEERS 2
1171#define DB_REPMGR_ACKS_NONE 3
1172#define DB_REPMGR_ACKS_ONE 4
1173#define DB_REPMGR_ACKS_ONE_PEER 5
1174#define DB_REPMGR_ACKS_QUORUM 6
1175
1176/* Replication timeout configuration values. */
1177#define DB_REP_ACK_TIMEOUT 1 /* RepMgr acknowledgements. */
1178#define DB_REP_CHECKPOINT_DELAY 2 /* RepMgr acknowledgements. */
1179#define DB_REP_CONNECTION_RETRY 3 /* RepMgr connections. */
1180#define DB_REP_ELECTION_RETRY 4 /* RepMgr elect retries. */
1181#define DB_REP_ELECTION_TIMEOUT 5 /* Rep normal elections. */
1182#define DB_REP_FULL_ELECTION_TIMEOUT 6 /* Rep full elections. */
1183#define DB_REP_LEASE_TIMEOUT 7 /* Master leases. */
1184
1185/* Event notification types. */
1186#define DB_EVENT_NO_SUCH_EVENT 0 /* out-of-band sentinel value */
1187#define DB_EVENT_PANIC 1
1188#define DB_EVENT_REP_CLIENT 2
1189#define DB_EVENT_REP_ELECTED 3
1190#define DB_EVENT_REP_MASTER 4
1191#define DB_EVENT_REP_NEWMASTER 5
1192#define DB_EVENT_REP_PERM_FAILED 6
1193#define DB_EVENT_REP_STARTUPDONE 7
1194#define DB_EVENT_WRITE_FAILED 8
1195
1196/* Flag value for repmgr_add_remote_site. */
1197#define DB_REPMGR_PEER 0x01
1198
1199/* Replication Manager site status. */
1200struct __db_repmgr_site {
1201 int eid;
1202 char *host;
1203 u_int port;
1204
1205#define DB_REPMGR_CONNECTED 0x01
1206#define DB_REPMGR_DISCONNECTED 0x02
1207 uint32_t status;
1208};
1209
1210/* Replication statistics. */
1211struct __db_rep_stat {
1212 /* !!!
1213 * Many replication statistics fields cannot be protected by a mutex
1214 * without an unacceptable performance penalty, since most message
1215 * processing is done without the need to hold a region-wide lock.
1216 * Fields whose comments end with a '+' may be updated without holding
1217 * the replication or log mutexes (as appropriate), and thus may be
1218 * off somewhat (or, on unreasonable architectures under unlucky
1219 * circumstances, garbaged).
1220 */
1221 uint32_t st_log_queued; /* Log records currently queued.+ */
1222 uint32_t st_startup_complete; /* Site completed client sync-up. */
1223#ifndef __TEST_DB_NO_STATISTICS
1224 uint32_t st_status; /* Current replication status. */
1225 DB_LSN st_next_lsn; /* Next LSN to use or expect. */
1226 DB_LSN st_waiting_lsn; /* LSN we're awaiting, if any. */
1227 db_pgno_t st_next_pg; /* Next pg we expect. */
1228 db_pgno_t st_waiting_pg; /* pg we're awaiting, if any. */
1229
1230 uint32_t st_dupmasters; /* # of times a duplicate master
1231 condition was detected.+ */
1232 int st_env_id; /* Current environment ID. */
1233 int st_env_priority; /* Current environment priority. */
1234 uint32_t st_bulk_fills; /* Bulk buffer fills. */
1235 uint32_t st_bulk_overflows; /* Bulk buffer overflows. */
1236 uint32_t st_bulk_records; /* Bulk records stored. */
1237 uint32_t st_bulk_transfers; /* Transfers of bulk buffers. */
1238 uint32_t st_client_rerequests; /* Number of forced rerequests. */
1239 uint32_t st_client_svc_req; /* Number of client service requests
1240 received by this client. */
1241 uint32_t st_client_svc_miss; /* Number of client service requests
1242 missing on this client. */
1243 uint32_t st_gen; /* Current generation number. */
1244 uint32_t st_egen; /* Current election gen number. */
1245 uint32_t st_log_duplicated; /* Log records received multiply.+ */
1246 uint32_t st_log_queued_max; /* Max. log records queued at once.+ */
1247 uint32_t st_log_queued_total; /* Total # of log recs. ever queued.+ */
1248 uint32_t st_log_records; /* Log records received and put.+ */
1249 uint32_t st_log_requested; /* Log recs. missed and requested.+ */
1250 int st_master; /* Env. ID of the current master. */
1251 uint32_t st_master_changes; /* # of times we've switched masters. */
1252 uint32_t st_msgs_badgen; /* Messages with a bad generation #.+ */
1253 uint32_t st_msgs_processed; /* Messages received and processed.+ */
1254 uint32_t st_msgs_recover; /* Messages ignored because this site
1255 was a client in recovery.+ */
1256 uint32_t st_msgs_send_failures;/* # of failed message sends.+ */
1257 uint32_t st_msgs_sent; /* # of successful message sends.+ */
1258 uint32_t st_newsites; /* # of NEWSITE msgs. received.+ */
1259 int st_nsites; /* Current number of sites we will
1260 assume during elections. */
1261 uint32_t st_nthrottles; /* # of times we were throttled. */
1262 uint32_t st_outdated; /* # of times we detected and returned
1263 an OUTDATED condition.+ */
1264 uint32_t st_pg_duplicated; /* Pages received multiply.+ */
1265 uint32_t st_pg_records; /* Pages received and stored.+ */
1266 uint32_t st_pg_requested; /* Pages missed and requested.+ */
1267 uint32_t st_txns_applied; /* # of transactions applied.+ */
1268 uint32_t st_startsync_delayed; /* # of STARTSYNC msgs delayed.+ */
1269
1270 /* Elections generally. */
1271 uint32_t st_elections; /* # of elections held.+ */
1272 uint32_t st_elections_won; /* # of elections won by this site.+ */
1273
1274 /* Statistics about an in-progress election. */
1275 int st_election_cur_winner; /* Current front-runner. */
1276 uint32_t st_election_gen; /* Election generation number. */
1277 DB_LSN st_election_lsn; /* Max. LSN of current winner. */
1278 int st_election_nsites; /* # of "registered voters". */
1279 int st_election_nvotes; /* # of "registered voters" needed. */
1280 int st_election_priority; /* Current election priority. */
1281 int st_election_status; /* Current election status. */
1282 uint32_t st_election_tiebreaker;/* Election tiebreaker value. */
1283 int st_election_votes; /* Votes received in this round. */
1284 uint32_t st_election_sec; /* Last election time seconds. */
1285 uint32_t st_election_usec; /* Last election time useconds. */
1286#endif
1287};
1288
1289/* Replication Manager statistics. */
1290struct __db_repmgr_stat {
1291 uint32_t st_perm_failed; /* # of insufficiently ack'ed msgs. */
1292 uint32_t st_msgs_queued; /* # msgs queued for network delay. */
1293 uint32_t st_msgs_dropped; /* # msgs discarded due to excessive
1294 queue length. */
1295 uint32_t st_connection_drop; /* Existing connections dropped. */
1296 uint32_t st_connect_fail; /* Failed new connection attempts. */
1297};
1298
1299/*******************************************************
1300 * Sequences.
1301 *******************************************************/
1302/*
1303 * The storage record for a sequence.
1304 */
1305struct __db_seq_record {
1306 uint32_t seq_version; /* Version size/number. */
1307#define DB_SEQ_DEC 0x00000001 /* Decrement sequence. */
1308#define DB_SEQ_INC 0x00000002 /* Increment sequence. */
1309#define DB_SEQ_RANGE_SET 0x00000004 /* Range set (internal). */
1310#define DB_SEQ_WRAP 0x00000008 /* Wrap sequence at min/max. */
1311#define DB_SEQ_WRAPPED 0x00000010 /* Just wrapped (internal). */
1312 uint32_t flags; /* Flags. */
1313 db_seq_t seq_value; /* Current value. */
1314 db_seq_t seq_max; /* Max permitted. */
1315 db_seq_t seq_min; /* Min permitted. */
1316};
1317
1318/*
1319 * Handle for a sequence object.
1320 */
1321struct __db_sequence {
1322 DB *seq_dbp; /* DB handle for this sequence. */
1323 db_mutex_t mtx_seq; /* Mutex if sequence is threaded. */
1324 DB_SEQ_RECORD *seq_rp; /* Pointer to current data. */
1325 DB_SEQ_RECORD seq_record; /* Data from DB_SEQUENCE. */
1326 int32_t seq_cache_size; /* Number of values cached. */
1327 db_seq_t seq_last_value; /* Last value cached. */
1328 DBT seq_key; /* DBT pointing to sequence key. */
1329 DBT seq_data; /* DBT pointing to seq_record. */
1330
1331 /* API-private structure: used by C++ and Java. */
1332 void *api_internal;
1333
1334 /* DB_SEQUENCE PUBLIC HANDLE LIST BEGIN */
1335 int (*close) __P((DB_SEQUENCE *, uint32_t));
1336 int (*get) __P((DB_SEQUENCE *,
1337 DB_TXN *, int32_t, db_seq_t *, uint32_t));
1338 int (*get_cachesize) __P((DB_SEQUENCE *, int32_t *));
1339 int (*get_db) __P((DB_SEQUENCE *, DB **));
1340 int (*get_flags) __P((DB_SEQUENCE *, uint32_t *));
1341 int (*get_key) __P((DB_SEQUENCE *, DBT *));
1342 int (*get_range) __P((DB_SEQUENCE *,
1343 db_seq_t *, db_seq_t *));
1344 int (*initial_value) __P((DB_SEQUENCE *, db_seq_t));
1345 int (*open) __P((DB_SEQUENCE *,
1346 DB_TXN *, DBT *, uint32_t));
1347 int (*remove) __P((DB_SEQUENCE *, DB_TXN *, uint32_t));
1348 int (*set_cachesize) __P((DB_SEQUENCE *, int32_t));
1349 int (*set_flags) __P((DB_SEQUENCE *, uint32_t));
1350 int (*set_range) __P((DB_SEQUENCE *, db_seq_t, db_seq_t));
1351 int (*stat) __P((DB_SEQUENCE *,
1352 DB_SEQUENCE_STAT **, uint32_t));
1353 int (*stat_print) __P((DB_SEQUENCE *, uint32_t));
1354 /* DB_SEQUENCE PUBLIC HANDLE LIST END */
1355};
1356
1357struct __db_seq_stat {
1358 uint32_t st_wait; /* Sequence lock granted w/o wait. */
1359 uint32_t st_nowait; /* Sequence lock granted after wait. */
1360 db_seq_t st_current; /* Current value in db. */
1361 db_seq_t st_value; /* Current cached value. */
1362 db_seq_t st_last_value; /* Last cached value. */
1363 db_seq_t st_min; /* Minimum value. */
1364 db_seq_t st_max; /* Maximum value. */
1365 int32_t st_cache_size; /* Cache size. */
1366 uint32_t st_flags; /* Flag value. */
1367};
1368
1369/*******************************************************
1370 * Access methods.
1371 *******************************************************/
1372typedef enum {
1373 DB_BTREE=1,
1374 DB_HASH=2,
1375 DB_RECNO=3,
1376 DB_QUEUE=4,
1377 DB_UNKNOWN=5 /* Figure it out on open. */
1378} DBTYPE;
1379
1380#define DB_RENAMEMAGIC 0x030800 /* File has been renamed. */
1381
1382#define DB_BTREEVERSION 9 /* Current btree version. */
1383#define DB_BTREEOLDVER 8 /* Oldest btree version supported. */
1384#define DB_BTREEMAGIC 0x053162
1385
1386#define DB_HASHVERSION 9 /* Current hash version. */
1387#define DB_HASHOLDVER 7 /* Oldest hash version supported. */
1388#define DB_HASHMAGIC 0x061561
1389
1390#define DB_QAMVERSION 4 /* Current queue version. */
1391#define DB_QAMOLDVER 3 /* Oldest queue version supported. */
1392#define DB_QAMMAGIC 0x042253
1393
1394#define DB_SEQUENCE_VERSION 2 /* Current sequence version. */
1395#define DB_SEQUENCE_OLDVER 1 /* Oldest sequence version supported. */
1396
1397/*
1398 * DB access method and cursor operation values. Each value is an operation
1399 * code to which additional bit flags are added.
1400 */
1401#define DB_AFTER 1 /* Dbc.put */
1402#define DB_APPEND 2 /* Db.put */
1403#define DB_BEFORE 3 /* Dbc.put */
1404#define DB_CONSUME 4 /* Db.get */
1405#define DB_CONSUME_WAIT 5 /* Db.get */
1406#define DB_CURRENT 6 /* Dbc.get, Dbc.put, DbLogc.get */
1407#define DB_FIRST 7 /* Dbc.get, DbLogc->get */
1408#define DB_GET_BOTH 8 /* Db.get, Dbc.get */
1409#define DB_GET_BOTHC 9 /* Dbc.get (internal) */
1410#define DB_GET_BOTH_RANGE 10 /* Db.get, Dbc.get */
1411#define DB_GET_RECNO 11 /* Dbc.get */
1412#define DB_JOIN_ITEM 12 /* Dbc.get; don't do primary lookup */
1413#define DB_KEYFIRST 13 /* Dbc.put */
1414#define DB_KEYLAST 14 /* Dbc.put */
1415#define DB_LAST 15 /* Dbc.get, DbLogc->get */
1416#define DB_NEXT 16 /* Dbc.get, DbLogc->get */
1417#define DB_NEXT_DUP 17 /* Dbc.get */
1418#define DB_NEXT_NODUP 18 /* Dbc.get */
1419#define DB_NODUPDATA 19 /* Db.put, Dbc.put */
1420#define DB_NOOVERWRITE 20 /* Db.put */
1421#define DB_NOSYNC 21 /* Db.close */
1422#define DB_POSITION 22 /* Dbc.dup */
1423#define DB_PREV 23 /* Dbc.get, DbLogc->get */
1424#define DB_PREV_DUP 24 /* Dbc.get */
1425#define DB_PREV_NODUP 25 /* Dbc.get */
1426#define DB_SET 26 /* Dbc.get, DbLogc->get */
1427#define DB_SET_RANGE 27 /* Dbc.get */
1428#define DB_SET_RECNO 28 /* Db.get, Dbc.get */
1429#define DB_UPDATE_SECONDARY 29 /* Dbc.get, Dbc.del (internal) */
1430#define DB_WRITECURSOR 30 /* Db.cursor */
1431#define DB_WRITELOCK 31 /* Db.cursor (internal) */
1432
1433/* This has to change when the max opcode hits 255. */
1434#define DB_OPFLAGS_MASK 0x000000ff /* Mask for operations flags. */
1435
1436/*
1437 * Masks for flags that can be OR'd into DB access method and cursor
1438 * operation values. Three top bits have already been taken:
1439 *
1440 * DB_AUTO_COMMIT 0x02000000
1441 * DB_READ_COMMITTED 0x04000000
1442 * DB_READ_UNCOMMITTED 0x08000000
1443 */
1444#define DB_MULTIPLE 0x10000000 /* Return multiple data values. */
1445#define DB_MULTIPLE_KEY 0x20000000 /* Return multiple data/key pairs. */
1446#define DB_RMW 0x40000000 /* Acquire write lock immediately. */
1447
1448/*
1449 * DB (user visible) error return codes.
1450 *
1451 * !!!
1452 * We don't want our error returns to conflict with other packages where
1453 * possible, so pick a base error value that's hopefully not common. We
1454 * document that we own the error name space from -30,800 to -30,999.
1455 */
1456/* DB (public) error return codes. */
1457#define DB_BUFFER_SMALL (-30999)/* User memory too small for return. */
1458#define DB_DONOTINDEX (-30998)/* "Null" return from 2ndary callbk. */
1459#define DB_KEYEMPTY (-30997)/* Key/data deleted or never created. */
1460#define DB_KEYEXIST (-30996)/* The key/data pair already exists. */
1461#define DB_LOCK_DEADLOCK (-30995)/* Deadlock. */
1462#define DB_LOCK_NOTGRANTED (-30994)/* Lock unavailable. */
1463#define DB_LOG_BUFFER_FULL (-30993)/* In-memory log buffer full. */
1464#define DB_NOSERVER (-30992)/* Server panic return. */
1465#define DB_NOSERVER_HOME (-30991)/* Bad home sent to server. */
1466#define DB_NOSERVER_ID (-30990)/* Bad ID sent to server. */
1467#define DB_NOTFOUND (-30989)/* Key/data pair not found (EOF). */
1468#define DB_OLD_VERSION (-30988)/* Out-of-date version. */
1469#define DB_PAGE_NOTFOUND (-30987)/* Requested page not found. */
1470#define DB_REP_DUPMASTER (-30986)/* There are two masters. */
1471#define DB_REP_HANDLE_DEAD (-30985)/* Rolled back a commit. */
1472#define DB_REP_HOLDELECTION (-30984)/* Time to hold an election. */
1473#define DB_REP_IGNORE (-30983)/* This msg should be ignored.*/
1474#define DB_REP_ISPERM (-30982)/* Cached not written perm written.*/
1475#define DB_REP_JOIN_FAILURE (-30981)/* Unable to join replication group. */
1476#define DB_REP_LEASE_EXPIRED (-30980)/* Master lease has expired. */
1477#define DB_REP_LOCKOUT (-30979)/* API/Replication lockout now. */
1478#define DB_REP_NEWSITE (-30978)/* New site entered system. */
1479#define DB_REP_NOTPERM (-30977)/* Permanent log record not written. */
1480#define DB_REP_UNAVAIL (-30976)/* Site cannot currently be reached. */
1481#define DB_RUNRECOVERY (-30975)/* Panic return. */
1482#define DB_SECONDARY_BAD (-30974)/* Secondary index corrupt. */
1483#define DB_VERIFY_BAD (-30973)/* Verify failed; bad format. */
1484#define DB_VERSION_MISMATCH (-30972)/* Environment version mismatch. */
1485
1486/* DB (private) error return codes. */
1487#define DB_ALREADY_ABORTED (-30899)
1488#define DB_DELETED (-30898)/* Recovery file marked deleted. */
1489#define DB_EVENT_NOT_HANDLED (-30897)/* Forward event to application. */
1490#define DB_NEEDSPLIT (-30896)/* Page needs to be split. */
1491#define DB_REP_BULKOVF (-30895)/* Rep bulk buffer overflow. */
1492#define DB_REP_EGENCHG (-30894)/* Egen changed while in election. */
1493#define DB_REP_LOGREADY (-30893)/* Rep log ready for recovery. */
1494#define DB_REP_NEWMASTER (-30892)/* We have learned of a new master. */
1495#define DB_REP_PAGEDONE (-30891)/* This page was already done. */
1496#define DB_SURPRISE_KID (-30890)/* Child commit where parent
1497 didn't know it was a parent. */
1498#define DB_SWAPBYTES (-30889)/* Database needs byte swapping. */
1499#define DB_TIMEOUT (-30888)/* Timed out waiting for election. */
1500#define DB_TXN_CKP (-30887)/* Encountered ckp record in log. */
1501#define DB_VERIFY_FATAL (-30886)/* DB->verify cannot proceed. */
1502
1503/* Database handle. */
1504struct __db {
1505 /*******************************************************
1506 * Public: owned by the application.
1507 *******************************************************/
1508 uint32_t pgsize; /* Database logical page size. */
1509 DB_CACHE_PRIORITY priority; /* Database priority in cache. */
1510
1511 /* Callbacks. */
1512 int (*db_append_recno) __P((DB *, DBT *, db_recno_t));
1513 void (*db_feedback) __P((DB *, int, int));
1514 int (*dup_compare) __P((DB *, const DBT *, const DBT *));
1515
1516 void *app_private; /* Application-private handle. */
1517
1518 /*******************************************************
1519 * Private: owned by DB.
1520 *******************************************************/
1521 DB_ENV *dbenv; /* Backing environment. */
1522
1523 DBTYPE type; /* DB access method type. */
1524
1525 DB_MPOOLFILE *mpf; /* Backing buffer pool. */
1526
1527 db_mutex_t mutex; /* Synchronization for free threading */
1528
1529 char *fname, *dname; /* File/database passed to DB->open. */
1530 uint32_t open_flags; /* Flags passed to DB->open. */
1531
1532 uint8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */
1533
1534 uint32_t adj_fileid; /* File's unique ID for curs. adj. */
1535
1536#define DB_LOGFILEID_INVALID -1
1537 FNAME *log_filename; /* File's naming info for logging. */
1538
1539 db_pgno_t meta_pgno; /* Meta page number */
1540 DB_LOCKER *locker; /* Locker for handle locking. */
1541 DB_LOCKER *cur_locker; /* Current handle lock holder. */
1542 DB_TXN *cur_txn; /* Opening transaction. */
1543 DB_LOCKER *associate_locker; /* Locker for DB->associate call. */
1544 DB_LOCK handle_lock; /* Lock held on this handle. */
1545
1546 u_int cl_id; /* RPC: remote client id. */
1547
1548 time_t timestamp; /* Handle timestamp for replication. */
1549 uint32_t fid_gen; /* Rep generation number for fids. */
1550
1551 /*
1552 * Returned data memory for DB->get() and friends.
1553 */
1554 DBT my_rskey; /* Secondary key. */
1555 DBT my_rkey; /* [Primary] key. */
1556 DBT my_rdata; /* Data. */
1557
1558 /*
1559 * !!!
1560 * Some applications use DB but implement their own locking outside of
1561 * DB. If they're using fcntl(2) locking on the underlying database
1562 * file, and we open and close a file descriptor for that file, we will
1563 * discard their locks. The DB_FCNTL_LOCKING flag to DB->open is an
1564 * undocumented interface to support this usage which leaves any file
1565 * descriptors we open until DB->close. This will only work with the
1566 * DB->open interface and simple caches, e.g., creating a transaction
1567 * thread may open/close file descriptors this flag doesn't protect.
1568 * Locking with fcntl(2) on a file that you don't own is a very, very
1569 * unsafe thing to do. 'Nuff said.
1570 */
1571 DB_FH *saved_open_fhp; /* Saved file handle. */
1572
1573 /*
1574 * Linked list of DBP's, linked from the DB_ENV, used to keep track
1575 * of all open db handles for cursor adjustment.
1576 *
1577 * !!!
1578 * Explicit representations of structures from queue.h.
1579 * TAILQ_ENTRY(__db) dblistlinks;
1580 */
1581 struct {
1582 struct __db *tqe_next;
1583 struct __db **tqe_prev;
1584 } dblistlinks;
1585
1586 /*
1587 * Cursor queues.
1588 *
1589 * !!!
1590 * Explicit representations of structures from queue.h.
1591 * TAILQ_HEAD(__cq_fq, __dbc) free_queue;
1592 * TAILQ_HEAD(__cq_aq, __dbc) active_queue;
1593 * TAILQ_HEAD(__cq_jq, __dbc) join_queue;
1594 */
1595 struct __cq_fq {
1596 struct __dbc *tqh_first;
1597 struct __dbc **tqh_last;
1598 } free_queue;
1599 struct __cq_aq {
1600 struct __dbc *tqh_first;
1601 struct __dbc **tqh_last;
1602 } active_queue;
1603 struct __cq_jq {
1604 struct __dbc *tqh_first;
1605 struct __dbc **tqh_last;
1606 } join_queue;
1607
1608 /*
1609 * Secondary index support.
1610 *
1611 * Linked list of secondary indices -- set in the primary.
1612 *
1613 * !!!
1614 * Explicit representations of structures from queue.h.
1615 * LIST_HEAD(s_secondaries, __db);
1616 */
1617 struct {
1618 struct __db *lh_first;
1619 } s_secondaries;
1620
1621 /*
1622 * List entries for secondaries, and reference count of how many
1623 * threads are updating this secondary (see Dbc.put).
1624 *
1625 * !!!
1626 * Note that these are synchronized by the primary's mutex, but
1627 * filled in in the secondaries.
1628 *
1629 * !!!
1630 * Explicit representations of structures from queue.h.
1631 * LIST_ENTRY(__db) s_links;
1632 */
1633 struct {
1634 struct __db *le_next;
1635 struct __db **le_prev;
1636 } s_links;
1637 uint32_t s_refcnt;
1638
1639 /* Secondary callback and free functions -- set in the secondary. */
1640 int (*s_callback) __P((DB *, const DBT *, const DBT *, DBT *));
1641
1642 /* Reference to primary -- set in the secondary. */
1643 DB *s_primary;
1644
1645#define DB_ASSOC_IMMUTABLE_KEY 0x00000001 /* Secondary key is immutable. */
1646
1647 /* Flags passed to associate -- set in the secondary. */
1648 uint32_t s_assoc_flags;
1649
1650 /* API-private structure: used by DB 1.85, C++, Java, Perl and Tcl */
1651 void *api_internal;
1652
1653 /* Subsystem-private structure. */
1654 void *bt_internal; /* Btree/Recno access method. */
1655 void *h_internal; /* Hash access method. */
1656 void *q_internal; /* Queue access method. */
1657 void *xa_internal; /* XA. */
1658
1659 /* DB PUBLIC HANDLE LIST BEGIN */
1660 int (*associate) __P((DB *, DB_TXN *, DB *,
1661 int (*)(DB *, const DBT *, const DBT *, DBT *), uint32_t));
1662 int (*close) __P((DB *, uint32_t));
1663 int (*compact) __P((DB *,
1664 DB_TXN *, DBT *, DBT *, DB_COMPACT *, uint32_t, DBT *));
1665 int (*cursor) __P((DB *, DB_TXN *, DBC **, uint32_t));
1666 int (*del) __P((DB *, DB_TXN *, DBT *, uint32_t));
1667 void (*err) __P((DB *, int, const char *, ...));
1668 void (*errx) __P((DB *, const char *, ...));
1669 int (*exists) __P((DB *, DB_TXN *, DBT *, uint32_t));
1670 int (*fd) __P((DB *, int *));
1671 int (*get) __P((DB *, DB_TXN *, DBT *, DBT *, uint32_t));
1672 int (*get_bt_minkey) __P((DB *, uint32_t *));
1673 int (*get_byteswapped) __P((DB *, int *));
1674 int (*get_cachesize) __P((DB *, uint32_t *, uint32_t *, int *));
1675 int (*get_dbname) __P((DB *, const char **, const char **));
1676 int (*get_encrypt_flags) __P((DB *, uint32_t *));
1677 DB_ENV *(*get_env) __P((DB *));
1678 void (*get_errfile) __P((DB *, FILE **));
1679 void (*get_errpfx) __P((DB *, const char **));
1680 int (*get_flags) __P((DB *, uint32_t *));
1681 int (*get_h_ffactor) __P((DB *, uint32_t *));
1682 int (*get_h_nelem) __P((DB *, uint32_t *));
1683 int (*get_lorder) __P((DB *, int *));
1684 DB_MPOOLFILE *(*get_mpf) __P((DB *));
1685 void (*get_msgfile) __P((DB *, FILE **));
1686 int (*get_multiple) __P((DB *));
1687 int (*get_open_flags) __P((DB *, uint32_t *));
1688 int (*get_pagesize) __P((DB *, uint32_t *));
1689 int (*get_priority) __P((DB *, DB_CACHE_PRIORITY *));
1690 int (*get_q_extentsize) __P((DB *, uint32_t *));
1691 int (*get_re_delim) __P((DB *, int *));
1692 int (*get_re_len) __P((DB *, uint32_t *));
1693 int (*get_re_pad) __P((DB *, int *));
1694 int (*get_re_source) __P((DB *, const char **));
1695 int (*get_transactional) __P((DB *));
1696 int (*get_type) __P((DB *, DBTYPE *));
1697 int (*join) __P((DB *, DBC **, DBC **, uint32_t));
1698 int (*key_range)
1699 __P((DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, uint32_t));
1700 int (*open) __P((DB *,
1701 DB_TXN *, const char *, const char *, DBTYPE, uint32_t, int));
1702 int (*pget) __P((DB *, DB_TXN *, DBT *, DBT *, DBT *, uint32_t));
1703 int (*put) __P((DB *, DB_TXN *, DBT *, DBT *, uint32_t));
1704 int (*remove) __P((DB *, const char *, const char *, uint32_t));
1705 int (*rename) __P((DB *,
1706 const char *, const char *, const char *, uint32_t));
1707 int (*set_alloc) __P((DB *, void *(*)(size_t),
1708 void *(*)(void *, size_t), void (*)(void *)));
1709 int (*set_append_recno) __P((DB *, int (*)(DB *, DBT *, db_recno_t)));
1710 int (*set_bt_compare)
1711 __P((DB *, int (*)(DB *, const DBT *, const DBT *)));
1712 int (*set_bt_minkey) __P((DB *, uint32_t));
1713 int (*set_bt_prefix)
1714 __P((DB *, size_t (*)(DB *, const DBT *, const DBT *)));
1715 int (*set_cachesize) __P((DB *, uint32_t, uint32_t, int));
1716 int (*set_dup_compare)
1717 __P((DB *, int (*)(DB *, const DBT *, const DBT *)));
1718 int (*set_encrypt) __P((DB *, const char *, uint32_t));
1719 void (*set_errcall) __P((DB *,
1720 void (*)(const DB_ENV *, const char *, const char *)));
1721 void (*set_errfile) __P((DB *, FILE *));
1722 void (*set_errpfx) __P((DB *, const char *));
1723 int (*set_feedback) __P((DB *, void (*)(DB *, int, int)));
1724 int (*set_flags) __P((DB *, uint32_t));
1725 int (*set_h_compare)
1726 __P((DB *, int (*)(DB *, const DBT *, const DBT *)));
1727 int (*set_h_ffactor) __P((DB *, uint32_t));
1728 int (*set_h_hash)
1729 __P((DB *, uint32_t (*)(DB *, const void *, uint32_t)));
1730 int (*set_h_nelem) __P((DB *, uint32_t));
1731 int (*set_lorder) __P((DB *, int));
1732 void (*set_msgcall) __P((DB *, void (*)(const DB_ENV *, const char *)));
1733 void (*set_msgfile) __P((DB *, FILE *));
1734 int (*set_pagesize) __P((DB *, uint32_t));
1735 int (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int)));
1736 int (*set_priority) __P((DB *, DB_CACHE_PRIORITY));
1737 int (*set_q_extentsize) __P((DB *, uint32_t));
1738 int (*set_re_delim) __P((DB *, int));
1739 int (*set_re_len) __P((DB *, uint32_t));
1740 int (*set_re_pad) __P((DB *, int));
1741 int (*set_re_source) __P((DB *, const char *));
1742 int (*stat) __P((DB *, DB_TXN *, void *, uint32_t));
1743 int (*stat_print) __P((DB *, uint32_t));
1744 int (*sync) __P((DB *, uint32_t));
1745 int (*truncate) __P((DB *, DB_TXN *, uint32_t *, uint32_t));
1746 int (*upgrade) __P((DB *, const char *, uint32_t));
1747 int (*verify)
1748 __P((DB *, const char *, const char *, FILE *, uint32_t));
1749 /* DB PUBLIC HANDLE LIST END */
1750
1751 /* DB PRIVATE HANDLE LIST BEGIN */
1752 int (*dump) __P((DB *, const char *,
1753 int (*)(void *, const void *), void *, int, int));
1754 int (*db_am_remove) __P((DB *, DB_TXN *, const char *, const char *));
1755 int (*db_am_rename) __P((DB *, DB_TXN *,
1756 const char *, const char *, const char *));
1757 /* DB PRIVATE HANDLE LIST END */
1758
1759 /*
1760 * Never called; these are a place to save function pointers
1761 * so that we can undo an associate.
1762 */
1763 int (*stored_get) __P((DB *, DB_TXN *, DBT *, DBT *, uint32_t));
1764 int (*stored_close) __P((DB *, uint32_t));
1765
1766#define DB_OK_BTREE 0x01
1767#define DB_OK_HASH 0x02
1768#define DB_OK_QUEUE 0x04
1769#define DB_OK_RECNO 0x08
1770 uint32_t am_ok; /* Legal AM choices. */
1771
1772 /*
1773 * This field really ought to be an AM_FLAG, but we have
1774 * have run out of bits. If/when we decide to split up
1775 * the flags, we can incorporate it.
1776 */
1777 int preserve_fid; /* Do not free fileid on close. */
1778
1779#define DB_AM_CHKSUM 0x00000001 /* Checksumming */
1780#define DB_AM_COMPENSATE 0x00000002 /* Created by compensating txn */
1781#define DB_AM_CREATED 0x00000004 /* Database was created upon open */
1782#define DB_AM_CREATED_MSTR 0x00000008 /* Encompassing file was created */
1783#define DB_AM_DBM_ERROR 0x00000010 /* Error in DBM/NDBM database */
1784#define DB_AM_DELIMITER 0x00000020 /* Variable length delimiter set */
1785#define DB_AM_DISCARD 0x00000040 /* Discard any cached pages */
1786#define DB_AM_DUP 0x00000080 /* DB_DUP */
1787#define DB_AM_DUPSORT 0x00000100 /* DB_DUPSORT */
1788#define DB_AM_ENCRYPT 0x00000200 /* Encryption */
1789#define DB_AM_FIXEDLEN 0x00000400 /* Fixed-length records */
1790#define DB_AM_INMEM 0x00000800 /* In-memory; no sync on close */
1791#define DB_AM_INORDER 0x00001000 /* DB_INORDER */
1792#define DB_AM_IN_RENAME 0x00002000 /* File is being renamed */
1793#define DB_AM_NOT_DURABLE 0x00004000 /* Do not log changes */
1794#define DB_AM_OPEN_CALLED 0x00008000 /* DB->open called */
1795#define DB_AM_PAD 0x00010000 /* Fixed-length record pad */
1796#define DB_AM_PGDEF 0x00020000 /* Page size was defaulted */
1797#define DB_AM_RDONLY 0x00040000 /* Database is readonly */
1798#define DB_AM_READ_UNCOMMITTED 0x00080000 /* Support degree 1 isolation */
1799#define DB_AM_RECNUM 0x00100000 /* DB_RECNUM */
1800#define DB_AM_RECOVER 0x00200000 /* DB opened by recovery routine */
1801#define DB_AM_RENUMBER 0x00400000 /* DB_RENUMBER */
1802#define DB_AM_REVSPLITOFF 0x00800000 /* DB_REVSPLITOFF */
1803#define DB_AM_SECONDARY 0x01000000 /* Database is a secondary index */
1804#define DB_AM_SNAPSHOT 0x02000000 /* DB_SNAPSHOT */
1805#define DB_AM_SUBDB 0x04000000 /* Subdatabases supported */
1806#define DB_AM_SWAP 0x08000000 /* Pages need to be byte-swapped */
1807#define DB_AM_TXN 0x10000000 /* Opened in a transaction */
1808#define DB_AM_VERIFYING 0x20000000 /* DB handle is in the verifier */
1809 uint32_t orig_flags; /* Flags at open, for refresh */
1810 uint32_t flags;
1811};
1812
1813/*
1814 * Macros for bulk get. These are only intended for the C API.
1815 * For C++, use DbMultiple*Iterator.
1816 */
1817#define DB_MULTIPLE_INIT(pointer, dbt) \
1818 (pointer = (uint8_t *)(dbt)->data + \
1819 (dbt)->ulen - sizeof(uint32_t))
1820#define DB_MULTIPLE_NEXT(pointer, dbt, retdata, retdlen) \
1821 do { \
1822 if (*((uint32_t *)(pointer)) == (uint32_t)-1) { \
1823 retdata = NULL; \
1824 pointer = NULL; \
1825 break; \
1826 } \
1827 retdata = (uint8_t *) \
1828 (dbt)->data + *(uint32_t *)(pointer); \
1829 (pointer) = (uint32_t *)(pointer) - 1; \
1830 retdlen = *(uint32_t *)(pointer); \
1831 (pointer) = (uint32_t *)(pointer) - 1; \
1832 if (retdlen == 0 && \
1833 retdata == (uint8_t *)(dbt)->data) \
1834 retdata = NULL; \
1835 } while (0)
1836#define DB_MULTIPLE_KEY_NEXT(pointer, dbt, retkey, retklen, retdata, retdlen) \
1837 do { \
1838 if (*((uint32_t *)(pointer)) == (uint32_t)-1) { \
1839 retdata = NULL; \
1840 retkey = NULL; \
1841 pointer = NULL; \
1842 break; \
1843 } \
1844 retkey = (uint8_t *) \
1845 (dbt)->data + *(uint32_t *)(pointer); \
1846 (pointer) = (uint32_t *)(pointer) - 1; \
1847 retklen = *(uint32_t *)(pointer); \
1848 (pointer) = (uint32_t *)(pointer) - 1; \
1849 retdata = (uint8_t *) \
1850 (dbt)->data + *(uint32_t *)(pointer); \
1851 (pointer) = (uint32_t *)(pointer) - 1; \
1852 retdlen = *(uint32_t *)(pointer); \
1853 (pointer) = (uint32_t *)(pointer) - 1; \
1854 } while (0)
1855
1856#define DB_MULTIPLE_RECNO_NEXT(pointer, dbt, recno, retdata, retdlen) \
1857 do { \
1858 if (*((uint32_t *)(pointer)) == (uint32_t)0) { \
1859 recno = 0; \
1860 retdata = NULL; \
1861 pointer = NULL; \
1862 break; \
1863 } \
1864 recno = *(uint32_t *)(pointer); \
1865 (pointer) = (uint32_t *)(pointer) - 1; \
1866 retdata = (uint8_t *) \
1867 (dbt)->data + *(uint32_t *)(pointer); \
1868 (pointer) = (uint32_t *)(pointer) - 1; \
1869 retdlen = *(uint32_t *)(pointer); \
1870 (pointer) = (uint32_t *)(pointer) - 1; \
1871 } while (0)
1872
1873/*******************************************************
1874 * Access method cursors.
1875 *******************************************************/
1876struct __dbc {
1877 DB *dbp; /* Related DB access method. */
1878 DB_TXN *txn; /* Associated transaction. */
1879 DB_CACHE_PRIORITY priority; /* Priority in cache. */
1880
1881 /*
1882 * Active/free cursor queues.
1883 *
1884 * !!!
1885 * Explicit representations of structures from queue.h.
1886 * TAILQ_ENTRY(__dbc) links;
1887 */
1888 struct {
1889 DBC *tqe_next;
1890 DBC **tqe_prev;
1891 } links;
1892
1893 /*
1894 * The DBT *'s below are used by the cursor routines to return
1895 * data to the user when DBT flags indicate that DB should manage
1896 * the returned memory. They point at a DBT containing the buffer
1897 * and length that will be used, and "belonging" to the handle that
1898 * should "own" this memory. This may be a "my_*" field of this
1899 * cursor--the default--or it may be the corresponding field of
1900 * another cursor, a DB handle, a join cursor, etc. In general, it
1901 * will be whatever handle the user originally used for the current
1902 * DB interface call.
1903 */
1904 DBT *rskey; /* Returned secondary key. */
1905 DBT *rkey; /* Returned [primary] key. */
1906 DBT *rdata; /* Returned data. */
1907
1908 DBT my_rskey; /* Space for returned secondary key. */
1909 DBT my_rkey; /* Space for returned [primary] key. */
1910 DBT my_rdata; /* Space for returned data. */
1911
1912 void *lref; /* Reference to default locker. */
1913 DB_LOCKER *locker; /* Locker for this operation. */
1914 DBT lock_dbt; /* DBT referencing lock. */
1915 DB_LOCK_ILOCK lock; /* Object to be locked. */
1916 DB_LOCK mylock; /* CDB lock held on this cursor. */
1917
1918 u_int cl_id; /* Remote client id. */
1919
1920 DBTYPE dbtype; /* Cursor type. */
1921
1922 DBC_INTERNAL *internal; /* Access method private. */
1923
1924 /* DBC PUBLIC HANDLE LIST BEGIN */
1925 int (*close) __P((DBC *));
1926 int (*count) __P((DBC *, db_recno_t *, uint32_t));
1927 int (*del) __P((DBC *, uint32_t));
1928 int (*dup) __P((DBC *, DBC **, uint32_t));
1929 int (*get) __P((DBC *, DBT *, DBT *, uint32_t));
1930 int (*get_priority) __P((DBC *, DB_CACHE_PRIORITY *));
1931 int (*pget) __P((DBC *, DBT *, DBT *, DBT *, uint32_t));
1932 int (*put) __P((DBC *, DBT *, DBT *, uint32_t));
1933 int (*set_priority) __P((DBC *, DB_CACHE_PRIORITY));
1934 /* DBC PUBLIC HANDLE LIST END */
1935
1936 /* The following are the method names deprecated in the 4.6 release. */
1937 int (*c_close) __P((DBC *));
1938 int (*c_count) __P((DBC *, db_recno_t *, uint32_t));
1939 int (*c_del) __P((DBC *, uint32_t));
1940 int (*c_dup) __P((DBC *, DBC **, uint32_t));
1941 int (*c_get) __P((DBC *, DBT *, DBT *, uint32_t));
1942 int (*c_pget) __P((DBC *, DBT *, DBT *, DBT *, uint32_t));
1943 int (*c_put) __P((DBC *, DBT *, DBT *, uint32_t));
1944
1945 /* DBC PRIVATE HANDLE LIST BEGIN */
1946 int (*am_bulk) __P((DBC *, DBT *, uint32_t));
1947 int (*am_close) __P((DBC *, db_pgno_t, int *));
1948 int (*am_del) __P((DBC *));
1949 int (*am_destroy) __P((DBC *));
1950 int (*am_get) __P((DBC *, DBT *, DBT *, uint32_t, db_pgno_t *));
1951 int (*am_put) __P((DBC *, DBT *, DBT *, uint32_t, db_pgno_t *));
1952 int (*am_writelock) __P((DBC *));
1953 /* DBC PRIVATE HANDLE LIST END */
1954
1955/*
1956 * DBC_DONTLOCK and DBC_RECOVER are used during recovery and transaction
1957 * abort. If a transaction is being aborted or recovered then DBC_RECOVER
1958 * will be set and locking and logging will be disabled on this cursor. If
1959 * we are performing a compensating transaction (e.g. free page processing)
1960 * then DB_DONTLOCK will be set to inhibit locking, but logging will still
1961 * be required. DB_DONTLOCK is also used if the whole database is locked.
1962 */
1963#define DBC_ACTIVE 0x0001 /* Cursor in use. */
1964#define DBC_DONTLOCK 0x0002 /* Don't lock on this cursor. */
1965#define DBC_MULTIPLE 0x0004 /* Return Multiple data. */
1966#define DBC_MULTIPLE_KEY 0x0008 /* Return Multiple keys and data. */
1967#define DBC_OPD 0x0010 /* Cursor references off-page dups. */
1968#define DBC_OWN_LID 0x0020 /* Free lock id on destroy. */
1969#define DBC_READ_COMMITTED 0x0040 /* Cursor has degree 2 isolation. */
1970#define DBC_READ_UNCOMMITTED 0x0080 /* Cursor has degree 1 isolation. */
1971#define DBC_RECOVER 0x0100 /* Recovery cursor; don't log/lock. */
1972#define DBC_RMW 0x0200 /* Acquire write flag in read op. */
1973#define DBC_TRANSIENT 0x0400 /* Cursor is transient. */
1974#define DBC_WRITECURSOR 0x0800 /* Cursor may be used to write (CDB). */
1975#define DBC_WRITER 0x1000 /* Cursor immediately writing (CDB). */
1976 uint32_t flags;
1977};
1978
1979/* Key range statistics structure */
1980struct __key_range {
1981 double less;
1982 double equal;
1983 double greater;
1984};
1985
1986/* Btree/Recno statistics structure. */
1987struct __db_bt_stat {
1988 uint32_t bt_magic; /* Magic number. */
1989 uint32_t bt_version; /* Version number. */
1990 uint32_t bt_metaflags; /* Metadata flags. */
1991 uint32_t bt_nkeys; /* Number of unique keys. */
1992 uint32_t bt_ndata; /* Number of data items. */
1993 uint32_t bt_pagecnt; /* Page count. */
1994 uint32_t bt_pagesize; /* Page size. */
1995 uint32_t bt_minkey; /* Minkey value. */
1996 uint32_t bt_re_len; /* Fixed-length record length. */
1997 uint32_t bt_re_pad; /* Fixed-length record pad. */
1998 uint32_t bt_levels; /* Tree levels. */
1999 uint32_t bt_int_pg; /* Internal pages. */
2000 uint32_t bt_leaf_pg; /* Leaf pages. */
2001 uint32_t bt_dup_pg; /* Duplicate pages. */
2002 uint32_t bt_over_pg; /* Overflow pages. */
2003 uint32_t bt_empty_pg; /* Empty pages. */
2004 uint32_t bt_free; /* Pages on the free list. */
2005 uint32_t bt_int_pgfree; /* Bytes free in internal pages. */
2006 uint32_t bt_leaf_pgfree; /* Bytes free in leaf pages. */
2007 uint32_t bt_dup_pgfree; /* Bytes free in duplicate pages. */
2008 uint32_t bt_over_pgfree; /* Bytes free in overflow pages. */
2009};
2010
2011struct __db_compact {
2012 /* Input Parameters. */
2013 uint32_t compact_fillpercent; /* Desired fillfactor: 1-100 */
2014 db_timeout_t compact_timeout; /* Lock timeout. */
2015 uint32_t compact_pages; /* Max pages to process. */
2016 /* Output Stats. */
2017 uint32_t compact_pages_free; /* Number of pages freed. */
2018 uint32_t compact_pages_examine; /* Number of pages examine. */
2019 uint32_t compact_levels; /* Number of levels removed. */
2020 uint32_t compact_deadlock; /* Number of deadlocks. */
2021 db_pgno_t compact_pages_truncated; /* Pages truncated to OS. */
2022 /* Internal. */
2023 db_pgno_t compact_truncate; /* Page number for truncation */
2024};
2025
2026/* Hash statistics structure. */
2027struct __db_h_stat {
2028 uint32_t hash_magic; /* Magic number. */
2029 uint32_t hash_version; /* Version number. */
2030 uint32_t hash_metaflags; /* Metadata flags. */
2031 uint32_t hash_nkeys; /* Number of unique keys. */
2032 uint32_t hash_ndata; /* Number of data items. */
2033 uint32_t hash_pagecnt; /* Page count. */
2034 uint32_t hash_pagesize; /* Page size. */
2035 uint32_t hash_ffactor; /* Fill factor specified at create. */
2036 uint32_t hash_buckets; /* Number of hash buckets. */
2037 uint32_t hash_free; /* Pages on the free list. */
2038 uint32_t hash_bfree; /* Bytes free on bucket pages. */
2039 uint32_t hash_bigpages; /* Number of big key/data pages. */
2040 uint32_t hash_big_bfree; /* Bytes free on big item pages. */
2041 uint32_t hash_overflows; /* Number of overflow pages. */
2042 uint32_t hash_ovfl_free; /* Bytes free on ovfl pages. */
2043 uint32_t hash_dup; /* Number of dup pages. */
2044 uint32_t hash_dup_free; /* Bytes free on duplicate pages. */
2045};
2046
2047/* Queue statistics structure. */
2048struct __db_qam_stat {
2049 uint32_t qs_magic; /* Magic number. */
2050 uint32_t qs_version; /* Version number. */
2051 uint32_t qs_metaflags; /* Metadata flags. */
2052 uint32_t qs_nkeys; /* Number of unique keys. */
2053 uint32_t qs_ndata; /* Number of data items. */
2054 uint32_t qs_pagesize; /* Page size. */
2055 uint32_t qs_extentsize; /* Pages per extent. */
2056 uint32_t qs_pages; /* Data pages. */
2057 uint32_t qs_re_len; /* Fixed-length record length. */
2058 uint32_t qs_re_pad; /* Fixed-length record pad. */
2059 uint32_t qs_pgfree; /* Bytes free in data pages. */
2060 uint32_t qs_first_recno; /* First not deleted record. */
2061 uint32_t qs_cur_recno; /* Next available record number. */
2062};
2063
2064/*******************************************************
2065 * Environment.
2066 *******************************************************/
2067#define DB_REGION_MAGIC 0x120897 /* Environment magic number. */
2068
2069/* Database Environment handle. */
2070struct __db_env {
2071 /*******************************************************
2072 * Public: owned by the application.
2073 *******************************************************/
2074 /* Error message callback. */
2075 void (*db_errcall) __P((const DB_ENV *, const char *, const char *));
2076 FILE *db_errfile; /* Error message file stream. */
2077 const char *db_errpfx; /* Error message prefix. */
2078
2079 FILE *db_msgfile; /* Statistics message file stream. */
2080 /* Statistics message callback. */
2081 void (*db_msgcall) __P((const DB_ENV *, const char *));
2082
2083 /* Other Callbacks. */
2084 void (*db_feedback) __P((DB_ENV *, int, int));
2085 void (*db_paniccall) __P((DB_ENV *, int));
2086 void (*db_event_func) __P((DB_ENV *, uint32_t, void *));
2087
2088 /* App-specified alloc functions. */
2089 void *(*db_malloc) __P((size_t));
2090 void *(*db_realloc) __P((void *, size_t));
2091 void (*db_free) __P((void *));
2092
2093 /* Application callback to copy data to/from a custom data source. */
2094#define DB_USERCOPY_GETDATA 0x0001
2095#define DB_USERCOPY_SETDATA 0x0002
2096 int (*dbt_usercopy)
2097 __P((DBT *, uint32_t, void *, uint32_t, uint32_t));
2098
2099 /*
2100 * Currently, the verbose list is a bit field with room for 32
2101 * entries. There's no reason that it needs to be limited, if
2102 * there are ever more than 32 entries, convert to a bit array.
2103 */
2104#define DB_VERB_DEADLOCK 0x0001 /* Deadlock detection information. */
2105#define DB_VERB_FILEOPS 0x0002 /* Major file operations. */
2106#define DB_VERB_FILEOPS_ALL 0x0004 /* All file operations. */
2107#define DB_VERB_RECOVERY 0x0008 /* Recovery information. */
2108#define DB_VERB_REGISTER 0x0010 /* Dump waits-for table. */
2109#define DB_VERB_REPLICATION 0x0020 /* Replication information. */
2110#define DB_VERB_WAITSFOR 0x0040 /* Dump waits-for table. */
2111 uint32_t verbose; /* Verbose output. */
2112
2113 void *app_private; /* Application-private handle. */
2114
2115 int (*app_dispatch) /* User-specified recovery dispatch. */
2116 __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
2117
2118 /* Mutexes. */
2119 uint32_t mutex_align; /* Mutex alignment */
2120 uint32_t mutex_cnt; /* Number of mutexes to configure */
2121 uint32_t mutex_inc; /* Number of mutexes to add */
2122 uint32_t mutex_tas_spins;/* Test-and-set spin count */
2123
2124 struct {
2125 int alloc_id; /* Allocation ID argument */
2126 uint32_t flags; /* Flags argument */
2127 } *mutex_iq; /* Initial mutexes queue */
2128 u_int mutex_iq_next; /* Count of initial mutexes */
2129 u_int mutex_iq_max; /* Maximum initial mutexes */
2130
2131 /* Locking. */
2132 uint8_t *lk_conflicts; /* Two dimensional conflict matrix. */
2133 int lk_modes; /* Number of lock modes in table. */
2134 uint32_t lk_max; /* Maximum number of locks. */
2135 uint32_t lk_max_lockers;/* Maximum number of lockers. */
2136 uint32_t lk_max_objects;/* Maximum number of locked objects. */
2137 uint32_t lk_detect; /* Deadlock detect on all conflicts. */
2138 db_timeout_t lk_timeout; /* Lock timeout period. */
2139
2140 /* Logging. */
2141 uint32_t lg_bsize; /* Buffer size. */
2142 uint32_t lg_size; /* Log file size. */
2143 uint32_t lg_regionmax; /* Region size. */
2144 int lg_filemode; /* Log file permission mode. */
2145
2146 /* Memory pool. */
2147 u_int mp_ncache; /* Initial number of cache regions. */
2148 uint32_t mp_gbytes; /* Cache size: GB. */
2149 uint32_t mp_bytes; /* Cache size: bytes. */
2150 uint32_t mp_max_gbytes; /* Maximum cache size: GB. */
2151 uint32_t mp_max_bytes; /* Maximum cache size: bytes. */
2152 size_t mp_mmapsize; /* Maximum file size for mmap. */
2153 int mp_maxopenfd; /* Maximum open file descriptors. */
2154 int mp_maxwrite; /* Maximum buffers to write. */
2155 db_timeout_t mp_maxwrite_sleep; /* Sleep after writing max buffers. */
2156
2157 /* Transactions. */
2158 uint32_t tx_max; /* Maximum number of transactions. */
2159 time_t tx_timestamp; /* Recover to specific timestamp. */
2160 db_timeout_t tx_timeout; /* Timeout for transactions. */
2161
2162 /* Thread tracking. */
2163 uint32_t thr_nbucket; /* Number of hash buckets. */
2164 uint32_t thr_max; /* Max before garbage collection. */
2165 void *thr_hashtab; /* Hash table of DB_THREAD_INFO. */
2166
2167 /*******************************************************
2168 * Private: owned by DB.
2169 *******************************************************/
2170 db_mutex_t mtx_env; /* General DbEnv structure mutex. */
2171
2172 pid_t pid_cache; /* Cached process ID. */
2173
2174 /* User files, paths. */
2175 char *db_home; /* Database home. */
2176 char *db_log_dir; /* Database log file directory. */
2177 char *db_tmp_dir; /* Database tmp file directory. */
2178
2179 char **db_data_dir; /* Database data file directories. */
2180 int data_cnt; /* Database data file slots. */
2181 int data_next; /* Next Database data file slot. */
2182
2183 int db_mode; /* Default open permissions. */
2184 int dir_mode; /* Intermediate directory perms. */
2185 void *env_lref; /* Locker in non-threaded handles. */
2186 uint32_t open_flags; /* Flags passed to DB_ENV->open. */
2187
2188 void *reginfo; /* REGINFO structure reference. */
2189 DB_FH *lockfhp; /* fcntl(2) locking file handle. */
2190
2191 DB_FH *registry; /* DB_REGISTER file handle. */
2192 uint32_t registry_off; /*
2193 * Offset of our slot. We can't use
2194 * off_t because its size depends on
2195 * build settings.
2196 */
2197
2198 /* Return IDs. */
2199 void (*thread_id) __P((DB_ENV *, pid_t *, db_threadid_t *));
2200 /* Return if IDs alive. */
2201 int (*is_alive)
2202 __P((DB_ENV *, pid_t, db_threadid_t, uint32_t));
2203 /* Format IDs into a string. */
2204 char *(*thread_id_string)
2205 __P((DB_ENV *, pid_t, db_threadid_t, char *));
2206
2207 int (**recover_dtab) /* Dispatch table for recover funcs. */
2208 __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
2209 size_t recover_dtab_size;
2210 /* Slots in the dispatch table. */
2211
2212 void *cl_handle; /* RPC: remote client handle. */
2213 u_int cl_id; /* RPC: remote client env id. */
2214
2215 int db_ref; /* DB reference count. */
2216
2217 long shm_key; /* shmget(2) key. */
2218
2219 /*
2220 * List of open file handles for this DB_ENV. Must be protected
2221 * for multi-threaded support.
2222 *
2223 * !!!
2224 * Explicit representation of structure in queue.h.
2225 * TAILQ_HEAD(__fdlist, __fh_t);
2226 */
2227 struct __fdlist {
2228 struct __fh_t *tqh_first;
2229 struct __fh_t **tqh_last;
2230 } fdlist;
2231
2232 /*
2233 * List of open DB handles for this DB_ENV, used for cursor
2234 * adjustment. Must be protected for multi-threaded support.
2235 *
2236 * !!!
2237 * Explicit representation of structure in queue.h.
2238 * TAILQ_HEAD(__dblist, __db);
2239 */
2240 db_mutex_t mtx_dblist; /* Mutex. */
2241 struct __dblist {
2242 struct __db *tqh_first;
2243 struct __db **tqh_last;
2244 } dblist;
2245
2246 /*
2247 * XA support.
2248 *
2249 * !!!
2250 * Explicit representations of structures from queue.h.
2251 * TAILQ_ENTRY(__db_env) links;
2252 * TAILQ_HEAD(xa_txn, __db_txn);
2253 */
2254 struct {
2255 struct __db_env *tqe_next;
2256 struct __db_env **tqe_prev;
2257 } links;
2258 struct __xa_txn { /* XA Active Transactions. */
2259 struct __db_txn *tqh_first;
2260 struct __db_txn **tqh_last;
2261 } xa_txn;
2262 int xa_rmid; /* XA Resource Manager ID. */
2263
2264 char *passwd; /* Cryptography support. */
2265 size_t passwd_len;
2266 void *crypto_handle; /* Primary handle. */
2267 db_mutex_t mtx_mt; /* Mersenne Twister mutex. */
2268 int mti; /* Mersenne Twister index. */
2269 u_long *mt; /* Mersenne Twister state vector. */
2270
2271 /* API-private structure. */
2272 void *api1_internal; /* C++, Perl API private */
2273 void *api2_internal; /* Java API private */
2274
2275 DB_LOCKTAB *lk_handle; /* Lock handle. */
2276 DB_LOG *lg_handle; /* Log handle. */
2277 DB_MPOOL *mp_handle; /* Mpool handle. */
2278 DB_MUTEXMGR *mutex_handle; /* Mutex handle. */
2279 DB_REP *rep_handle; /* Replication handle. */
2280 DB_TXNMGR *tx_handle; /* Txn handle. */
2281
2282 /* DB_ENV PUBLIC HANDLE LIST BEGIN */
2283 int (*cdsgroup_begin) __P((DB_ENV *, DB_TXN **));
2284 int (*close) __P((DB_ENV *, uint32_t));
2285 int (*dbremove) __P((DB_ENV *,
2286 DB_TXN *, const char *, const char *, uint32_t));
2287 int (*dbrename) __P((DB_ENV *,
2288 DB_TXN *, const char *, const char *, const char *, uint32_t));
2289 void (*err) __P((const DB_ENV *, int, const char *, ...));
2290 void (*errx) __P((const DB_ENV *, const char *, ...));
2291 int (*failchk) __P((DB_ENV *, uint32_t));
2292 int (*fileid_reset) __P((DB_ENV *, const char *, uint32_t));
2293 int (*get_cachesize) __P((DB_ENV *, uint32_t *, uint32_t *, int *));
2294 int (*get_cache_max) __P((DB_ENV *, uint32_t *, uint32_t *));
2295 int (*get_data_dirs) __P((DB_ENV *, const char ***));
2296 int (*get_encrypt_flags) __P((DB_ENV *, uint32_t *));
2297 void (*get_errfile) __P((DB_ENV *, FILE **));
2298 void (*get_errpfx) __P((DB_ENV *, const char **));
2299 int (*get_flags) __P((DB_ENV *, uint32_t *));
2300 int (*get_home) __P((DB_ENV *, const char **));
2301 int (*get_lg_bsize) __P((DB_ENV *, uint32_t *));
2302 int (*get_lg_dir) __P((DB_ENV *, const char **));
2303 int (*get_lg_filemode) __P((DB_ENV *, int *));
2304 int (*get_lg_max) __P((DB_ENV *, uint32_t *));
2305 int (*get_lg_regionmax) __P((DB_ENV *, uint32_t *));
2306 int (*get_lk_conflicts) __P((DB_ENV *, const uint8_t **, int *));
2307 int (*get_lk_detect) __P((DB_ENV *, uint32_t *));
2308 int (*get_lk_max_lockers) __P((DB_ENV *, uint32_t *));
2309 int (*get_lk_max_locks) __P((DB_ENV *, uint32_t *));
2310 int (*get_lk_max_objects) __P((DB_ENV *, uint32_t *));
2311 int (*get_mp_max_openfd) __P((DB_ENV *, int *));
2312 int (*get_mp_max_write) __P((DB_ENV *, int *, db_timeout_t *));
2313 int (*get_mp_mmapsize) __P((DB_ENV *, size_t *));
2314 void (*get_msgfile) __P((DB_ENV *, FILE **));
2315 int (*get_open_flags) __P((DB_ENV *, uint32_t *));
2316 int (*get_shm_key) __P((DB_ENV *, long *));
2317 int (*get_thread_count) __P((DB_ENV *, uint32_t *));
2318 int (*get_timeout) __P((DB_ENV *, db_timeout_t *, uint32_t));
2319 int (*get_tmp_dir) __P((DB_ENV *, const char **));
2320 int (*get_tx_max) __P((DB_ENV *, uint32_t *));
2321 int (*get_tx_timestamp) __P((DB_ENV *, time_t *));
2322 int (*get_verbose) __P((DB_ENV *, uint32_t, int *));
2323 int (*is_bigendian) __P((void));
2324 int (*lock_detect) __P((DB_ENV *, uint32_t, uint32_t, int *));
2325 int (*lock_get) __P((DB_ENV *,
2326 uint32_t, uint32_t, const DBT *, db_lockmode_t, DB_LOCK *));
2327 int (*lock_id) __P((DB_ENV *, uint32_t *));
2328 int (*lock_id_free) __P((DB_ENV *, uint32_t));
2329 int (*lock_put) __P((DB_ENV *, DB_LOCK *));
2330 int (*lock_stat) __P((DB_ENV *, DB_LOCK_STAT **, uint32_t));
2331 int (*lock_stat_print) __P((DB_ENV *, uint32_t));
2332 int (*lock_vec) __P((DB_ENV *,
2333 uint32_t, uint32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
2334 int (*log_archive) __P((DB_ENV *, char **[], uint32_t));
2335 int (*log_cursor) __P((DB_ENV *, DB_LOGC **, uint32_t));
2336 int (*log_file) __P((DB_ENV *, const DB_LSN *, char *, size_t));
2337 int (*log_flush) __P((DB_ENV *, const DB_LSN *));
2338 int (*log_printf) __P((DB_ENV *, DB_TXN *, const char *, ...));
2339 int (*log_put) __P((DB_ENV *, DB_LSN *, const DBT *, uint32_t));
2340 int (*log_stat) __P((DB_ENV *, DB_LOG_STAT **, uint32_t));
2341 int (*log_stat_print) __P((DB_ENV *, uint32_t));
2342 int (*lsn_reset) __P((DB_ENV *, const char *, uint32_t));
2343 int (*memp_fcreate) __P((DB_ENV *, DB_MPOOLFILE **, uint32_t));
2344 int (*memp_register) __P((DB_ENV *, int, int (*)(DB_ENV *,
2345 db_pgno_t, void *, DBT *), int (*)(DB_ENV *,
2346 db_pgno_t, void *, DBT *)));
2347 int (*memp_stat) __P((DB_ENV *,
2348 DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, uint32_t));
2349 int (*memp_stat_print) __P((DB_ENV *, uint32_t));
2350 int (*memp_sync) __P((DB_ENV *, DB_LSN *));
2351 int (*memp_trickle) __P((DB_ENV *, int, int *));
2352 int (*mutex_alloc) __P((DB_ENV *, uint32_t, db_mutex_t *));
2353 int (*mutex_free) __P((DB_ENV *, db_mutex_t));
2354 int (*mutex_get_align) __P((DB_ENV *, uint32_t *));
2355 int (*mutex_get_increment) __P((DB_ENV *, uint32_t *));
2356 int (*mutex_get_max) __P((DB_ENV *, uint32_t *));
2357 int (*mutex_get_tas_spins) __P((DB_ENV *, uint32_t *));
2358 int (*mutex_lock) __P((DB_ENV *, db_mutex_t));
2359 int (*mutex_set_align) __P((DB_ENV *, uint32_t));
2360 int (*mutex_set_increment) __P((DB_ENV *, uint32_t));
2361 int (*mutex_set_max) __P((DB_ENV *, uint32_t));
2362 int (*mutex_set_tas_spins) __P((DB_ENV *, uint32_t));
2363 int (*mutex_stat) __P((DB_ENV *, DB_MUTEX_STAT **, uint32_t));
2364 int (*mutex_stat_print) __P((DB_ENV *, uint32_t));
2365 int (*mutex_unlock) __P((DB_ENV *, db_mutex_t));
2366 int (*open) __P((DB_ENV *, const char *, uint32_t, int));
2367 int (*remove) __P((DB_ENV *, const char *, uint32_t));
2368 int (*rep_elect) __P((DB_ENV *, int, int, uint32_t));
2369 int (*rep_flush) __P((DB_ENV *));
2370 int (*rep_get_config) __P((DB_ENV *, uint32_t, int *));
2371 int (*rep_get_limit) __P((DB_ENV *, uint32_t *, uint32_t *));
2372 int (*rep_get_nsites) __P((DB_ENV *, int *));
2373 int (*rep_get_priority) __P((DB_ENV *, int *));
2374 int (*rep_get_timeout) __P((DB_ENV *, int, uint32_t *));
2375 int (*rep_process_message)
2376 __P((DB_ENV *, DBT *, DBT *, int, DB_LSN *));
2377 int (*rep_set_config) __P((DB_ENV *, uint32_t, int));
2378 int (*rep_set_lease) __P((DB_ENV *, uint32_t, uint32_t));
2379 int (*rep_set_limit) __P((DB_ENV *, uint32_t, uint32_t));
2380 int (*rep_set_nsites) __P((DB_ENV *, int));
2381 int (*rep_set_priority) __P((DB_ENV *, int));
2382 int (*rep_set_timeout) __P((DB_ENV *, int, db_timeout_t));
2383 int (*rep_set_transport) __P((DB_ENV *, int, int (*)(DB_ENV *,
2384 const DBT *, const DBT *, const DB_LSN *, int, uint32_t)));
2385 int (*rep_start) __P((DB_ENV *, DBT *, uint32_t));
2386 int (*rep_stat) __P((DB_ENV *, DB_REP_STAT **, uint32_t));
2387 int (*rep_stat_print) __P((DB_ENV *, uint32_t));
2388 int (*rep_sync) __P((DB_ENV *, uint32_t));
2389 int (*repmgr_add_remote_site) __P((DB_ENV *, const char *, u_int,
2390 int *, uint32_t));
2391 int (*repmgr_get_ack_policy) __P((DB_ENV *, int *));
2392 int (*repmgr_set_ack_policy) __P((DB_ENV *, int));
2393 int (*repmgr_set_local_site) __P((DB_ENV *, const char *, u_int,
2394 uint32_t));
2395 int (*repmgr_site_list) __P((DB_ENV *, u_int *,
2396 DB_REPMGR_SITE **));
2397 int (*repmgr_start) __P((DB_ENV *, int, uint32_t));
2398 int (*repmgr_stat) __P((DB_ENV *, DB_REPMGR_STAT **, uint32_t));
2399 int (*repmgr_stat_print) __P((DB_ENV *, uint32_t));
2400 int (*set_alloc) __P((DB_ENV *, void *(*)(size_t),
2401 void *(*)(void *, size_t), void (*)(void *)));
2402 int (*set_app_dispatch)
2403 __P((DB_ENV *, int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops)));
2404 int (*set_cachesize) __P((DB_ENV *, uint32_t, uint32_t, int));
2405 int (*set_cache_max) __P((DB_ENV *, uint32_t, uint32_t));
2406 int (*set_data_dir) __P((DB_ENV *, const char *));
2407 int (*set_encrypt) __P((DB_ENV *, const char *, uint32_t));
2408 void (*set_errcall) __P((DB_ENV *,
2409 void (*)(const DB_ENV *, const char *, const char *)));
2410 void (*set_errfile) __P((DB_ENV *, FILE *));
2411 void (*set_errpfx) __P((DB_ENV *, const char *));
2412 int (*set_event_notify)
2413 __P((DB_ENV *, void (*)(DB_ENV *, uint32_t, void *)));
2414 int (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
2415 int (*set_flags) __P((DB_ENV *, uint32_t, int));
2416 int (*set_intermediate_dir) __P((DB_ENV *, int, uint32_t));
2417 int (*set_isalive) __P((DB_ENV *,
2418 int (*)(DB_ENV *, pid_t, db_threadid_t, uint32_t)));
2419 int (*set_lg_bsize) __P((DB_ENV *, uint32_t));
2420 int (*set_lg_dir) __P((DB_ENV *, const char *));
2421 int (*set_lg_filemode) __P((DB_ENV *, int));
2422 int (*set_lg_max) __P((DB_ENV *, uint32_t));
2423 int (*set_lg_regionmax) __P((DB_ENV *, uint32_t));
2424 int (*set_lk_conflicts) __P((DB_ENV *, uint8_t *, int));
2425 int (*set_lk_detect) __P((DB_ENV *, uint32_t));
2426 int (*set_lk_max_lockers) __P((DB_ENV *, uint32_t));
2427 int (*set_lk_max_locks) __P((DB_ENV *, uint32_t));
2428 int (*set_lk_max_objects) __P((DB_ENV *, uint32_t));
2429 int (*set_mp_max_openfd) __P((DB_ENV *, int));
2430 int (*set_mp_max_write) __P((DB_ENV *, int, db_timeout_t));
2431 int (*set_mp_mmapsize) __P((DB_ENV *, size_t));
2432 void (*set_msgcall)
2433 __P((DB_ENV *, void (*)(const DB_ENV *, const char *)));
2434 void (*set_msgfile) __P((DB_ENV *, FILE *));
2435 int (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int)));
2436 int (*set_rep_request) __P((DB_ENV *, uint32_t, uint32_t));
2437 int (*set_rpc_server)
2438 __P((DB_ENV *, void *, const char *, long, long, uint32_t));
2439 int (*set_shm_key) __P((DB_ENV *, long));
2440 int (*set_thread_count) __P((DB_ENV *, uint32_t));
2441 int (*set_thread_id) __P((DB_ENV *,
2442 void (*)(DB_ENV *, pid_t *, db_threadid_t *)));
2443 int (*set_thread_id_string) __P((DB_ENV *,
2444 char *(*)(DB_ENV *, pid_t, db_threadid_t, char *)));
2445 int (*set_timeout) __P((DB_ENV *, db_timeout_t, uint32_t));
2446 int (*set_tmp_dir) __P((DB_ENV *, const char *));
2447 int (*set_tx_max) __P((DB_ENV *, uint32_t));
2448 int (*set_tx_timestamp) __P((DB_ENV *, time_t *));
2449 int (*set_verbose) __P((DB_ENV *, uint32_t, int));
2450 int (*stat_print) __P((DB_ENV *, uint32_t));
2451 int (*txn_begin) __P((DB_ENV *, DB_TXN *, DB_TXN **, uint32_t));
2452 int (*txn_checkpoint) __P((DB_ENV *, uint32_t, uint32_t, uint32_t));
2453 int (*txn_recover)
2454 __P((DB_ENV *, DB_PREPLIST *, long, long *, uint32_t));
2455 int (*txn_stat) __P((DB_ENV *, DB_TXN_STAT **, uint32_t));
2456 int (*txn_stat_print) __P((DB_ENV *, uint32_t));
2457 /* DB_ENV PUBLIC HANDLE LIST END */
2458
2459 /* DB_ENV PRIVATE HANDLE LIST BEGIN */
2460 int (*prdbt) __P((DBT *,
2461 int, const char *, void *, int (*)(void *, const void *), int));
2462 /* DB_ENV PRIVATE HANDLE LIST END */
2463
2464#define DB_TEST_ELECTINIT 1 /* after __rep_elect_init */
2465#define DB_TEST_ELECTVOTE1 2 /* after sending VOTE1 */
2466#define DB_TEST_POSTDESTROY 3 /* after destroy op */
2467#define DB_TEST_POSTLOG 4 /* after logging all pages */
2468#define DB_TEST_POSTLOGMETA 5 /* after logging meta in btree */
2469#define DB_TEST_POSTOPEN 6 /* after __os_open */
2470#define DB_TEST_POSTSYNC 7 /* after syncing the log */
2471#define DB_TEST_PREDESTROY 8 /* before destroy op */
2472#define DB_TEST_PREOPEN 9 /* before __os_open */
2473#define DB_TEST_RECYCLE 10 /* test rep and txn_recycle */
2474#define DB_TEST_SUBDB_LOCKS 11 /* subdb locking tests */
2475 int test_abort; /* Abort value for testing. */
2476 int test_check; /* Checkpoint value for testing. */
2477 int test_copy; /* Copy value for testing. */
2478
2479#define DB_ENV_AUTO_COMMIT 0x00000001 /* DB_AUTO_COMMIT. */
2480#define DB_ENV_CDB 0x00000002 /* DB_INIT_CDB. */
2481#define DB_ENV_CDB_ALLDB 0x00000004 /* CDB environment wide locking. */
2482#define DB_ENV_DBLOCAL 0x00000008 /* Environment for a private DB. */
2483#define DB_ENV_DIRECT_DB 0x00000010 /* DB_DIRECT_DB set. */
2484#define DB_ENV_DIRECT_LOG 0x00000020 /* DB_DIRECT_LOG set. */
2485#define DB_ENV_DSYNC_DB 0x00000040 /* DB_DSYNC_DB set. */
2486#define DB_ENV_DSYNC_LOG 0x00000080 /* DB_DSYNC_LOG set. */
2487#define DB_ENV_LOCKDOWN 0x00000100 /* DB_LOCKDOWN set. */
2488#define DB_ENV_LOG_AUTOREMOVE 0x00000200 /* DB_LOG_AUTOREMOVE set. */
2489#define DB_ENV_LOG_INMEMORY 0x00000400 /* DB_LOG_INMEMORY set. */
2490#define DB_ENV_MULTIVERSION 0x00000800 /* DB_MULTIVERSION set. */
2491#define DB_ENV_NOLOCKING 0x00001000 /* DB_NOLOCKING set. */
2492#define DB_ENV_NOMMAP 0x00002000 /* DB_NOMMAP set. */
2493#define DB_ENV_NOPANIC 0x00004000 /* Okay if panic set. */
2494#define DB_ENV_NO_OUTPUT_SET 0x00008000 /* No output channel set. */
2495#define DB_ENV_OPEN_CALLED 0x00010000 /* DB_ENV->open called. */
2496#define DB_ENV_OVERWRITE 0x00020000 /* DB_OVERWRITE set. */
2497#define DB_ENV_PRIVATE 0x00040000 /* DB_PRIVATE set. */
2498#define DB_ENV_RECOVER_FATAL 0x00080000 /* Doing fatal recovery in env. */
2499#define DB_ENV_REF_COUNTED 0x00100000 /* Region references this handle. */
2500#define DB_ENV_REGION_INIT 0x00200000 /* DB_REGION_INIT set. */
2501#define DB_ENV_RPCCLIENT 0x00400000 /* DB_RPCCLIENT set. */
2502#define DB_ENV_RPCCLIENT_GIVEN 0x00800000 /* User-supplied RPC client struct */
2503#define DB_ENV_SYSTEM_MEM 0x01000000 /* DB_SYSTEM_MEM set. */
2504#define DB_ENV_THREAD 0x02000000 /* DB_THREAD set. */
2505#define DB_ENV_TIME_NOTGRANTED 0x04000000 /* DB_TIME_NOTGRANTED set. */
2506#define DB_ENV_TXN_NOSYNC 0x08000000 /* DB_TXN_NOSYNC set. */
2507#define DB_ENV_TXN_NOWAIT 0x10000000 /* DB_TXN_NOWAIT set. */
2508#define DB_ENV_TXN_SNAPSHOT 0x20000000 /* DB_TXN_SNAPSHOT set. */
2509#define DB_ENV_TXN_WRITE_NOSYNC 0x40000000 /* DB_TXN_WRITE_NOSYNC set. */
2510#define DB_ENV_YIELDCPU 0x80000000 /* DB_YIELDCPU set. */
2511 uint32_t flags;
2512};
2513
2514#ifndef DB_DBM_HSEARCH
2515#define DB_DBM_HSEARCH 0 /* No historic interfaces by default. */
2516#endif
2517#if DB_DBM_HSEARCH != 0
2518/*******************************************************
2519 * Dbm/Ndbm historic interfaces.
2520 *******************************************************/
2521typedef struct __db DBM;
2522
2523#define DBM_INSERT 0 /* Flags to dbm_store(). */
2524#define DBM_REPLACE 1
2525
2526/*
2527 * The DB support for ndbm(3) always appends this suffix to the
2528 * file name to avoid overwriting the user's original database.
2529 */
2530#define DBM_SUFFIX ".db"
2531
2532#if defined(_XPG4_2)
2533typedef struct {
2534 char *dptr;
2535 size_t dsize;
2536} datum;
2537#else
2538typedef struct {
2539 char *dptr;
2540 int dsize;
2541} datum;
2542#endif
2543
2544/*
2545 * Translate NDBM calls into DB calls so that DB doesn't step on the
2546 * application's name space.
2547 */
2548#define dbm_clearerr(a) __db_ndbm_clearerr(a)
2549#define dbm_close(a) __db_ndbm_close(a)
2550#define dbm_delete(a, b) __db_ndbm_delete(a, b)
2551#define dbm_dirfno(a) __db_ndbm_dirfno(a)
2552#define dbm_error(a) __db_ndbm_error(a)
2553#define dbm_fetch(a, b) __db_ndbm_fetch(a, b)
2554#define dbm_firstkey(a) __db_ndbm_firstkey(a)
2555#define dbm_nextkey(a) __db_ndbm_nextkey(a)
2556#define dbm_open(a, b, c) __db_ndbm_open(a, b, c)
2557#define dbm_pagfno(a) __db_ndbm_pagfno(a)
2558#define dbm_rdonly(a) __db_ndbm_rdonly(a)
2559#define dbm_store(a, b, c, d) \
2560 __db_ndbm_store(a, b, c, d)
2561
2562/*
2563 * Translate DBM calls into DB calls so that DB doesn't step on the
2564 * application's name space.
2565 *
2566 * The global variables dbrdonly, dirf and pagf were not retained when 4BSD
2567 * replaced the dbm interface with ndbm, and are not supported here.
2568 */
2569#define dbminit(a) __db_dbm_init(a)
2570#define dbmclose __db_dbm_close
2571#if !defined(__cplusplus)
2572#define delete(a) __db_dbm_delete(a)
2573#endif
2574#define fetch(a) __db_dbm_fetch(a)
2575#define firstkey __db_dbm_firstkey
2576#define nextkey(a) __db_dbm_nextkey(a)
2577#define store(a, b) __db_dbm_store(a, b)
2578
2579/*******************************************************
2580 * Hsearch historic interface.
2581 *******************************************************/
2582typedef enum {
2583 FIND, ENTER
2584} ACTION;
2585
2586typedef struct entry {
2587 char *key;
2588 char *data;
2589} ENTRY;
2590
2591#define hcreate(a) __db_hcreate(a)
2592#define hdestroy __db_hdestroy
2593#define hsearch(a, b) __db_hsearch(a, b)
2594
2595#endif /* DB_DBM_HSEARCH */
2596
2597#if defined(__cplusplus)
2598}
2599#endif
2600
2601
2602#endif /* !_DB_H_ */
2603
2604/* DO NOT EDIT: automatically built by dist/s_include. */
2605#ifndef _DB_EXT_PROT_IN_
2606#define _DB_EXT_PROT_IN_
2607
2608#if defined(__cplusplus)
2609extern "C" {
2610#endif
2611
2612int db_create __P((DB **, DB_ENV *, uint32_t));
2613char *db_strerror __P((int));
2614int db_env_create __P((DB_ENV **, uint32_t));
2615char *db_version __P((int *, int *, int *));
2616int log_compare __P((const DB_LSN *, const DB_LSN *));
2617int db_env_set_func_close __P((int (*)(int)));
2618int db_env_set_func_dirfree __P((void (*)(char **, int)));
2619int db_env_set_func_dirlist __P((int (*)(const char *, char ***, int *)));
2620int db_env_set_func_exists __P((int (*)(const char *, int *)));
2621int db_env_set_func_free __P((void (*)(void *)));
2622int db_env_set_func_fsync __P((int (*)(int)));
2623int db_env_set_func_ftruncate __P((int (*)(int, off_t)));
2624int db_env_set_func_ioinfo __P((int (*)(const char *, int, uint32_t *, uint32_t *, uint32_t *)));
2625int db_env_set_func_malloc __P((void *(*)(size_t)));
2626int db_env_set_func_map __P((int (*)(char *, size_t, int, int, void **)));
2627int db_env_set_func_pread __P((ssize_t (*)(int, void *, size_t, off_t)));
2628int db_env_set_func_pwrite __P((ssize_t (*)(int, const void *, size_t, off_t)));
2629int db_env_set_func_open __P((int (*)(const char *, int, ...)));
2630int db_env_set_func_read __P((ssize_t (*)(int, void *, size_t)));
2631int db_env_set_func_realloc __P((void *(*)(void *, size_t)));
2632int db_env_set_func_rename __P((int (*)(const char *, const char *)));
2633int db_env_set_func_seek __P((int (*)(int, off_t, int)));
2634int db_env_set_func_sleep __P((int (*)(u_long, u_long)));
2635int db_env_set_func_unlink __P((int (*)(const char *)));
2636int db_env_set_func_unmap __P((int (*)(void *, size_t)));
2637int db_env_set_func_write __P((ssize_t (*)(int, const void *, size_t)));
2638int db_env_set_func_yield __P((int (*)(void)));
2639int db_sequence_create __P((DB_SEQUENCE **, DB *, uint32_t));
2640#if DB_DBM_HSEARCH != 0
2641int __db_ndbm_clearerr __P((DBM *));
2642void __db_ndbm_close __P((DBM *));
2643int __db_ndbm_delete __P((DBM *, datum));
2644int __db_ndbm_dirfno __P((DBM *));
2645int __db_ndbm_error __P((DBM *));
2646datum __db_ndbm_fetch __P((DBM *, datum));
2647datum __db_ndbm_firstkey __P((DBM *));
2648datum __db_ndbm_nextkey __P((DBM *));
2649DBM *__db_ndbm_open __P((const char *, int, int));
2650int __db_ndbm_pagfno __P((DBM *));
2651int __db_ndbm_rdonly __P((DBM *));
2652int __db_ndbm_store __P((DBM *, datum, datum, int));
2653int __db_dbm_close __P((void));
2654int __db_dbm_delete __P((datum));
2655datum __db_dbm_fetch __P((datum));
2656datum __db_dbm_firstkey __P((void));
2657int __db_dbm_init __P((char *));
2658datum __db_dbm_nextkey __P((datum));
2659int __db_dbm_store __P((datum, datum));
2660#endif
2661#if DB_DBM_HSEARCH != 0
2662int __db_hcreate __P((size_t));
2663ENTRY *__db_hsearch __P((ENTRY, ACTION));
2664void __db_hdestroy __P((void));
2665#endif
2666
2667#if defined(__cplusplus)
2668}
2669#endif
2670#endif /* !_DB_EXT_PROT_IN_ */
2671