Warning: That file was not part of the compilation database. It may have many parsing errors.

1/*
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1996, 2013 Oracle and/or its affiliates. All rights reserved.
5 *
6 * $Id$
7 *
8 * db.h include file layout:
9 * General.
10 * Database Environment.
11 * Locking subsystem.
12 * Logging subsystem.
13 * Shared buffer cache (mpool) subsystem.
14 * Transaction subsystem.
15 * Access methods.
16 * Access method cursors.
17 * Dbm/Ndbm, Hsearch historic interfaces.
18 */
19
20#ifndef _DB_H_
21#define _DB_H_
22
23#ifndef __NO_SYSTEM_INCLUDES
24#include <sys/types.h>
25#include <inttypes.h>
26#include <stdint.h>
27#include <stddef.h>
28#include <stdio.h>
29#include <unistd.h>
30#include <pthread.h>
31#endif
32
33
34#if defined(__cplusplus)
35extern "C" {
36#endif
37
38
39#undef __P
40#define __P(protos) protos
41
42/*
43 * Berkeley DB version information.
44 */
45#define DB_VERSION_FAMILY 11
46#define DB_VERSION_RELEASE 2
47#define DB_VERSION_MAJOR 5
48#define DB_VERSION_MINOR 3
49#define DB_VERSION_PATCH 28
50#define DB_VERSION_STRING "Berkeley DB 5.3.28: (September 9, 2013)"
51#define DB_VERSION_FULL_STRING "Berkeley DB 11g Release 2, library version 11.2.5.3.28: (September 9, 2013)"
52
53/*
54 * !!!
55 * Berkeley DB uses specifically sized types. If they're not provided by
56 * the system, typedef them here.
57 *
58 * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
59 * as does BIND and Kerberos, since we don't know for sure what #include
60 * files the user is using.
61 *
62 * !!!
63 * We also provide the standard u_int, u_long etc., if they're not provided
64 * by the system.
65 */
66#ifndef __BIT_TYPES_DEFINED__
67#define __BIT_TYPES_DEFINED__
68
69
70
71
72
73
74
75#endif
76
77
78
79
80
81
82/*
83 * Missing ANSI types.
84 *
85 * uintmax_t --
86 * Largest unsigned type, used to align structures in memory. We don't store
87 * floating point types in structures, so integral types should be sufficient
88 * (and we don't have to worry about systems that store floats in other than
89 * power-of-2 numbers of bytes). Additionally this fixes compilers that rewrite
90 * structure assignments and ANSI C memcpy calls to be in-line instructions
91 * that happen to require alignment.
92 *
93 * uintptr_t --
94 * Unsigned type that's the same size as a pointer. There are places where
95 * DB modifies pointers by discarding the bottom bits to guarantee alignment.
96 * We can't use uintmax_t, it may be larger than the pointer, and compilers
97 * get upset about that. So far we haven't run on any machine where there's
98 * no unsigned type the same size as a pointer -- here's hoping.
99 */
100
101
102
103
104
105
106
107#ifdef HAVE_MIXED_SIZE_ADDRESSING
108typedef u_int32_t db_size_t;
109#else
110typedef size_t db_size_t;
111#endif
112
113#ifdef HAVE_MIXED_SIZE_ADDRESSING
114typedef int32_t db_ssize_t;
115#else
116typedef ssize_t db_ssize_t;
117#endif
118
119
120/*
121 * Sequences are only available on machines with 64-bit integral types.
122 */
123typedef long db_seq_t;
124
125/* Thread and process identification. */
126typedef pthread_t db_threadid_t;
127
128/* Basic types that are exported or quasi-exported. */
129typedef u_int32_t db_pgno_t; /* Page number type. */
130typedef u_int16_t db_indx_t; /* Page offset type. */
131#define DB_MAX_PAGES 0xffffffff /* >= # of pages in a file */
132
133typedef u_int32_t db_recno_t; /* Record number type. */
134#define DB_MAX_RECORDS 0xffffffff /* >= # of records in a tree */
135
136typedef u_int32_t db_timeout_t; /* Type of a timeout. */
137
138/*
139 * Region offsets are the difference between a pointer in a region and the
140 * region's base address. With private environments, both addresses are the
141 * result of calling malloc, and we can't assume anything about what malloc
142 * will return, so region offsets have to be able to hold differences between
143 * arbitrary pointers.
144 */
145typedef db_size_t roff_t;
146
147/*
148 * Forward structure declarations, so we can declare pointers and
149 * applications can get type checking.
150 */
151struct __channel; typedef struct __channel CHANNEL;
152struct __db; typedef struct __db DB;
153struct __db_bt_stat; typedef struct __db_bt_stat DB_BTREE_STAT;
154struct __db_channel; typedef struct __db_channel DB_CHANNEL;
155struct __db_cipher; typedef struct __db_cipher DB_CIPHER;
156struct __db_compact; typedef struct __db_compact DB_COMPACT;
157struct __db_dbt; typedef struct __db_dbt DBT;
158struct __db_distab; typedef struct __db_distab DB_DISTAB;
159struct __db_env; typedef struct __db_env DB_ENV;
160struct __db_h_stat; typedef struct __db_h_stat DB_HASH_STAT;
161struct __db_heap_rid; typedef struct __db_heap_rid DB_HEAP_RID;
162struct __db_heap_stat; typedef struct __db_heap_stat DB_HEAP_STAT;
163struct __db_ilock; typedef struct __db_ilock DB_LOCK_ILOCK;
164struct __db_lock_hstat; typedef struct __db_lock_hstat DB_LOCK_HSTAT;
165struct __db_lock_pstat; typedef struct __db_lock_pstat DB_LOCK_PSTAT;
166struct __db_lock_stat; typedef struct __db_lock_stat DB_LOCK_STAT;
167struct __db_lock_u; typedef struct __db_lock_u DB_LOCK;
168struct __db_locker; typedef struct __db_locker DB_LOCKER;
169struct __db_lockreq; typedef struct __db_lockreq DB_LOCKREQ;
170struct __db_locktab; typedef struct __db_locktab DB_LOCKTAB;
171struct __db_log; typedef struct __db_log DB_LOG;
172struct __db_log_cursor; typedef struct __db_log_cursor DB_LOGC;
173struct __db_log_stat; typedef struct __db_log_stat DB_LOG_STAT;
174struct __db_lsn; typedef struct __db_lsn DB_LSN;
175struct __db_mpool; typedef struct __db_mpool DB_MPOOL;
176struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
177struct __db_mpool_stat; typedef struct __db_mpool_stat DB_MPOOL_STAT;
178struct __db_mpoolfile; typedef struct __db_mpoolfile DB_MPOOLFILE;
179struct __db_mutex_stat; typedef struct __db_mutex_stat DB_MUTEX_STAT;
180struct __db_mutex_t; typedef struct __db_mutex_t DB_MUTEX;
181struct __db_mutexmgr; typedef struct __db_mutexmgr DB_MUTEXMGR;
182struct __db_preplist; typedef struct __db_preplist DB_PREPLIST;
183struct __db_qam_stat; typedef struct __db_qam_stat DB_QUEUE_STAT;
184struct __db_rep; typedef struct __db_rep DB_REP;
185struct __db_rep_stat; typedef struct __db_rep_stat DB_REP_STAT;
186struct __db_repmgr_conn_err;
187 typedef struct __db_repmgr_conn_err DB_REPMGR_CONN_ERR;
188struct __db_repmgr_site;typedef struct __db_repmgr_site DB_REPMGR_SITE;
189struct __db_repmgr_stat;typedef struct __db_repmgr_stat DB_REPMGR_STAT;
190struct __db_seq_record; typedef struct __db_seq_record DB_SEQ_RECORD;
191struct __db_seq_stat; typedef struct __db_seq_stat DB_SEQUENCE_STAT;
192struct __db_site; typedef struct __db_site DB_SITE;
193struct __db_sequence; typedef struct __db_sequence DB_SEQUENCE;
194struct __db_thread_info;typedef struct __db_thread_info DB_THREAD_INFO;
195struct __db_txn; typedef struct __db_txn DB_TXN;
196struct __db_txn_active; typedef struct __db_txn_active DB_TXN_ACTIVE;
197struct __db_txn_stat; typedef struct __db_txn_stat DB_TXN_STAT;
198struct __db_txn_token; typedef struct __db_txn_token DB_TXN_TOKEN;
199struct __db_txnmgr; typedef struct __db_txnmgr DB_TXNMGR;
200struct __dbc; typedef struct __dbc DBC;
201struct __dbc_internal; typedef struct __dbc_internal DBC_INTERNAL;
202struct __env; typedef struct __env ENV;
203struct __fh_t; typedef struct __fh_t DB_FH;
204struct __fname; typedef struct __fname FNAME;
205struct __key_range; typedef struct __key_range DB_KEY_RANGE;
206struct __mpoolfile; typedef struct __mpoolfile MPOOLFILE;
207struct __db_logvrfy_config;
208typedef struct __db_logvrfy_config DB_LOG_VERIFY_CONFIG;
209
210/*
211 * The Berkeley DB API flags are automatically-generated -- the following flag
212 * names are no longer used, but remain for compatibility reasons.
213 */
214#define DB_DEGREE_2 DB_READ_COMMITTED
215#define DB_DIRTY_READ DB_READ_UNCOMMITTED
216#define DB_JOINENV 0x0
217
218/* Key/data structure -- a Data-Base Thang. */
219struct __db_dbt {
220 void *data; /* Key/data */
221 u_int32_t size; /* key/data length */
222
223 u_int32_t ulen; /* RO: length of user buffer. */
224 u_int32_t dlen; /* RO: get/put record length. */
225 u_int32_t doff; /* RO: get/put record offset. */
226
227 void *app_data;
228
229#define DB_DBT_APPMALLOC 0x001 /* Callback allocated memory. */
230#define DB_DBT_BULK 0x002 /* Internal: Insert if duplicate. */
231#define DB_DBT_DUPOK 0x004 /* Internal: Insert if duplicate. */
232#define DB_DBT_ISSET 0x008 /* Lower level calls set value. */
233#define DB_DBT_MALLOC 0x010 /* Return in malloc'd memory. */
234#define DB_DBT_MULTIPLE 0x020 /* References multiple records. */
235#define DB_DBT_PARTIAL 0x040 /* Partial put/get. */
236#define DB_DBT_REALLOC 0x080 /* Return in realloc'd memory. */
237#define DB_DBT_READONLY 0x100 /* Readonly, don't update. */
238#define DB_DBT_STREAMING 0x200 /* Internal: DBT is being streamed. */
239#define DB_DBT_USERCOPY 0x400 /* Use the user-supplied callback. */
240#define DB_DBT_USERMEM 0x800 /* Return in user's memory. */
241 u_int32_t flags;
242};
243
244/*******************************************************
245 * Mutexes.
246 *******************************************************/
247/*
248 * When mixed size addressing is supported mutexes need to be the same size
249 * independent of the process address size is.
250 */
251#ifdef HAVE_MIXED_SIZE_ADDRESSING
252typedef db_size_t db_mutex_t;
253#else
254typedef uintptr_t db_mutex_t;
255#endif
256
257struct __db_mutex_stat { /* SHARED */
258 /* The following fields are maintained in the region's copy. */
259 u_int32_t st_mutex_align; /* Mutex alignment */
260 u_int32_t st_mutex_tas_spins; /* Mutex test-and-set spins */
261 u_int32_t st_mutex_init; /* Initial mutex count */
262 u_int32_t st_mutex_cnt; /* Mutex count */
263 u_int32_t st_mutex_max; /* Mutex max */
264 u_int32_t st_mutex_free; /* Available mutexes */
265 u_int32_t st_mutex_inuse; /* Mutexes in use */
266 u_int32_t st_mutex_inuse_max; /* Maximum mutexes ever in use */
267
268 /* The following fields are filled-in from other places. */
269#ifndef __TEST_DB_NO_STATISTICS
270 uintmax_t st_region_wait; /* Region lock granted after wait. */
271 uintmax_t st_region_nowait; /* Region lock granted without wait. */
272 roff_t st_regsize; /* Region size. */
273 roff_t st_regmax; /* Region max. */
274#endif
275};
276
277/* This is the length of the buffer passed to DB_ENV->thread_id_string() */
278#define DB_THREADID_STRLEN 128
279
280/*******************************************************
281 * Locking.
282 *******************************************************/
283#define DB_LOCKVERSION 1
284
285#define DB_FILE_ID_LEN 20 /* Unique file ID length. */
286
287/*
288 * Deadlock detector modes; used in the DB_ENV structure to configure the
289 * locking subsystem.
290 */
291#define DB_LOCK_NORUN 0
292#define DB_LOCK_DEFAULT 1 /* Default policy. */
293#define DB_LOCK_EXPIRE 2 /* Only expire locks, no detection. */
294#define DB_LOCK_MAXLOCKS 3 /* Select locker with max locks. */
295#define DB_LOCK_MAXWRITE 4 /* Select locker with max writelocks. */
296#define DB_LOCK_MINLOCKS 5 /* Select locker with min locks. */
297#define DB_LOCK_MINWRITE 6 /* Select locker with min writelocks. */
298#define DB_LOCK_OLDEST 7 /* Select oldest locker. */
299#define DB_LOCK_RANDOM 8 /* Select random locker. */
300#define DB_LOCK_YOUNGEST 9 /* Select youngest locker. */
301
302/*
303 * Simple R/W lock modes and for multi-granularity intention locking.
304 *
305 * !!!
306 * These values are NOT random, as they are used as an index into the lock
307 * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
308 * must be == 4.
309 */
310typedef enum {
311 DB_LOCK_NG=0, /* Not granted. */
312 DB_LOCK_READ=1, /* Shared/read. */
313 DB_LOCK_WRITE=2, /* Exclusive/write. */
314 DB_LOCK_WAIT=3, /* Wait for event */
315 DB_LOCK_IWRITE=4, /* Intent exclusive/write. */
316 DB_LOCK_IREAD=5, /* Intent to share/read. */
317 DB_LOCK_IWR=6, /* Intent to read and write. */
318 DB_LOCK_READ_UNCOMMITTED=7, /* Degree 1 isolation. */
319 DB_LOCK_WWRITE=8 /* Was Written. */
320} db_lockmode_t;
321
322/*
323 * Request types.
324 */
325typedef enum {
326 DB_LOCK_DUMP=0, /* Display held locks. */
327 DB_LOCK_GET=1, /* Get the lock. */
328 DB_LOCK_GET_TIMEOUT=2, /* Get lock with a timeout. */
329 DB_LOCK_INHERIT=3, /* Pass locks to parent. */
330 DB_LOCK_PUT=4, /* Release the lock. */
331 DB_LOCK_PUT_ALL=5, /* Release locker's locks. */
332 DB_LOCK_PUT_OBJ=6, /* Release locker's locks on obj. */
333 DB_LOCK_PUT_READ=7, /* Release locker's read locks. */
334 DB_LOCK_TIMEOUT=8, /* Force a txn to timeout. */
335 DB_LOCK_TRADE=9, /* Trade locker ids on a lock. */
336 DB_LOCK_UPGRADE_WRITE=10 /* Upgrade writes for dirty reads. */
337} db_lockop_t;
338
339/*
340 * Status of a lock.
341 */
342typedef enum {
343 DB_LSTAT_ABORTED=1, /* Lock belongs to an aborted txn. */
344 DB_LSTAT_EXPIRED=2, /* Lock has expired. */
345 DB_LSTAT_FREE=3, /* Lock is unallocated. */
346 DB_LSTAT_HELD=4, /* Lock is currently held. */
347 DB_LSTAT_PENDING=5, /* Lock was waiting and has been
348 * promoted; waiting for the owner
349 * to run and upgrade it to held. */
350 DB_LSTAT_WAITING=6 /* Lock is on the wait queue. */
351}db_status_t;
352
353/* Lock statistics structure. */
354struct __db_lock_stat { /* SHARED */
355 u_int32_t st_id; /* Last allocated locker ID. */
356 u_int32_t st_cur_maxid; /* Current maximum unused ID. */
357 u_int32_t st_initlocks; /* Initial number of locks in table. */
358 u_int32_t st_initlockers; /* Initial num of lockers in table. */
359 u_int32_t st_initobjects; /* Initial num of objects in table. */
360 u_int32_t st_locks; /* Current number of locks in table. */
361 u_int32_t st_lockers; /* Current num of lockers in table. */
362 u_int32_t st_objects; /* Current num of objects in table. */
363 u_int32_t st_maxlocks; /* Maximum number of locks in table. */
364 u_int32_t st_maxlockers; /* Maximum num of lockers in table. */
365 u_int32_t st_maxobjects; /* Maximum num of objects in table. */
366 u_int32_t st_partitions; /* number of partitions. */
367 u_int32_t st_tablesize; /* Size of object hash table. */
368 int32_t st_nmodes; /* Number of lock modes. */
369 u_int32_t st_nlockers; /* Current number of lockers. */
370#ifndef __TEST_DB_NO_STATISTICS
371 u_int32_t st_nlocks; /* Current number of locks. */
372 u_int32_t st_maxnlocks; /* Maximum number of locks so far. */
373 u_int32_t st_maxhlocks; /* Maximum number of locks in any bucket. */
374 uintmax_t st_locksteals; /* Number of lock steals so far. */
375 uintmax_t st_maxlsteals; /* Maximum number steals in any partition. */
376 u_int32_t st_maxnlockers; /* Maximum number of lockers so far. */
377 u_int32_t st_nobjects; /* Current number of objects. */
378 u_int32_t st_maxnobjects; /* Maximum number of objects so far. */
379 u_int32_t st_maxhobjects; /* Maximum number of objectsin any bucket. */
380 uintmax_t st_objectsteals; /* Number of objects steals so far. */
381 uintmax_t st_maxosteals; /* Maximum number of steals in any partition. */
382 uintmax_t st_nrequests; /* Number of lock gets. */
383 uintmax_t st_nreleases; /* Number of lock puts. */
384 uintmax_t st_nupgrade; /* Number of lock upgrades. */
385 uintmax_t st_ndowngrade; /* Number of lock downgrades. */
386 uintmax_t st_lock_wait; /* Lock conflicts w/ subsequent wait */
387 uintmax_t st_lock_nowait; /* Lock conflicts w/o subsequent wait */
388 uintmax_t st_ndeadlocks; /* Number of lock deadlocks. */
389 db_timeout_t st_locktimeout; /* Lock timeout. */
390 uintmax_t st_nlocktimeouts; /* Number of lock timeouts. */
391 db_timeout_t st_txntimeout; /* Transaction timeout. */
392 uintmax_t st_ntxntimeouts; /* Number of transaction timeouts. */
393 uintmax_t st_part_wait; /* Partition lock granted after wait. */
394 uintmax_t st_part_nowait; /* Partition lock granted without wait. */
395 uintmax_t st_part_max_wait; /* Max partition lock granted after wait. */
396 uintmax_t st_part_max_nowait; /* Max partition lock granted without wait. */
397 uintmax_t st_objs_wait; /* Object lock granted after wait. */
398 uintmax_t st_objs_nowait; /* Object lock granted without wait. */
399 uintmax_t st_lockers_wait; /* Locker lock granted after wait. */
400 uintmax_t st_lockers_nowait; /* Locker lock granted without wait. */
401 uintmax_t st_region_wait; /* Region lock granted after wait. */
402 uintmax_t st_region_nowait; /* Region lock granted without wait. */
403 u_int32_t st_hash_len; /* Max length of bucket. */
404 roff_t st_regsize; /* Region size. */
405#endif
406};
407
408struct __db_lock_hstat { /* SHARED */
409 uintmax_t st_nrequests; /* Number of lock gets. */
410 uintmax_t st_nreleases; /* Number of lock puts. */
411 uintmax_t st_nupgrade; /* Number of lock upgrades. */
412 uintmax_t st_ndowngrade; /* Number of lock downgrades. */
413 u_int32_t st_nlocks; /* Current number of locks. */
414 u_int32_t st_maxnlocks; /* Maximum number of locks so far. */
415 u_int32_t st_nobjects; /* Current number of objects. */
416 u_int32_t st_maxnobjects; /* Maximum number of objects so far. */
417 uintmax_t st_lock_wait; /* Lock conflicts w/ subsequent wait */
418 uintmax_t st_lock_nowait; /* Lock conflicts w/o subsequent wait */
419 uintmax_t st_nlocktimeouts; /* Number of lock timeouts. */
420 uintmax_t st_ntxntimeouts; /* Number of transaction timeouts. */
421 u_int32_t st_hash_len; /* Max length of bucket. */
422};
423
424struct __db_lock_pstat { /* SHARED */
425 u_int32_t st_nlocks; /* Current number of locks. */
426 u_int32_t st_maxnlocks; /* Maximum number of locks so far. */
427 u_int32_t st_nobjects; /* Current number of objects. */
428 u_int32_t st_maxnobjects; /* Maximum number of objects so far. */
429 uintmax_t st_locksteals; /* Number of lock steals so far. */
430 uintmax_t st_objectsteals; /* Number of objects steals so far. */
431};
432
433/*
434 * DB_LOCK_ILOCK --
435 * Internal DB access method lock.
436 */
437struct __db_ilock { /* SHARED */
438 db_pgno_t pgno; /* Page being locked. */
439 u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
440#define DB_HANDLE_LOCK 1
441#define DB_RECORD_LOCK 2
442#define DB_PAGE_LOCK 3
443#define DB_DATABASE_LOCK 4
444 u_int32_t type; /* Type of lock. */
445};
446
447/*
448 * DB_LOCK --
449 * The structure is allocated by the caller and filled in during a
450 * lock_get request (or a lock_vec/DB_LOCK_GET).
451 */
452struct __db_lock_u { /* SHARED */
453 roff_t off; /* Offset of the lock in the region */
454 u_int32_t ndx; /* Index of the object referenced by
455 * this lock; used for locking. */
456 u_int32_t gen; /* Generation number of this lock. */
457 db_lockmode_t mode; /* mode of this lock. */
458};
459
460/* Lock request structure. */
461struct __db_lockreq {
462 db_lockop_t op; /* Operation. */
463 db_lockmode_t mode; /* Requested mode. */
464 db_timeout_t timeout; /* Time to expire lock. */
465 DBT *obj; /* Object being locked. */
466 DB_LOCK lock; /* Lock returned. */
467};
468
469/*******************************************************
470 * Logging.
471 *******************************************************/
472#define DB_LOGVERSION 19 /* Current log version. */
473#define DB_LOGVERSION_LATCHING 15 /* Log version using latching: db-4.8 */
474#define DB_LOGCHKSUM 12 /* Check sum headers: db-4.5 */
475#define DB_LOGOLDVER 8 /* Oldest version supported: db-4.2 */
476#define DB_LOGMAGIC 0x040988
477
478/*
479 * A DB_LSN has two parts, a fileid which identifies a specific file, and an
480 * offset within that file. The fileid is an unsigned 4-byte quantity that
481 * uniquely identifies a file within the log directory -- currently a simple
482 * counter inside the log. The offset is also an unsigned 4-byte value. The
483 * log manager guarantees the offset is never more than 4 bytes by switching
484 * to a new log file before the maximum length imposed by an unsigned 4-byte
485 * offset is reached.
486 */
487struct __db_lsn { /* SHARED */
488 u_int32_t file; /* File ID. */
489 u_int32_t offset; /* File offset. */
490};
491
492/*
493 * Application-specified log record types start at DB_user_BEGIN, and must not
494 * equal or exceed DB_debug_FLAG.
495 *
496 * DB_debug_FLAG is the high-bit of the u_int32_t that specifies a log record
497 * type. If the flag is set, it's a log record that was logged for debugging
498 * purposes only, even if it reflects a database change -- the change was part
499 * of a non-durable transaction.
500 */
501#define DB_user_BEGIN 10000
502#define DB_debug_FLAG 0x80000000
503
504/*
505 * DB_LOGC --
506 * Log cursor.
507 */
508struct __db_log_cursor {
509 ENV *env; /* Environment */
510
511 DB_FH *fhp; /* File handle. */
512 DB_LSN lsn; /* Cursor: LSN */
513 u_int32_t len; /* Cursor: record length */
514 u_int32_t prev; /* Cursor: previous record's offset */
515
516 DBT dbt; /* Return DBT. */
517 DB_LSN p_lsn; /* Persist LSN. */
518 u_int32_t p_version; /* Persist version. */
519
520 u_int8_t *bp; /* Allocated read buffer. */
521 u_int32_t bp_size; /* Read buffer length in bytes. */
522 u_int32_t bp_rlen; /* Read buffer valid data length. */
523 DB_LSN bp_lsn; /* Read buffer first byte LSN. */
524
525 u_int32_t bp_maxrec; /* Max record length in the log file. */
526
527 /* DB_LOGC PUBLIC HANDLE LIST BEGIN */
528 int (*close) __P((DB_LOGC *, u_int32_t));
529 int (*get) __P((DB_LOGC *, DB_LSN *, DBT *, u_int32_t));
530 int (*version) __P((DB_LOGC *, u_int32_t *, u_int32_t));
531 /* DB_LOGC PUBLIC HANDLE LIST END */
532
533#define DB_LOG_DISK 0x01 /* Log record came from disk. */
534#define DB_LOG_LOCKED 0x02 /* Log region already locked */
535#define DB_LOG_SILENT_ERR 0x04 /* Turn-off error messages. */
536 u_int32_t flags;
537};
538
539/* Log statistics structure. */
540struct __db_log_stat { /* SHARED */
541 u_int32_t st_magic; /* Log file magic number. */
542 u_int32_t st_version; /* Log file version number. */
543 int32_t st_mode; /* Log file permissions mode. */
544 u_int32_t st_lg_bsize; /* Log buffer size. */
545 u_int32_t st_lg_size; /* Log file size. */
546 u_int32_t st_wc_bytes; /* Bytes to log since checkpoint. */
547 u_int32_t st_wc_mbytes; /* Megabytes to log since checkpoint. */
548 u_int32_t st_fileid_init; /* Initial allocation for fileids. */
549#ifndef __TEST_DB_NO_STATISTICS
550 u_int32_t st_nfileid; /* Current number of fileids. */
551 u_int32_t st_maxnfileid; /* Maximum number of fileids used. */
552 uintmax_t st_record; /* Records entered into the log. */
553 u_int32_t st_w_bytes; /* Bytes to log. */
554 u_int32_t st_w_mbytes; /* Megabytes to log. */
555 uintmax_t st_wcount; /* Total I/O writes to the log. */
556 uintmax_t st_wcount_fill; /* Overflow writes to the log. */
557 uintmax_t st_rcount; /* Total I/O reads from the log. */
558 uintmax_t st_scount; /* Total syncs to the log. */
559 uintmax_t st_region_wait; /* Region lock granted after wait. */
560 uintmax_t st_region_nowait; /* Region lock granted without wait. */
561 u_int32_t st_cur_file; /* Current log file number. */
562 u_int32_t st_cur_offset; /* Current log file offset. */
563 u_int32_t st_disk_file; /* Known on disk log file number. */
564 u_int32_t st_disk_offset; /* Known on disk log file offset. */
565 u_int32_t st_maxcommitperflush; /* Max number of commits in a flush. */
566 u_int32_t st_mincommitperflush; /* Min number of commits in a flush. */
567 roff_t st_regsize; /* Region size. */
568#endif
569};
570
571/*
572 * We need to record the first log record of a transaction. For user
573 * defined logging this macro returns the place to put that information,
574 * if it is need in rlsnp, otherwise it leaves it unchanged. We also
575 * need to track the last record of the transaction, this returns the
576 * place to put that info.
577 */
578#define DB_SET_TXN_LSNP(txn, blsnp, llsnp) \
579 ((txn)->set_txn_lsnp(txn, blsnp, llsnp))
580
581/*
582 * Definition of the structure which specifies marshalling of log records.
583 */
584typedef enum {
585 LOGREC_Done,
586 LOGREC_ARG,
587 LOGREC_HDR,
588 LOGREC_DATA,
589 LOGREC_DB,
590 LOGREC_DBOP,
591 LOGREC_DBT,
592 LOGREC_LOCKS,
593 LOGREC_OP,
594 LOGREC_PGDBT,
595 LOGREC_PGDDBT,
596 LOGREC_PGLIST,
597 LOGREC_POINTER,
598 LOGREC_TIME
599} log_rec_type_t;
600
601typedef const struct __log_rec_spec {
602 log_rec_type_t type;
603 u_int32_t offset;
604 const char *name;
605 const char fmt[4];
606} DB_LOG_RECSPEC;
607
608/*
609 * Size of a DBT in a log record.
610 */
611#define LOG_DBT_SIZE(dbt) \
612 (sizeof(u_int32_t) + ((dbt) == NULL ? 0 : (dbt)->size))
613
614/*******************************************************
615 * Shared buffer cache (mpool).
616 *******************************************************/
617/* Priority values for DB_MPOOLFILE->{put,set_priority}. */
618typedef enum {
619 DB_PRIORITY_UNCHANGED=0,
620 DB_PRIORITY_VERY_LOW=1,
621 DB_PRIORITY_LOW=2,
622 DB_PRIORITY_DEFAULT=3,
623 DB_PRIORITY_HIGH=4,
624 DB_PRIORITY_VERY_HIGH=5
625} DB_CACHE_PRIORITY;
626
627/* Per-process DB_MPOOLFILE information. */
628struct __db_mpoolfile {
629 DB_FH *fhp; /* Underlying file handle. */
630
631 /*
632 * !!!
633 * The ref, pinref and q fields are protected by the region lock.
634 */
635 u_int32_t ref; /* Reference count. */
636
637 u_int32_t pinref; /* Pinned block reference count. */
638
639 /*
640 * !!!
641 * Explicit representations of structures from queue.h.
642 * TAILQ_ENTRY(__db_mpoolfile) q;
643 */
644 struct {
645 struct __db_mpoolfile *tqe_next;
646 struct __db_mpoolfile **tqe_prev;
647 } q; /* Linked list of DB_MPOOLFILE's. */
648
649 /*
650 * !!!
651 * The rest of the fields (with the exception of the MP_FLUSH flag)
652 * are not thread-protected, even when they may be modified at any
653 * time by the application. The reason is the DB_MPOOLFILE handle
654 * is single-threaded from the viewpoint of the application, and so
655 * the only fields needing to be thread-protected are those accessed
656 * by checkpoint or sync threads when using DB_MPOOLFILE structures
657 * to flush buffers from the cache.
658 */
659 ENV *env; /* Environment */
660 MPOOLFILE *mfp; /* Underlying MPOOLFILE. */
661
662 u_int32_t clear_len; /* Cleared length on created pages. */
663 u_int8_t /* Unique file ID. */
664 fileid[DB_FILE_ID_LEN];
665 int ftype; /* File type. */
666 int32_t lsn_offset; /* LSN offset in page. */
667 u_int32_t gbytes, bytes; /* Maximum file size. */
668 DBT *pgcookie; /* Byte-string passed to pgin/pgout. */
669 int32_t priority; /* Cache priority. */
670
671 void *addr; /* Address of mmap'd region. */
672 size_t len; /* Length of mmap'd region. */
673
674 u_int32_t config_flags; /* Flags to DB_MPOOLFILE->set_flags. */
675
676 /* DB_MPOOLFILE PUBLIC HANDLE LIST BEGIN */
677 int (*close) __P((DB_MPOOLFILE *, u_int32_t));
678 int (*get)
679 __P((DB_MPOOLFILE *, db_pgno_t *, DB_TXN *, u_int32_t, void *));
680 int (*get_clear_len) __P((DB_MPOOLFILE *, u_int32_t *));
681 int (*get_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
682 int (*get_flags) __P((DB_MPOOLFILE *, u_int32_t *));
683 int (*get_ftype) __P((DB_MPOOLFILE *, int *));
684 int (*get_last_pgno) __P((DB_MPOOLFILE *, db_pgno_t *));
685 int (*get_lsn_offset) __P((DB_MPOOLFILE *, int32_t *));
686 int (*get_maxsize) __P((DB_MPOOLFILE *, u_int32_t *, u_int32_t *));
687 int (*get_pgcookie) __P((DB_MPOOLFILE *, DBT *));
688 int (*get_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY *));
689 int (*open) __P((DB_MPOOLFILE *, const char *, u_int32_t, int, size_t));
690 int (*put) __P((DB_MPOOLFILE *, void *, DB_CACHE_PRIORITY, u_int32_t));
691 int (*set_clear_len) __P((DB_MPOOLFILE *, u_int32_t));
692 int (*set_fileid) __P((DB_MPOOLFILE *, u_int8_t *));
693 int (*set_flags) __P((DB_MPOOLFILE *, u_int32_t, int));
694 int (*set_ftype) __P((DB_MPOOLFILE *, int));
695 int (*set_lsn_offset) __P((DB_MPOOLFILE *, int32_t));
696 int (*set_maxsize) __P((DB_MPOOLFILE *, u_int32_t, u_int32_t));
697 int (*set_pgcookie) __P((DB_MPOOLFILE *, DBT *));
698 int (*set_priority) __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY));
699 int (*sync) __P((DB_MPOOLFILE *));
700 /* DB_MPOOLFILE PUBLIC HANDLE LIST END */
701
702 /*
703 * MP_FILEID_SET, MP_OPEN_CALLED and MP_READONLY do not need to be
704 * thread protected because they are initialized before the file is
705 * linked onto the per-process lists, and never modified.
706 *
707 * MP_FLUSH is thread protected because it is potentially read/set by
708 * multiple threads of control.
709 */
710#define MP_FILEID_SET 0x001 /* Application supplied a file ID. */
711#define MP_FLUSH 0x002 /* Was used to flush a buffer. */
712#define MP_FOR_FLUSH 0x004 /* Was opened to flush a buffer. */
713#define MP_MULTIVERSION 0x008 /* Opened for multiversion access. */
714#define MP_OPEN_CALLED 0x010 /* File opened. */
715#define MP_READONLY 0x020 /* File is readonly. */
716#define MP_DUMMY 0x040 /* File is dummy for __memp_fput. */
717 u_int32_t flags;
718};
719
720/* Mpool statistics structure. */
721struct __db_mpool_stat { /* SHARED */
722 u_int32_t st_gbytes; /* Total cache size: GB. */
723 u_int32_t st_bytes; /* Total cache size: B. */
724 u_int32_t st_ncache; /* Number of cache regions. */
725 u_int32_t st_max_ncache; /* Maximum number of regions. */
726 db_size_t st_mmapsize; /* Maximum file size for mmap. */
727 int32_t st_maxopenfd; /* Maximum number of open fd's. */
728 int32_t st_maxwrite; /* Maximum buffers to write. */
729 db_timeout_t st_maxwrite_sleep; /* Sleep after writing max buffers. */
730 u_int32_t st_pages; /* Total number of pages. */
731#ifndef __TEST_DB_NO_STATISTICS
732 u_int32_t st_map; /* Pages from mapped files. */
733 uintmax_t st_cache_hit; /* Pages found in the cache. */
734 uintmax_t st_cache_miss; /* Pages not found in the cache. */
735 uintmax_t st_page_create; /* Pages created in the cache. */
736 uintmax_t st_page_in; /* Pages read in. */
737 uintmax_t st_page_out; /* Pages written out. */
738 uintmax_t st_ro_evict; /* Clean pages forced from the cache. */
739 uintmax_t st_rw_evict; /* Dirty pages forced from the cache. */
740 uintmax_t st_page_trickle; /* Pages written by memp_trickle. */
741 u_int32_t st_page_clean; /* Clean pages. */
742 u_int32_t st_page_dirty; /* Dirty pages. */
743 u_int32_t st_hash_buckets; /* Number of hash buckets. */
744 u_int32_t st_hash_mutexes; /* Number of hash bucket mutexes. */
745 u_int32_t st_pagesize; /* Assumed page size. */
746 u_int32_t st_hash_searches; /* Total hash chain searches. */
747 u_int32_t st_hash_longest; /* Longest hash chain searched. */
748 uintmax_t st_hash_examined; /* Total hash entries searched. */
749 uintmax_t st_hash_nowait; /* Hash lock granted with nowait. */
750 uintmax_t st_hash_wait; /* Hash lock granted after wait. */
751 uintmax_t st_hash_max_nowait; /* Max hash lock granted with nowait. */
752 uintmax_t st_hash_max_wait; /* Max hash lock granted after wait. */
753 uintmax_t st_region_nowait; /* Region lock granted with nowait. */
754 uintmax_t st_region_wait; /* Region lock granted after wait. */
755 uintmax_t st_mvcc_frozen; /* Buffers frozen. */
756 uintmax_t st_mvcc_thawed; /* Buffers thawed. */
757 uintmax_t st_mvcc_freed; /* Frozen buffers freed. */
758 uintmax_t st_alloc; /* Number of page allocations. */
759 uintmax_t st_alloc_buckets; /* Buckets checked during allocation. */
760 uintmax_t st_alloc_max_buckets;/* Max checked during allocation. */
761 uintmax_t st_alloc_pages; /* Pages checked during allocation. */
762 uintmax_t st_alloc_max_pages; /* Max checked during allocation. */
763 uintmax_t st_io_wait; /* Thread waited on buffer I/O. */
764 uintmax_t st_sync_interrupted; /* Number of times sync interrupted. */
765 roff_t st_regsize; /* Region size. */
766 roff_t st_regmax; /* Region max. */
767#endif
768};
769
770/*
771 * Mpool file statistics structure.
772 * The first fields in this structure must mirror the __db_mpool_fstat_int
773 * structure, since content is mem copied between the two.
774 */
775struct __db_mpool_fstat {
776 u_int32_t st_pagesize; /* Page size. */
777#ifndef __TEST_DB_NO_STATISTICS
778 u_int32_t st_map; /* Pages from mapped files. */
779 uintmax_t st_cache_hit; /* Pages found in the cache. */
780 uintmax_t st_cache_miss; /* Pages not found in the cache. */
781 uintmax_t st_page_create; /* Pages created in the cache. */
782 uintmax_t st_page_in; /* Pages read in. */
783 uintmax_t st_page_out; /* Pages written out. */
784 uintmax_t st_backup_spins; /* Number of spins during a copy. */
785#endif
786 char *file_name; /* File name. */
787};
788
789/*******************************************************
790 * Transactions and recovery.
791 *******************************************************/
792#define DB_TXNVERSION 1
793
794typedef enum {
795 DB_TXN_ABORT=0, /* Public. */
796 DB_TXN_APPLY=1, /* Public. */
797 DB_TXN_BACKWARD_ROLL=3, /* Public. */
798 DB_TXN_FORWARD_ROLL=4, /* Public. */
799 DB_TXN_OPENFILES=5, /* Internal. */
800 DB_TXN_POPENFILES=6, /* Internal. */
801 DB_TXN_PRINT=7, /* Public. */
802 DB_TXN_LOG_VERIFY=8 /* Internal. */
803} db_recops;
804
805/*
806 * BACKWARD_ALLOC is used during the forward pass to pick up any aborted
807 * allocations for files that were created during the forward pass.
808 * The main difference between _ALLOC and _ROLL is that the entry for
809 * the file not exist during the rollforward pass.
810 */
811#define DB_UNDO(op) ((op) == DB_TXN_ABORT || (op) == DB_TXN_BACKWARD_ROLL)
812#define DB_REDO(op) ((op) == DB_TXN_FORWARD_ROLL || (op) == DB_TXN_APPLY)
813
814struct __db_txn {
815 DB_TXNMGR *mgrp; /* Pointer to transaction manager. */
816 DB_TXN *parent; /* Pointer to transaction's parent. */
817 DB_THREAD_INFO *thread_info; /* Pointer to thread information. */
818
819 u_int32_t txnid; /* Unique transaction id. */
820 char *name; /* Transaction name. */
821 DB_LOCKER *locker; /* Locker for this txn. */
822
823 void *td; /* Detail structure within region. */
824 db_timeout_t lock_timeout; /* Timeout for locks for this txn. */
825 void *txn_list; /* Undo information for parent. */
826
827 /*
828 * !!!
829 * Explicit representations of structures from queue.h.
830 * TAILQ_ENTRY(__db_txn) links;
831 */
832 struct {
833 struct __db_txn *tqe_next;
834 struct __db_txn **tqe_prev;
835 } links; /* Links transactions off manager. */
836
837 /*
838 * !!!
839 * Explicit representations of structures from shqueue.h.
840 * SH_TAILQ_ENTRY xa_links;
841 * These links link together transactions that are active in
842 * the same thread of control.
843 */
844 struct {
845 db_ssize_t stqe_next;
846 db_ssize_t stqe_prev;
847 } xa_links; /* Links XA transactions. */
848
849 /*
850 * !!!
851 * Explicit representations of structures from queue.h.
852 * TAILQ_HEAD(__kids, __db_txn) kids;
853 */
854 struct __kids {
855 struct __db_txn *tqh_first;
856 struct __db_txn **tqh_last;
857 } kids;
858
859 /*
860 * !!!
861 * Explicit representations of structures from queue.h.
862 * TAILQ_HEAD(__events, __txn_event) events;
863 */
864 struct {
865 struct __txn_event *tqh_first;
866 struct __txn_event **tqh_last;
867 } events; /* Links deferred events. */
868
869 /*
870 * !!!
871 * Explicit representations of structures from queue.h.
872 * STAILQ_HEAD(__logrec, __txn_logrec) logs;
873 */
874 struct {
875 struct __txn_logrec *stqh_first;
876 struct __txn_logrec **stqh_last;
877 } logs; /* Links in memory log records. */
878
879 /*
880 * !!!
881 * Explicit representations of structures from queue.h.
882 * TAILQ_ENTRY(__db_txn) klinks;
883 */
884 struct {
885 struct __db_txn *tqe_next;
886 struct __db_txn **tqe_prev;
887 } klinks; /* Links of children in parent. */
888
889 /*
890 * !!!
891 * Explicit representations of structures from queue.h.
892 * TAILQ_HEAD(__my_cursors, __dbc) my_cursors;
893 */
894 struct __my_cursors {
895 struct __dbc *tqh_first;
896 struct __dbc **tqh_last;
897 } my_cursors;
898
899 /*
900 * !!!
901 * Explicit representations of structures from queue.h.
902 * TAILQ_HEAD(__femfs, MPOOLFILE) femfs;
903 *
904 * These are DBs involved in file extension in this transaction.
905 */
906 struct __femfs {
907 DB *tqh_first;
908 DB **tqh_last;
909 } femfs;
910
911 DB_TXN_TOKEN *token_buffer; /* User's commit token buffer. */
912 void *api_internal; /* C++ API private. */
913 void *xml_internal; /* XML API private. */
914
915 u_int32_t cursors; /* Number of cursors open for txn */
916
917 /* DB_TXN PUBLIC HANDLE LIST BEGIN */
918 int (*abort) __P((DB_TXN *));
919 int (*commit) __P((DB_TXN *, u_int32_t));
920 int (*discard) __P((DB_TXN *, u_int32_t));
921 int (*get_name) __P((DB_TXN *, const char **));
922 int (*get_priority) __P((DB_TXN *, u_int32_t *));
923 u_int32_t (*id) __P((DB_TXN *));
924 int (*prepare) __P((DB_TXN *, u_int8_t *));
925 int (*set_commit_token) __P((DB_TXN *, DB_TXN_TOKEN *));
926 int (*set_name) __P((DB_TXN *, const char *));
927 int (*set_priority) __P((DB_TXN *, u_int32_t));
928 int (*set_timeout) __P((DB_TXN *, db_timeout_t, u_int32_t));
929 /* DB_TXN PUBLIC HANDLE LIST END */
930
931 /* DB_TXN PRIVATE HANDLE LIST BEGIN */
932 void (*set_txn_lsnp) __P((DB_TXN *txn, DB_LSN **, DB_LSN **));
933 /* DB_TXN PRIVATE HANDLE LIST END */
934
935#define TXN_XA_THREAD_NOTA 0
936#define TXN_XA_THREAD_ASSOCIATED 1
937#define TXN_XA_THREAD_SUSPENDED 2
938#define TXN_XA_THREAD_UNASSOCIATED 3
939 u_int32_t xa_thr_status;
940
941#define TXN_CHILDCOMMIT 0x00001 /* Txn has committed. */
942#define TXN_COMPENSATE 0x00002 /* Compensating transaction. */
943#define TXN_DEADLOCK 0x00004 /* Txn has deadlocked. */
944#define TXN_FAMILY 0x00008 /* Cursors/children are independent. */
945#define TXN_IGNORE_LEASE 0x00010 /* Skip lease check at commit time. */
946#define TXN_INFAMILY 0x00020 /* Part of a transaction family. */
947#define TXN_LOCKTIMEOUT 0x00040 /* Txn has a lock timeout. */
948#define TXN_MALLOC 0x00080 /* Structure allocated by TXN system. */
949#define TXN_NOSYNC 0x00100 /* Do not sync on prepare and commit. */
950#define TXN_NOWAIT 0x00200 /* Do not wait on locks. */
951#define TXN_PRIVATE 0x00400 /* Txn owned by cursor. */
952#define TXN_READONLY 0x00800 /* CDS group handle. */
953#define TXN_READ_COMMITTED 0x01000 /* Txn has degree 2 isolation. */
954#define TXN_READ_UNCOMMITTED 0x02000 /* Txn has degree 1 isolation. */
955#define TXN_RESTORED 0x04000 /* Txn has been restored. */
956#define TXN_SNAPSHOT 0x08000 /* Snapshot Isolation. */
957#define TXN_SYNC 0x10000 /* Write and sync on prepare/commit. */
958#define TXN_WRITE_NOSYNC 0x20000 /* Write only on prepare/commit. */
959#define TXN_BULK 0x40000 /* Enable bulk loading optimization. */
960 u_int32_t flags;
961};
962
963#define TXN_SYNC_FLAGS (TXN_SYNC | TXN_NOSYNC | TXN_WRITE_NOSYNC)
964
965/*
966 * Structure used for two phase commit interface.
967 * We set the size of our global transaction id (gid) to be 128 in order
968 * to match that defined by the XA X/Open standard.
969 */
970#define DB_GID_SIZE 128
971struct __db_preplist {
972 DB_TXN *txn;
973 u_int8_t gid[DB_GID_SIZE];
974};
975
976/* Transaction statistics structure. */
977struct __db_txn_active {
978 u_int32_t txnid; /* Transaction ID */
979 u_int32_t parentid; /* Transaction ID of parent */
980 pid_t pid; /* Process owning txn ID */
981 db_threadid_t tid; /* Thread owning txn ID */
982
983 DB_LSN lsn; /* LSN when transaction began */
984
985 DB_LSN read_lsn; /* Read LSN for MVCC */
986 u_int32_t mvcc_ref; /* MVCC reference count */
987
988 u_int32_t priority; /* Deadlock resolution priority */
989
990#define TXN_ABORTED 1
991#define TXN_COMMITTED 2
992#define TXN_NEED_ABORT 3
993#define TXN_PREPARED 4
994#define TXN_RUNNING 5
995 u_int32_t status; /* Status of the transaction */
996
997#define TXN_XA_ACTIVE 1
998#define TXN_XA_DEADLOCKED 2
999#define TXN_XA_IDLE 3
1000#define TXN_XA_PREPARED 4
1001#define TXN_XA_ROLLEDBACK 5
1002 u_int32_t xa_status; /* XA status */
1003
1004 u_int8_t gid[DB_GID_SIZE]; /* Global transaction ID */
1005 char name[51]; /* 50 bytes of name, nul termination */
1006};
1007
1008struct __db_txn_stat {
1009 u_int32_t st_nrestores; /* number of restored transactions
1010 after recovery. */
1011#ifndef __TEST_DB_NO_STATISTICS
1012 DB_LSN st_last_ckp; /* lsn of the last checkpoint */
1013 time_t st_time_ckp; /* time of last checkpoint */
1014 u_int32_t st_last_txnid; /* last transaction id given out */
1015 u_int32_t st_inittxns; /* inital txns allocated */
1016 u_int32_t st_maxtxns; /* maximum txns possible */
1017 uintmax_t st_naborts; /* number of aborted transactions */
1018 uintmax_t st_nbegins; /* number of begun transactions */
1019 uintmax_t st_ncommits; /* number of committed transactions */
1020 u_int32_t st_nactive; /* number of active transactions */
1021 u_int32_t st_nsnapshot; /* number of snapshot transactions */
1022 u_int32_t st_maxnactive; /* maximum active transactions */
1023 u_int32_t st_maxnsnapshot; /* maximum snapshot transactions */
1024 uintmax_t st_region_wait; /* Region lock granted after wait. */
1025 uintmax_t st_region_nowait; /* Region lock granted without wait. */
1026 roff_t st_regsize; /* Region size. */
1027 DB_TXN_ACTIVE *st_txnarray; /* array of active transactions */
1028#endif
1029};
1030
1031#define DB_TXN_TOKEN_SIZE 20
1032struct __db_txn_token {
1033 u_int8_t buf[DB_TXN_TOKEN_SIZE];
1034};
1035
1036/*******************************************************
1037 * Replication.
1038 *******************************************************/
1039/* Special, out-of-band environment IDs. */
1040#define DB_EID_BROADCAST -1
1041#define DB_EID_INVALID -2
1042#define DB_EID_MASTER -3
1043
1044#define DB_REP_DEFAULT_PRIORITY 100
1045
1046/* Acknowledgement policies; 0 reserved as OOB. */
1047#define DB_REPMGR_ACKS_ALL 1
1048#define DB_REPMGR_ACKS_ALL_AVAILABLE 2
1049#define DB_REPMGR_ACKS_ALL_PEERS 3
1050#define DB_REPMGR_ACKS_NONE 4
1051#define DB_REPMGR_ACKS_ONE 5
1052#define DB_REPMGR_ACKS_ONE_PEER 6
1053#define DB_REPMGR_ACKS_QUORUM 7
1054
1055/* Replication timeout configuration values. */
1056#define DB_REP_ACK_TIMEOUT 1 /* RepMgr acknowledgements. */
1057#define DB_REP_CHECKPOINT_DELAY 2 /* Master checkpoint delay. */
1058#define DB_REP_CONNECTION_RETRY 3 /* RepMgr connections. */
1059#define DB_REP_ELECTION_RETRY 4 /* RepMgr elect retries. */
1060#define DB_REP_ELECTION_TIMEOUT 5 /* Rep normal elections. */
1061#define DB_REP_FULL_ELECTION_TIMEOUT 6 /* Rep full elections. */
1062#define DB_REP_HEARTBEAT_MONITOR 7 /* RepMgr client HB monitor. */
1063#define DB_REP_HEARTBEAT_SEND 8 /* RepMgr master send freq. */
1064#define DB_REP_LEASE_TIMEOUT 9 /* Master leases. */
1065
1066/*
1067 * Event notification types. (Tcl testing interface currently assumes there are
1068 * no more than 32 of these.)
1069 */
1070#define DB_EVENT_PANIC 0
1071#define DB_EVENT_REG_ALIVE 1
1072#define DB_EVENT_REG_PANIC 2
1073#define DB_EVENT_REP_CLIENT 3
1074#define DB_EVENT_REP_CONNECT_BROKEN 4
1075#define DB_EVENT_REP_CONNECT_ESTD 5
1076#define DB_EVENT_REP_CONNECT_TRY_FAILED 6
1077#define DB_EVENT_REP_DUPMASTER 7
1078#define DB_EVENT_REP_ELECTED 8
1079#define DB_EVENT_REP_ELECTION_FAILED 9
1080#define DB_EVENT_REP_INIT_DONE 10
1081#define DB_EVENT_REP_JOIN_FAILURE 11
1082#define DB_EVENT_REP_LOCAL_SITE_REMOVED 12
1083#define DB_EVENT_REP_MASTER 13
1084#define DB_EVENT_REP_MASTER_FAILURE 14
1085#define DB_EVENT_REP_NEWMASTER 15
1086#define DB_EVENT_REP_PERM_FAILED 16
1087#define DB_EVENT_REP_SITE_ADDED 17
1088#define DB_EVENT_REP_SITE_REMOVED 18
1089#define DB_EVENT_REP_STARTUPDONE 19
1090#define DB_EVENT_REP_WOULD_ROLLBACK 20 /* Undocumented; C API only. */
1091#define DB_EVENT_WRITE_FAILED 21
1092#define DB_EVENT_NO_SUCH_EVENT 0xffffffff /* OOB sentinel value */
1093
1094/* Replication Manager site status. */
1095struct __db_repmgr_site {
1096 int eid;
1097 char *host;
1098 u_int port;
1099
1100#define DB_REPMGR_CONNECTED 1
1101#define DB_REPMGR_DISCONNECTED 2
1102 u_int32_t status;
1103
1104#define DB_REPMGR_ISPEER 0x01
1105 u_int32_t flags;
1106};
1107
1108/* Replication statistics. */
1109struct __db_rep_stat { /* SHARED */
1110 /* !!!
1111 * Many replication statistics fields cannot be protected by a mutex
1112 * without an unacceptable performance penalty, since most message
1113 * processing is done without the need to hold a region-wide lock.
1114 * Fields whose comments end with a '+' may be updated without holding
1115 * the replication or log mutexes (as appropriate), and thus may be
1116 * off somewhat (or, on unreasonable architectures under unlucky
1117 * circumstances, garbaged).
1118 */
1119 u_int32_t st_startup_complete; /* Site completed client sync-up. */
1120#ifndef __TEST_DB_NO_STATISTICS
1121 uintmax_t st_log_queued; /* Log records currently queued.+ */
1122 u_int32_t st_status; /* Current replication status. */
1123 DB_LSN st_next_lsn; /* Next LSN to use or expect. */
1124 DB_LSN st_waiting_lsn; /* LSN we're awaiting, if any. */
1125 DB_LSN st_max_perm_lsn; /* Maximum permanent LSN. */
1126 db_pgno_t st_next_pg; /* Next pg we expect. */
1127 db_pgno_t st_waiting_pg; /* pg we're awaiting, if any. */
1128
1129 u_int32_t st_dupmasters; /* # of times a duplicate master
1130 condition was detected.+ */
1131 db_ssize_t st_env_id; /* Current environment ID. */
1132 u_int32_t st_env_priority; /* Current environment priority. */
1133 uintmax_t st_bulk_fills; /* Bulk buffer fills. */
1134 uintmax_t st_bulk_overflows; /* Bulk buffer overflows. */
1135 uintmax_t st_bulk_records; /* Bulk records stored. */
1136 uintmax_t st_bulk_transfers; /* Transfers of bulk buffers. */
1137 uintmax_t st_client_rerequests;/* Number of forced rerequests. */
1138 uintmax_t st_client_svc_req; /* Number of client service requests
1139 received by this client. */
1140 uintmax_t st_client_svc_miss; /* Number of client service requests
1141 missing on this client. */
1142 u_int32_t st_gen; /* Current generation number. */
1143 u_int32_t st_egen; /* Current election gen number. */
1144 uintmax_t st_lease_chk; /* Lease validity checks. */
1145 uintmax_t st_lease_chk_misses; /* Lease checks invalid. */
1146 uintmax_t st_lease_chk_refresh; /* Lease refresh attempts. */
1147 uintmax_t st_lease_sends; /* Lease messages sent live. */
1148
1149 uintmax_t st_log_duplicated; /* Log records received multiply.+ */
1150 uintmax_t st_log_queued_max; /* Max. log records queued at once.+ */
1151 uintmax_t st_log_queued_total; /* Total # of log recs. ever queued.+ */
1152 uintmax_t st_log_records; /* Log records received and put.+ */
1153 uintmax_t st_log_requested; /* Log recs. missed and requested.+ */
1154 db_ssize_t st_master; /* Env. ID of the current master. */
1155 uintmax_t st_master_changes; /* # of times we've switched masters. */
1156 uintmax_t st_msgs_badgen; /* Messages with a bad generation #.+ */
1157 uintmax_t st_msgs_processed; /* Messages received and processed.+ */
1158 uintmax_t st_msgs_recover; /* Messages ignored because this site
1159 was a client in recovery.+ */
1160 uintmax_t st_msgs_send_failures;/* # of failed message sends.+ */
1161 uintmax_t st_msgs_sent; /* # of successful message sends.+ */
1162 uintmax_t st_newsites; /* # of NEWSITE msgs. received.+ */
1163 u_int32_t st_nsites; /* Current number of sites we will
1164 assume during elections. */
1165 uintmax_t st_nthrottles; /* # of times we were throttled. */
1166 uintmax_t st_outdated; /* # of times we detected and returned
1167 an OUTDATED condition.+ */
1168 uintmax_t st_pg_duplicated; /* Pages received multiply.+ */
1169 uintmax_t st_pg_records; /* Pages received and stored.+ */
1170 uintmax_t st_pg_requested; /* Pages missed and requested.+ */
1171 uintmax_t st_txns_applied; /* # of transactions applied.+ */
1172 uintmax_t st_startsync_delayed;/* # of STARTSYNC msgs delayed.+ */
1173
1174 /* Elections generally. */
1175 uintmax_t st_elections; /* # of elections held.+ */
1176 uintmax_t st_elections_won; /* # of elections won by this site.+ */
1177
1178 /* Statistics about an in-progress election. */
1179 db_ssize_t st_election_cur_winner; /* Current front-runner. */
1180 u_int32_t st_election_gen; /* Election generation number. */
1181 u_int32_t st_election_datagen; /* Election data generation number. */
1182 DB_LSN st_election_lsn; /* Max. LSN of current winner. */
1183 u_int32_t st_election_nsites; /* # of "registered voters". */
1184 u_int32_t st_election_nvotes; /* # of "registered voters" needed. */
1185 u_int32_t st_election_priority; /* Current election priority. */
1186 int32_t st_election_status; /* Current election status. */
1187 u_int32_t st_election_tiebreaker;/* Election tiebreaker value. */
1188 u_int32_t st_election_votes; /* Votes received in this round. */
1189 u_int32_t st_election_sec; /* Last election time seconds. */
1190 u_int32_t st_election_usec; /* Last election time useconds. */
1191 u_int32_t st_max_lease_sec; /* Maximum lease timestamp seconds. */
1192 u_int32_t st_max_lease_usec; /* Maximum lease timestamp useconds. */
1193
1194 /* Undocumented statistics only used by the test system. */
1195#ifdef CONFIG_TEST
1196 u_int32_t st_filefail_cleanups; /* # of FILE_FAIL cleanups done. */
1197#endif
1198#endif
1199};
1200
1201/* Replication Manager statistics. */
1202struct __db_repmgr_stat { /* SHARED */
1203 uintmax_t st_perm_failed; /* # of insufficiently ack'ed msgs. */
1204 uintmax_t st_msgs_queued; /* # msgs queued for network delay. */
1205 uintmax_t st_msgs_dropped; /* # msgs discarded due to excessive
1206 queue length. */
1207 uintmax_t st_connection_drop; /* Existing connections dropped. */
1208 uintmax_t st_connect_fail; /* Failed new connection attempts. */
1209 uintmax_t st_elect_threads; /* # of active election threads. */
1210 uintmax_t st_max_elect_threads; /* Max concurrent e-threads ever. */
1211};
1212
1213/* Replication Manager connection error. */
1214struct __db_repmgr_conn_err {
1215 int eid; /* Replication Environment ID. */
1216 int error; /* System networking error code. */
1217};
1218
1219/*******************************************************
1220 * Sequences.
1221 *******************************************************/
1222/*
1223 * The storage record for a sequence.
1224 */
1225struct __db_seq_record {
1226 u_int32_t seq_version; /* Version size/number. */
1227 u_int32_t flags; /* DB_SEQ_XXX Flags. */
1228 db_seq_t seq_value; /* Current value. */
1229 db_seq_t seq_max; /* Max permitted. */
1230 db_seq_t seq_min; /* Min permitted. */
1231};
1232
1233/*
1234 * Handle for a sequence object.
1235 */
1236struct __db_sequence {
1237 DB *seq_dbp; /* DB handle for this sequence. */
1238 db_mutex_t mtx_seq; /* Mutex if sequence is threaded. */
1239 DB_SEQ_RECORD *seq_rp; /* Pointer to current data. */
1240 DB_SEQ_RECORD seq_record; /* Data from DB_SEQUENCE. */
1241 int32_t seq_cache_size; /* Number of values cached. */
1242 db_seq_t seq_last_value; /* Last value cached. */
1243 db_seq_t seq_prev_value; /* Last value returned. */
1244 DBT seq_key; /* DBT pointing to sequence key. */
1245 DBT seq_data; /* DBT pointing to seq_record. */
1246
1247 /* API-private structure: used by C++ and Java. */
1248 void *api_internal;
1249
1250 /* DB_SEQUENCE PUBLIC HANDLE LIST BEGIN */
1251 int (*close) __P((DB_SEQUENCE *, u_int32_t));
1252 int (*get) __P((DB_SEQUENCE *,
1253 DB_TXN *, int32_t, db_seq_t *, u_int32_t));
1254 int (*get_cachesize) __P((DB_SEQUENCE *, int32_t *));
1255 int (*get_db) __P((DB_SEQUENCE *, DB **));
1256 int (*get_flags) __P((DB_SEQUENCE *, u_int32_t *));
1257 int (*get_key) __P((DB_SEQUENCE *, DBT *));
1258 int (*get_range) __P((DB_SEQUENCE *,
1259 db_seq_t *, db_seq_t *));
1260 int (*initial_value) __P((DB_SEQUENCE *, db_seq_t));
1261 int (*open) __P((DB_SEQUENCE *,
1262 DB_TXN *, DBT *, u_int32_t));
1263 int (*remove) __P((DB_SEQUENCE *, DB_TXN *, u_int32_t));
1264 int (*set_cachesize) __P((DB_SEQUENCE *, int32_t));
1265 int (*set_flags) __P((DB_SEQUENCE *, u_int32_t));
1266 int (*set_range) __P((DB_SEQUENCE *, db_seq_t, db_seq_t));
1267 int (*stat) __P((DB_SEQUENCE *,
1268 DB_SEQUENCE_STAT **, u_int32_t));
1269 int (*stat_print) __P((DB_SEQUENCE *, u_int32_t));
1270 /* DB_SEQUENCE PUBLIC HANDLE LIST END */
1271};
1272
1273struct __db_seq_stat { /* SHARED */
1274 uintmax_t st_wait; /* Sequence lock granted w/o wait. */
1275 uintmax_t st_nowait; /* Sequence lock granted after wait. */
1276 db_seq_t st_current; /* Current value in db. */
1277 db_seq_t st_value; /* Current cached value. */
1278 db_seq_t st_last_value; /* Last cached value. */
1279 db_seq_t st_min; /* Minimum value. */
1280 db_seq_t st_max; /* Maximum value. */
1281 int32_t st_cache_size; /* Cache size. */
1282 u_int32_t st_flags; /* Flag value. */
1283};
1284
1285/*******************************************************
1286 * Access methods.
1287 *******************************************************/
1288/*
1289 * Any new methods need to retain the original numbering. The type
1290 * is written in a log record so must be maintained.
1291 */
1292typedef enum {
1293 DB_BTREE=1,
1294 DB_HASH=2,
1295 DB_HEAP=6,
1296 DB_RECNO=3,
1297 DB_QUEUE=4,
1298 DB_UNKNOWN=5 /* Figure it out on open. */
1299} DBTYPE;
1300
1301#define DB_RENAMEMAGIC 0x030800 /* File has been renamed. */
1302
1303#define DB_BTREEVERSION 9 /* Current btree version. */
1304#define DB_BTREEOLDVER 8 /* Oldest btree version supported. */
1305#define DB_BTREEMAGIC 0x053162
1306
1307#define DB_HASHVERSION 9 /* Current hash version. */
1308#define DB_HASHOLDVER 7 /* Oldest hash version supported. */
1309#define DB_HASHMAGIC 0x061561
1310
1311#define DB_HEAPVERSION 1 /* Current heap version. */
1312#define DB_HEAPOLDVER 1 /* Oldest heap version supported. */
1313#define DB_HEAPMAGIC 0x074582
1314
1315#define DB_QAMVERSION 4 /* Current queue version. */
1316#define DB_QAMOLDVER 3 /* Oldest queue version supported. */
1317#define DB_QAMMAGIC 0x042253
1318
1319#define DB_SEQUENCE_VERSION 2 /* Current sequence version. */
1320#define DB_SEQUENCE_OLDVER 1 /* Oldest sequence version supported. */
1321
1322/*
1323 * DB access method and cursor operation values. Each value is an operation
1324 * code to which additional bit flags are added.
1325 */
1326#define DB_AFTER 1 /* Dbc.put */
1327#define DB_APPEND 2 /* Db.put */
1328#define DB_BEFORE 3 /* Dbc.put */
1329#define DB_CONSUME 4 /* Db.get */
1330#define DB_CONSUME_WAIT 5 /* Db.get */
1331#define DB_CURRENT 6 /* Dbc.get, Dbc.put, DbLogc.get */
1332#define DB_FIRST 7 /* Dbc.get, DbLogc->get */
1333#define DB_GET_BOTH 8 /* Db.get, Dbc.get */
1334#define DB_GET_BOTHC 9 /* Dbc.get (internal) */
1335#define DB_GET_BOTH_RANGE 10 /* Db.get, Dbc.get */
1336#define DB_GET_RECNO 11 /* Dbc.get */
1337#define DB_JOIN_ITEM 12 /* Dbc.get; don't do primary lookup */
1338#define DB_KEYFIRST 13 /* Dbc.put */
1339#define DB_KEYLAST 14 /* Dbc.put */
1340#define DB_LAST 15 /* Dbc.get, DbLogc->get */
1341#define DB_NEXT 16 /* Dbc.get, DbLogc->get */
1342#define DB_NEXT_DUP 17 /* Dbc.get */
1343#define DB_NEXT_NODUP 18 /* Dbc.get */
1344#define DB_NODUPDATA 19 /* Db.put, Dbc.put */
1345#define DB_NOOVERWRITE 20 /* Db.put */
1346#define DB_OVERWRITE_DUP 21 /* Dbc.put, Db.put; no DB_KEYEXIST */
1347#define DB_POSITION 22 /* Dbc.dup */
1348#define DB_PREV 23 /* Dbc.get, DbLogc->get */
1349#define DB_PREV_DUP 24 /* Dbc.get */
1350#define DB_PREV_NODUP 25 /* Dbc.get */
1351#define DB_SET 26 /* Dbc.get, DbLogc->get */
1352#define DB_SET_RANGE 27 /* Dbc.get */
1353#define DB_SET_RECNO 28 /* Db.get, Dbc.get */
1354#define DB_UPDATE_SECONDARY 29 /* Dbc.get, Dbc.del (internal) */
1355#define DB_SET_LTE 30 /* Dbc.get (internal) */
1356#define DB_GET_BOTH_LTE 31 /* Dbc.get (internal) */
1357
1358/* This has to change when the max opcode hits 255. */
1359#define DB_OPFLAGS_MASK 0x000000ff /* Mask for operations flags. */
1360
1361/*
1362 * DB (user visible) error return codes.
1363 *
1364 * !!!
1365 * We don't want our error returns to conflict with other packages where
1366 * possible, so pick a base error value that's hopefully not common. We
1367 * document that we own the error name space from -30,800 to -30,999.
1368 */
1369/* DB (public) error return codes. */
1370#define DB_BUFFER_SMALL (-30999)/* User memory too small for return. */
1371#define DB_DONOTINDEX (-30998)/* "Null" return from 2ndary callbk. */
1372#define DB_FOREIGN_CONFLICT (-30997)/* A foreign db constraint triggered. */
1373#define DB_HEAP_FULL (-30996)/* No free space in a heap file. */
1374#define DB_KEYEMPTY (-30995)/* Key/data deleted or never created. */
1375#define DB_KEYEXIST (-30994)/* The key/data pair already exists. */
1376#define DB_LOCK_DEADLOCK (-30993)/* Deadlock. */
1377#define DB_LOCK_NOTGRANTED (-30992)/* Lock unavailable. */
1378#define DB_LOG_BUFFER_FULL (-30991)/* In-memory log buffer full. */
1379#define DB_LOG_VERIFY_BAD (-30990)/* Log verification failed. */
1380#define DB_NOSERVER (-30989)/* Server panic return. */
1381#define DB_NOTFOUND (-30988)/* Key/data pair not found (EOF). */
1382#define DB_OLD_VERSION (-30987)/* Out-of-date version. */
1383#define DB_PAGE_NOTFOUND (-30986)/* Requested page not found. */
1384#define DB_REP_DUPMASTER (-30985)/* There are two masters. */
1385#define DB_REP_HANDLE_DEAD (-30984)/* Rolled back a commit. */
1386#define DB_REP_HOLDELECTION (-30983)/* Time to hold an election. */
1387#define DB_REP_IGNORE (-30982)/* This msg should be ignored.*/
1388#define DB_REP_ISPERM (-30981)/* Cached not written perm written.*/
1389#define DB_REP_JOIN_FAILURE (-30980)/* Unable to join replication group. */
1390#define DB_REP_LEASE_EXPIRED (-30979)/* Master lease has expired. */
1391#define DB_REP_LOCKOUT (-30978)/* API/Replication lockout now. */
1392#define DB_REP_NEWSITE (-30977)/* New site entered system. */
1393#define DB_REP_NOTPERM (-30976)/* Permanent log record not written. */
1394#define DB_REP_UNAVAIL (-30975)/* Site cannot currently be reached. */
1395#define DB_REP_WOULDROLLBACK (-30974)/* UNDOC: rollback inhibited by app. */
1396#define DB_RUNRECOVERY (-30973)/* Panic return. */
1397#define DB_SECONDARY_BAD (-30972)/* Secondary index corrupt. */
1398#define DB_TIMEOUT (-30971)/* Timed out on read consistency. */
1399#define DB_VERIFY_BAD (-30970)/* Verify failed; bad format. */
1400#define DB_VERSION_MISMATCH (-30969)/* Environment version mismatch. */
1401
1402/* DB (private) error return codes. */
1403#define DB_ALREADY_ABORTED (-30899)
1404#define DB_CHKSUM_FAIL (-30898)/* Checksum failed. */
1405#define DB_DELETED (-30897)/* Recovery file marked deleted. */
1406#define DB_EVENT_NOT_HANDLED (-30896)/* Forward event to application. */
1407#define DB_NEEDSPLIT (-30895)/* Page needs to be split. */
1408#define DB_REP_BULKOVF (-30894)/* Rep bulk buffer overflow. */
1409#define DB_REP_LOGREADY (-30893)/* Rep log ready for recovery. */
1410#define DB_REP_NEWMASTER (-30892)/* We have learned of a new master. */
1411#define DB_REP_PAGEDONE (-30891)/* This page was already done. */
1412#define DB_SURPRISE_KID (-30890)/* Child commit where parent
1413 didn't know it was a parent. */
1414#define DB_SWAPBYTES (-30889)/* Database needs byte swapping. */
1415#define DB_TXN_CKP (-30888)/* Encountered ckp record in log. */
1416#define DB_VERIFY_FATAL (-30887)/* DB->verify cannot proceed. */
1417
1418/* Database handle. */
1419struct __db {
1420 /*******************************************************
1421 * Public: owned by the application.
1422 *******************************************************/
1423 u_int32_t pgsize; /* Database logical page size. */
1424 DB_CACHE_PRIORITY priority; /* Database priority in cache. */
1425
1426 /* Callbacks. */
1427 int (*db_append_recno) __P((DB *, DBT *, db_recno_t));
1428 void (*db_feedback) __P((DB *, int, int));
1429 int (*dup_compare) __P((DB *, const DBT *, const DBT *));
1430
1431 void *app_private; /* Application-private handle. */
1432
1433 /*******************************************************
1434 * Private: owned by DB.
1435 *******************************************************/
1436 DB_ENV *dbenv; /* Backing public environment. */
1437 ENV *env; /* Backing private environment. */
1438
1439 DBTYPE type; /* DB access method type. */
1440
1441 DB_MPOOLFILE *mpf; /* Backing buffer pool. */
1442
1443 db_mutex_t mutex; /* Synchronization for free threading */
1444
1445 char *fname, *dname; /* File/database passed to DB->open. */
1446 const char *dirname; /* Directory of DB file. */
1447 u_int32_t open_flags; /* Flags passed to DB->open. */
1448
1449 u_int8_t fileid[DB_FILE_ID_LEN];/* File's unique ID for locking. */
1450
1451 u_int32_t adj_fileid; /* File's unique ID for curs. adj. */
1452
1453#define DB_LOGFILEID_INVALID -1
1454 FNAME *log_filename; /* File's naming info for logging. */
1455
1456 db_pgno_t meta_pgno; /* Meta page number */
1457 DB_LOCKER *locker; /* Locker for handle locking. */
1458 DB_LOCKER *cur_locker; /* Current handle lock holder. */
1459 DB_TXN *cur_txn; /* Opening transaction. */
1460 DB_LOCKER *associate_locker; /* Locker for DB->associate call. */
1461 DB_LOCK handle_lock; /* Lock held on this handle. */
1462
1463 time_t timestamp; /* Handle timestamp for replication. */
1464 u_int32_t fid_gen; /* Rep generation number for fids. */
1465
1466 /*
1467 * Returned data memory for DB->get() and friends.
1468 */
1469 DBT my_rskey; /* Secondary key. */
1470 DBT my_rkey; /* [Primary] key. */
1471 DBT my_rdata; /* Data. */
1472
1473 /*
1474 * !!!
1475 * Some applications use DB but implement their own locking outside of
1476 * DB. If they're using fcntl(2) locking on the underlying database
1477 * file, and we open and close a file descriptor for that file, we will
1478 * discard their locks. The DB_FCNTL_LOCKING flag to DB->open is an
1479 * undocumented interface to support this usage which leaves any file
1480 * descriptors we open until DB->close. This will only work with the
1481 * DB->open interface and simple caches, e.g., creating a transaction
1482 * thread may open/close file descriptors this flag doesn't protect.
1483 * Locking with fcntl(2) on a file that you don't own is a very, very
1484 * unsafe thing to do. 'Nuff said.
1485 */
1486 DB_FH *saved_open_fhp; /* Saved file handle. */
1487
1488 /*
1489 * Linked list of DBP's, linked from the ENV, used to keep track
1490 * of all open db handles for cursor adjustment.
1491 *
1492 * !!!
1493 * Explicit representations of structures from queue.h.
1494 * TAILQ_ENTRY(__db) dblistlinks;
1495 */
1496 struct {
1497 struct __db *tqe_next;
1498 struct __db **tqe_prev;
1499 } dblistlinks;
1500
1501 /*
1502 * Cursor queues.
1503 *
1504 * !!!
1505 * Explicit representations of structures from queue.h.
1506 * TAILQ_HEAD(__cq_fq, __dbc) free_queue;
1507 * TAILQ_HEAD(__cq_aq, __dbc) active_queue;
1508 * TAILQ_HEAD(__cq_jq, __dbc) join_queue;
1509 */
1510 struct __cq_fq {
1511 struct __dbc *tqh_first;
1512 struct __dbc **tqh_last;
1513 } free_queue;
1514 struct __cq_aq {
1515 struct __dbc *tqh_first;
1516 struct __dbc **tqh_last;
1517 } active_queue;
1518 struct __cq_jq {
1519 struct __dbc *tqh_first;
1520 struct __dbc **tqh_last;
1521 } join_queue;
1522
1523 /*
1524 * Secondary index support.
1525 *
1526 * Linked list of secondary indices -- set in the primary.
1527 *
1528 * !!!
1529 * Explicit representations of structures from queue.h.
1530 * LIST_HEAD(s_secondaries, __db);
1531 */
1532 struct {
1533 struct __db *lh_first;
1534 } s_secondaries;
1535
1536 /*
1537 * List entries for secondaries, and reference count of how many
1538 * threads are updating this secondary (see Dbc.put).
1539 *
1540 * !!!
1541 * Note that these are synchronized by the primary's mutex, but
1542 * filled in in the secondaries.
1543 *
1544 * !!!
1545 * Explicit representations of structures from queue.h.
1546 * LIST_ENTRY(__db) s_links;
1547 */
1548 struct {
1549 struct __db *le_next;
1550 struct __db **le_prev;
1551 } s_links;
1552 u_int32_t s_refcnt;
1553
1554 /* Secondary callback and free functions -- set in the secondary. */
1555 int (*s_callback) __P((DB *, const DBT *, const DBT *, DBT *));
1556
1557 /* Reference to primary -- set in the secondary. */
1558 DB *s_primary;
1559
1560#define DB_ASSOC_IMMUTABLE_KEY 0x00000001 /* Secondary key is immutable. */
1561#define DB_ASSOC_CREATE 0x00000002 /* Secondary db populated on open. */
1562
1563 /* Flags passed to associate -- set in the secondary. */
1564 u_int32_t s_assoc_flags;
1565
1566 /*
1567 * Foreign key support.
1568 *
1569 * Linked list of primary dbs -- set in the foreign db
1570 *
1571 * !!!
1572 * Explicit representations of structures from queue.h.
1573 * LIST_HEAD(f_primaries, __db);
1574 */
1575 struct {
1576 struct __db_foreign_info *lh_first;
1577 } f_primaries;
1578
1579 /*
1580 * !!!
1581 * Explicit representations of structures from queue.h.
1582 * TAILQ_ENTRY(__db) felink;
1583 *
1584 * Links in a list of DBs involved in file extension
1585 * during a transaction. These are to be used only while the
1586 * metadata is locked.
1587 */
1588 struct {
1589 struct __db *tqe_next;
1590 struct __db **tqe_prev;
1591 } felink;
1592
1593 /* Reference to foreign -- set in the secondary. */
1594 DB *s_foreign;
1595
1596 /* API-private structure: used by DB 1.85, C++, Java, Perl and Tcl */
1597 void *api_internal;
1598
1599 /* Subsystem-private structure. */
1600 void *bt_internal; /* Btree/Recno access method. */
1601 void *h_internal; /* Hash access method. */
1602 void *heap_internal; /* Heap access method. */
1603 void *p_internal; /* Partition informaiton. */
1604 void *q_internal; /* Queue access method. */
1605
1606 /* DB PUBLIC HANDLE LIST BEGIN */
1607 int (*associate) __P((DB *, DB_TXN *, DB *,
1608 int (*)(DB *, const DBT *, const DBT *, DBT *), u_int32_t));
1609 int (*associate_foreign) __P((DB *, DB *,
1610 int (*)(DB *, const DBT *, DBT *, const DBT *, int *),
1611 u_int32_t));
1612 int (*close) __P((DB *, u_int32_t));
1613 int (*compact) __P((DB *,
1614 DB_TXN *, DBT *, DBT *, DB_COMPACT *, u_int32_t, DBT *));
1615 int (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
1616 int (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
1617 void (*err) __P((DB *, int, const char *, ...));
1618 void (*errx) __P((DB *, const char *, ...));
1619 int (*exists) __P((DB *, DB_TXN *, DBT *, u_int32_t));
1620 int (*fd) __P((DB *, int *));
1621 int (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
1622 int (*get_alloc) __P((DB *, void *(**)(size_t),
1623 void *(**)(void *, size_t), void (**)(void *)));
1624 int (*get_append_recno) __P((DB *, int (**)(DB *, DBT *, db_recno_t)));
1625 int (*get_assoc_flags) __P((DB *, u_int32_t *));
1626 int (*get_bt_compare)
1627 __P((DB *, int (**)(DB *, const DBT *, const DBT *)));
1628 int (*get_bt_compress) __P((DB *,
1629 int (**)(DB *,
1630 const DBT *, const DBT *, const DBT *, const DBT *, DBT *),
1631 int (**)(DB *, const DBT *, const DBT *, DBT *, DBT *, DBT *)));
1632 int (*get_bt_minkey) __P((DB *, u_int32_t *));
1633 int (*get_bt_prefix)
1634 __P((DB *, size_t (**)(DB *, const DBT *, const DBT *)));
1635 int (*get_byteswapped) __P((DB *, int *));
1636 int (*get_cachesize) __P((DB *, u_int32_t *, u_int32_t *, int *));
1637 int (*get_create_dir) __P((DB *, const char **));
1638 int (*get_dbname) __P((DB *, const char **, const char **));
1639 int (*get_dup_compare)
1640 __P((DB *, int (**)(DB *, const DBT *, const DBT *)));
1641 int (*get_encrypt_flags) __P((DB *, u_int32_t *));
1642 DB_ENV *(*get_env) __P((DB *));
1643 void (*get_errcall) __P((DB *,
1644 void (**)(const DB_ENV *, const char *, const char *)));
1645 void (*get_errfile) __P((DB *, FILE **));
1646 void (*get_errpfx) __P((DB *, const char **));
1647 int (*get_feedback) __P((DB *, void (**)(DB *, int, int)));
1648 int (*get_flags) __P((DB *, u_int32_t *));
1649 int (*get_h_compare)
1650 __P((DB *, int (**)(DB *, const DBT *, const DBT *)));
1651 int (*get_h_ffactor) __P((DB *, u_int32_t *));
1652 int (*get_h_hash)
1653 __P((DB *, u_int32_t (**)(DB *, const void *, u_int32_t)));
1654 int (*get_h_nelem) __P((DB *, u_int32_t *));
1655 int (*get_heapsize) __P((DB *, u_int32_t *, u_int32_t *));
1656 int (*get_heap_regionsize) __P((DB *, u_int32_t *));
1657 int (*get_lk_exclusive) __P((DB *, int *, int *));
1658 int (*get_lorder) __P((DB *, int *));
1659 DB_MPOOLFILE *(*get_mpf) __P((DB *));
1660 void (*get_msgcall) __P((DB *,
1661 void (**)(const DB_ENV *, const char *)));
1662 void (*get_msgfile) __P((DB *, FILE **));
1663 int (*get_multiple) __P((DB *));
1664 int (*get_open_flags) __P((DB *, u_int32_t *));
1665 int (*get_pagesize) __P((DB *, u_int32_t *));
1666 int (*get_partition_callback) __P((DB *,
1667 u_int32_t *, u_int32_t (**)(DB *, DBT *key)));
1668 int (*get_partition_dirs) __P((DB *, const char ***));
1669 int (*get_partition_keys) __P((DB *, u_int32_t *, DBT **));
1670 int (*get_priority) __P((DB *, DB_CACHE_PRIORITY *));
1671 int (*get_q_extentsize) __P((DB *, u_int32_t *));
1672 int (*get_re_delim) __P((DB *, int *));
1673 int (*get_re_len) __P((DB *, u_int32_t *));
1674 int (*get_re_pad) __P((DB *, int *));
1675 int (*get_re_source) __P((DB *, const char **));
1676 int (*get_transactional) __P((DB *));
1677 int (*get_type) __P((DB *, DBTYPE *));
1678 int (*join) __P((DB *, DBC **, DBC **, u_int32_t));
1679 int (*key_range)
1680 __P((DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, u_int32_t));
1681 int (*open) __P((DB *,
1682 DB_TXN *, const char *, const char *, DBTYPE, u_int32_t, int));
1683 int (*pget) __P((DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t));
1684 int (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
1685 int (*remove) __P((DB *, const char *, const char *, u_int32_t));
1686 int (*rename) __P((DB *,
1687 const char *, const char *, const char *, u_int32_t));
1688 int (*set_alloc) __P((DB *, void *(*)(size_t),
1689 void *(*)(void *, size_t), void (*)(void *)));
1690 int (*set_append_recno) __P((DB *, int (*)(DB *, DBT *, db_recno_t)));
1691 int (*set_bt_compare)
1692 __P((DB *, int (*)(DB *, const DBT *, const DBT *)));
1693 int (*set_bt_compress) __P((DB *,
1694 int (*)(DB *, const DBT *, const DBT *, const DBT *, const DBT *, DBT *),
1695 int (*)(DB *, const DBT *, const DBT *, DBT *, DBT *, DBT *)));
1696 int (*set_bt_minkey) __P((DB *, u_int32_t));
1697 int (*set_bt_prefix)
1698 __P((DB *, size_t (*)(DB *, const DBT *, const DBT *)));
1699 int (*set_cachesize) __P((DB *, u_int32_t, u_int32_t, int));
1700 int (*set_create_dir) __P((DB *, const char *));
1701 int (*set_dup_compare)
1702 __P((DB *, int (*)(DB *, const DBT *, const DBT *)));
1703 int (*set_encrypt) __P((DB *, const char *, u_int32_t));
1704 void (*set_errcall) __P((DB *,
1705 void (*)(const DB_ENV *, const char *, const char *)));
1706 void (*set_errfile) __P((DB *, FILE *));
1707 void (*set_errpfx) __P((DB *, const char *));
1708 int (*set_feedback) __P((DB *, void (*)(DB *, int, int)));
1709 int (*set_flags) __P((DB *, u_int32_t));
1710 int (*set_h_compare)
1711 __P((DB *, int (*)(DB *, const DBT *, const DBT *)));
1712 int (*set_h_ffactor) __P((DB *, u_int32_t));
1713 int (*set_h_hash)
1714 __P((DB *, u_int32_t (*)(DB *, const void *, u_int32_t)));
1715 int (*set_h_nelem) __P((DB *, u_int32_t));
1716 int (*set_heapsize) __P((DB *, u_int32_t, u_int32_t, u_int32_t));
1717 int (*set_heap_regionsize) __P((DB *, u_int32_t));
1718 int (*set_lk_exclusive) __P((DB *, int));
1719 int (*set_lorder) __P((DB *, int));
1720 void (*set_msgcall) __P((DB *, void (*)(const DB_ENV *, const char *)));
1721 void (*set_msgfile) __P((DB *, FILE *));
1722 int (*set_pagesize) __P((DB *, u_int32_t));
1723 int (*set_paniccall) __P((DB *, void (*)(DB_ENV *, int)));
1724 int (*set_partition) __P((DB *,
1725 u_int32_t, DBT *, u_int32_t (*)(DB *, DBT *key)));
1726 int (*set_partition_dirs) __P((DB *, const char **));
1727 int (*set_priority) __P((DB *, DB_CACHE_PRIORITY));
1728 int (*set_q_extentsize) __P((DB *, u_int32_t));
1729 int (*set_re_delim) __P((DB *, int));
1730 int (*set_re_len) __P((DB *, u_int32_t));
1731 int (*set_re_pad) __P((DB *, int));
1732 int (*set_re_source) __P((DB *, const char *));
1733 int (*sort_multiple) __P((DB *, DBT *, DBT *, u_int32_t));
1734 int (*stat) __P((DB *, DB_TXN *, void *, u_int32_t));
1735 int (*stat_print) __P((DB *, u_int32_t));
1736 int (*sync) __P((DB *, u_int32_t));
1737 int (*truncate) __P((DB *, DB_TXN *, u_int32_t *, u_int32_t));
1738 int (*upgrade) __P((DB *, const char *, u_int32_t));
1739 int (*verify)
1740 __P((DB *, const char *, const char *, FILE *, u_int32_t));
1741 /* DB PUBLIC HANDLE LIST END */
1742
1743 /* DB PRIVATE HANDLE LIST BEGIN */
1744 int (*dump) __P((DB *, const char *,
1745 int (*)(void *, const void *), void *, int, int));
1746 int (*db_am_remove) __P((DB *, DB_THREAD_INFO *,
1747 DB_TXN *, const char *, const char *, u_int32_t));
1748 int (*db_am_rename) __P((DB *, DB_THREAD_INFO *,
1749 DB_TXN *, const char *, const char *, const char *));
1750 /* DB PRIVATE HANDLE LIST END */
1751
1752 /*
1753 * Never called; these are a place to save function pointers
1754 * so that we can undo an associate.
1755 */
1756 int (*stored_get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
1757 int (*stored_close) __P((DB *, u_int32_t));
1758
1759 /* Alternative handle close function, used by C++ API. */
1760 int (*alt_close) __P((DB *, u_int32_t));
1761
1762#define DB_OK_BTREE 0x01
1763#define DB_OK_HASH 0x02
1764#define DB_OK_HEAP 0x04
1765#define DB_OK_QUEUE 0x08
1766#define DB_OK_RECNO 0x10
1767 u_int32_t am_ok; /* Legal AM choices. */
1768
1769 /*
1770 * This field really ought to be an AM_FLAG, but we have
1771 * have run out of bits. If/when we decide to split up
1772 * the flags, we can incorporate it.
1773 */
1774 int preserve_fid; /* Do not free fileid on close. */
1775
1776#define DB_AM_CHKSUM 0x00000001 /* Checksumming */
1777#define DB_AM_COMPENSATE 0x00000002 /* Created by compensating txn */
1778#define DB_AM_COMPRESS 0x00000004 /* Compressed BTree */
1779#define DB_AM_CREATED 0x00000008 /* Database was created upon open */
1780#define DB_AM_CREATED_MSTR 0x00000010 /* Encompassing file was created */
1781#define DB_AM_DBM_ERROR 0x00000020 /* Error in DBM/NDBM database */
1782#define DB_AM_DELIMITER 0x00000040 /* Variable length delimiter set */
1783#define DB_AM_DISCARD 0x00000080 /* Discard any cached pages */
1784#define DB_AM_DUP 0x00000100 /* DB_DUP */
1785#define DB_AM_DUPSORT 0x00000200 /* DB_DUPSORT */
1786#define DB_AM_ENCRYPT 0x00000400 /* Encryption */
1787#define DB_AM_FIXEDLEN 0x00000800 /* Fixed-length records */
1788#define DB_AM_INMEM 0x00001000 /* In-memory; no sync on close */
1789#define DB_AM_INORDER 0x00002000 /* DB_INORDER */
1790#define DB_AM_IN_RENAME 0x00004000 /* File is being renamed */
1791#define DB_AM_NOT_DURABLE 0x00008000 /* Do not log changes */
1792#define DB_AM_OPEN_CALLED 0x00010000 /* DB->open called */
1793#define DB_AM_PAD 0x00020000 /* Fixed-length record pad */
1794#define DB_AM_PARTDB 0x00040000 /* Handle for a database partition */
1795#define DB_AM_PGDEF 0x00080000 /* Page size was defaulted */
1796#define DB_AM_RDONLY 0x00100000 /* Database is readonly */
1797#define DB_AM_READ_UNCOMMITTED 0x00200000 /* Support degree 1 isolation */
1798#define DB_AM_RECNUM 0x00400000 /* DB_RECNUM */
1799#define DB_AM_RECOVER 0x00800000 /* DB opened by recovery routine */
1800#define DB_AM_RENUMBER 0x01000000 /* DB_RENUMBER */
1801#define DB_AM_REVSPLITOFF 0x02000000 /* DB_REVSPLITOFF */
1802#define DB_AM_SECONDARY 0x04000000 /* Database is a secondary index */
1803#define DB_AM_SNAPSHOT 0x08000000 /* DB_SNAPSHOT */
1804#define DB_AM_SUBDB 0x10000000 /* Subdatabases supported */
1805#define DB_AM_SWAP 0x20000000 /* Pages need to be byte-swapped */
1806#define DB_AM_TXN 0x40000000 /* Opened in a transaction */
1807#define DB_AM_VERIFYING 0x80000000 /* DB handle is in the verifier */
1808 u_int32_t orig_flags; /* Flags at open, for refresh */
1809 u_int32_t flags;
1810
1811#define DB2_AM_EXCL 0x00000001 /* Exclusively lock the handle */
1812#define DB2_AM_INTEXCL 0x00000002 /* Internal exclusive lock. */
1813#define DB2_AM_NOWAIT 0x00000004 /* Do not wait for handle lock */
1814 u_int32_t orig_flags2; /* Second flags word; for refresh */
1815 u_int32_t flags2; /* Second flags word */
1816};
1817
1818/*
1819 * Macros for bulk operations. These are only intended for the C API.
1820 * For C++, use DbMultiple*Iterator or DbMultiple*Builder.
1821 *
1822 * Bulk operations store multiple entries into a single DBT structure. The
1823 * following macros assist with creating and reading these Multiple DBTs.
1824 *
1825 * The basic layout for single data items is:
1826 *
1827 * -------------------------------------------------------------------------
1828 * | data1 | ... | dataN | ..... |-1 | dNLen | dNOff | ... | d1Len | d1Off |
1829 * -------------------------------------------------------------------------
1830 *
1831 * For the DB_MULTIPLE_KEY* macros, the items are in key/data pairs, so data1
1832 * would be a key, and data2 its corresponding value (N is always even).
1833 *
1834 * For the DB_MULTIPLE_RECNO* macros, the record number is stored along with
1835 * the len/off pair in the "header" section, and the list is zero terminated
1836 * (since -1 is a valid record number):
1837 *
1838 * --------------------------------------------------------------------------
1839 * | d1 |..| dN |..| 0 | dNLen | dNOff | recnoN |..| d1Len | d1Off | recno1 |
1840 * --------------------------------------------------------------------------
1841 */
1842#define DB_MULTIPLE_INIT(pointer, dbt) \
1843 (pointer = (u_int8_t *)(dbt)->data + \
1844 (dbt)->ulen - sizeof(u_int32_t))
1845
1846#define DB_MULTIPLE_NEXT(pointer, dbt, retdata, retdlen) \
1847 do { \
1848 u_int32_t *__p = (u_int32_t *)(pointer); \
1849 if (*__p == (u_int32_t)-1) { \
1850 retdata = NULL; \
1851 pointer = NULL; \
1852 break; \
1853 } \
1854 retdata = (u_int8_t *)(dbt)->data + *__p--; \
1855 retdlen = *__p--; \
1856 pointer = __p; \
1857 if (retdlen == 0 && retdata == (u_int8_t *)(dbt)->data) \
1858 retdata = NULL; \
1859 } while (0)
1860
1861#define DB_MULTIPLE_KEY_NEXT(pointer, dbt, retkey, retklen, retdata, retdlen) \
1862 do { \
1863 u_int32_t *__p = (u_int32_t *)(pointer); \
1864 if (*__p == (u_int32_t)-1) { \
1865 retdata = NULL; \
1866 retkey = NULL; \
1867 pointer = NULL; \
1868 break; \
1869 } \
1870 retkey = (u_int8_t *)(dbt)->data + *__p--; \
1871 retklen = *__p--; \
1872 retdata = (u_int8_t *)(dbt)->data + *__p--; \
1873 retdlen = *__p--; \
1874 pointer = __p; \
1875 } while (0)
1876
1877#define DB_MULTIPLE_RECNO_NEXT(pointer, dbt, recno, retdata, retdlen) \
1878 do { \
1879 u_int32_t *__p = (u_int32_t *)(pointer); \
1880 if (*__p == (u_int32_t)0) { \
1881 recno = 0; \
1882 retdata = NULL; \
1883 pointer = NULL; \
1884 break; \
1885 } \
1886 recno = *__p--; \
1887 retdata = (u_int8_t *)(dbt)->data + *__p--; \
1888 retdlen = *__p--; \
1889 pointer = __p; \
1890 } while (0)
1891
1892#define DB_MULTIPLE_WRITE_INIT(pointer, dbt) \
1893 do { \
1894 (dbt)->flags |= DB_DBT_BULK; \
1895 pointer = (u_int8_t *)(dbt)->data + \
1896 (dbt)->ulen - sizeof(u_int32_t); \
1897 *(u_int32_t *)(pointer) = (u_int32_t)-1; \
1898 } while (0)
1899
1900#define DB_MULTIPLE_RESERVE_NEXT(pointer, dbt, writedata, writedlen) \
1901 do { \
1902 u_int32_t *__p = (u_int32_t *)(pointer); \
1903 u_int32_t __off = ((pointer) == (u_int8_t *)(dbt)->data +\
1904 (dbt)->ulen - sizeof(u_int32_t)) ? 0 : __p[1] + __p[2];\
1905 if ((u_int8_t *)(dbt)->data + __off + (writedlen) > \
1906 (u_int8_t *)(__p - 2)) \
1907 writedata = NULL; \
1908 else { \
1909 writedata = (u_int8_t *)(dbt)->data + __off; \
1910 __p[0] = __off; \
1911 __p[-1] = (u_int32_t)(writedlen); \
1912 __p[-2] = (u_int32_t)-1; \
1913 pointer = __p - 2; \
1914 } \
1915 } while (0)
1916
1917#define DB_MULTIPLE_WRITE_NEXT(pointer, dbt, writedata, writedlen) \
1918 do { \
1919 void *__destd; \
1920 DB_MULTIPLE_RESERVE_NEXT((pointer), (dbt), \
1921 __destd, (writedlen)); \
1922 if (__destd == NULL) \
1923 pointer = NULL; \
1924 else \
1925 memcpy(__destd, (writedata), (writedlen)); \
1926 } while (0)
1927
1928#define DB_MULTIPLE_KEY_RESERVE_NEXT(pointer, dbt, writekey, writeklen, writedata, writedlen) \
1929 do { \
1930 u_int32_t *__p = (u_int32_t *)(pointer); \
1931 u_int32_t __off = ((pointer) == (u_int8_t *)(dbt)->data +\
1932 (dbt)->ulen - sizeof(u_int32_t)) ? 0 : __p[1] + __p[2];\
1933 if ((u_int8_t *)(dbt)->data + __off + (writeklen) + \
1934 (writedlen) > (u_int8_t *)(__p - 4)) { \
1935 writekey = NULL; \
1936 writedata = NULL; \
1937 } else { \
1938 writekey = (u_int8_t *)(dbt)->data + __off; \
1939 __p[0] = __off; \
1940 __p[-1] = (u_int32_t)(writeklen); \
1941 __p -= 2; \
1942 __off += (u_int32_t)(writeklen); \
1943 writedata = (u_int8_t *)(dbt)->data + __off; \
1944 __p[0] = __off; \
1945 __p[-1] = (u_int32_t)(writedlen); \
1946 __p[-2] = (u_int32_t)-1; \
1947 pointer = __p - 2; \
1948 } \
1949 } while (0)
1950
1951#define DB_MULTIPLE_KEY_WRITE_NEXT(pointer, dbt, writekey, writeklen, writedata, writedlen) \
1952 do { \
1953 void *__destk, *__destd; \
1954 DB_MULTIPLE_KEY_RESERVE_NEXT((pointer), (dbt), \
1955 __destk, (writeklen), __destd, (writedlen)); \
1956 if (__destk == NULL) \
1957 pointer = NULL; \
1958 else { \
1959 memcpy(__destk, (writekey), (writeklen)); \
1960 if (__destd != NULL) \
1961 memcpy(__destd, (writedata), (writedlen));\
1962 } \
1963 } while (0)
1964
1965#define DB_MULTIPLE_RECNO_WRITE_INIT(pointer, dbt) \
1966 do { \
1967 (dbt)->flags |= DB_DBT_BULK; \
1968 pointer = (u_int8_t *)(dbt)->data + \
1969 (dbt)->ulen - sizeof(u_int32_t); \
1970 *(u_int32_t *)(pointer) = 0; \
1971 } while (0)
1972
1973#define DB_MULTIPLE_RECNO_RESERVE_NEXT(pointer, dbt, recno, writedata, writedlen) \
1974 do { \
1975 u_int32_t *__p = (u_int32_t *)(pointer); \
1976 u_int32_t __off = ((pointer) == (u_int8_t *)(dbt)->data +\
1977 (dbt)->ulen - sizeof(u_int32_t)) ? 0 : __p[1] + __p[2]; \
1978 if (((u_int8_t *)(dbt)->data + __off) + (writedlen) > \
1979 (u_int8_t *)(__p - 3)) \
1980 writedata = NULL; \
1981 else { \
1982 writedata = (u_int8_t *)(dbt)->data + __off; \
1983 __p[0] = (u_int32_t)(recno); \
1984 __p[-1] = __off; \
1985 __p[-2] = (u_int32_t)(writedlen); \
1986 __p[-3] = 0; \
1987 pointer = __p - 3; \
1988 } \
1989 } while (0)
1990
1991#define DB_MULTIPLE_RECNO_WRITE_NEXT(pointer, dbt, recno, writedata, writedlen)\
1992 do { \
1993 void *__destd; \
1994 DB_MULTIPLE_RECNO_RESERVE_NEXT((pointer), (dbt), \
1995 (recno), __destd, (writedlen)); \
1996 if (__destd == NULL) \
1997 pointer = NULL; \
1998 else if ((writedlen) != 0) \
1999 memcpy(__destd, (writedata), (writedlen)); \
2000 } while (0)
2001
2002struct __db_heap_rid {
2003 db_pgno_t pgno; /* Page number. */
2004 db_indx_t indx; /* Index in the offset table. */
2005};
2006#define DB_HEAP_RID_SZ (sizeof(db_pgno_t) + sizeof(db_indx_t))
2007
2008/*******************************************************
2009 * Access method cursors.
2010 *******************************************************/
2011struct __dbc {
2012 DB *dbp; /* Backing database */
2013 DB_ENV *dbenv; /* Backing environment */
2014 ENV *env; /* Backing environment */
2015
2016 DB_THREAD_INFO *thread_info; /* Thread that owns this cursor. */
2017 DB_TXN *txn; /* Associated transaction. */
2018 DB_CACHE_PRIORITY priority; /* Priority in cache. */
2019
2020 /*
2021 * Active/free cursor queues.
2022 *
2023 * !!!
2024 * Explicit representations of structures from queue.h.
2025 * TAILQ_ENTRY(__dbc) links;
2026 */
2027 struct {
2028 DBC *tqe_next;
2029 DBC **tqe_prev;
2030 } links;
2031
2032 /*
2033 * Cursor queue of the owning transaction.
2034 *
2035 * !!!
2036 * Explicit representations of structures from queue.h.
2037 * TAILQ_ENTRY(__dbc) txn_cursors;
2038 */
2039 struct {
2040 DBC *tqe_next; /* next element */
2041 DBC **tqe_prev; /* address of previous next element */
2042 } txn_cursors;
2043
2044 /*
2045 * The DBT *'s below are used by the cursor routines to return
2046 * data to the user when DBT flags indicate that DB should manage
2047 * the returned memory. They point at a DBT containing the buffer
2048 * and length that will be used, and "belonging" to the handle that
2049 * should "own" this memory. This may be a "my_*" field of this
2050 * cursor--the default--or it may be the corresponding field of
2051 * another cursor, a DB handle, a join cursor, etc. In general, it
2052 * will be whatever handle the user originally used for the current
2053 * DB interface call.
2054 */
2055 DBT *rskey; /* Returned secondary key. */
2056 DBT *rkey; /* Returned [primary] key. */
2057 DBT *rdata; /* Returned data. */
2058
2059 DBT my_rskey; /* Space for returned secondary key. */
2060 DBT my_rkey; /* Space for returned [primary] key. */
2061 DBT my_rdata; /* Space for returned data. */
2062
2063 DB_LOCKER *lref; /* Reference to default locker. */
2064 DB_LOCKER *locker; /* Locker for this operation. */
2065 DBT lock_dbt; /* DBT referencing lock. */
2066 DB_LOCK_ILOCK lock; /* Object to be locked. */
2067 DB_LOCK mylock; /* CDB lock held on this cursor. */
2068
2069 DBTYPE dbtype; /* Cursor type. */
2070
2071 DBC_INTERNAL *internal; /* Access method private. */
2072
2073 /* DBC PUBLIC HANDLE LIST BEGIN */
2074 int (*close) __P((DBC *));
2075 int (*cmp) __P((DBC *, DBC *, int *, u_int32_t));
2076 int (*count) __P((DBC *, db_recno_t *, u_int32_t));
2077 int (*del) __P((DBC *, u_int32_t));
2078 int (*dup) __P((DBC *, DBC **, u_int32_t));
2079 int (*get) __P((DBC *, DBT *, DBT *, u_int32_t));
2080 int (*get_priority) __P((DBC *, DB_CACHE_PRIORITY *));
2081 int (*pget) __P((DBC *, DBT *, DBT *, DBT *, u_int32_t));
2082 int (*put) __P((DBC *, DBT *, DBT *, u_int32_t));
2083 int (*set_priority) __P((DBC *, DB_CACHE_PRIORITY));
2084 /* DBC PUBLIC HANDLE LIST END */
2085
2086 /* The following are the method names deprecated in the 4.6 release. */
2087 int (*c_close) __P((DBC *));
2088 int (*c_count) __P((DBC *, db_recno_t *, u_int32_t));
2089 int (*c_del) __P((DBC *, u_int32_t));
2090 int (*c_dup) __P((DBC *, DBC **, u_int32_t));
2091 int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
2092 int (*c_pget) __P((DBC *, DBT *, DBT *, DBT *, u_int32_t));
2093 int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
2094
2095 /* DBC PRIVATE HANDLE LIST BEGIN */
2096 int (*am_bulk) __P((DBC *, DBT *, u_int32_t));
2097 int (*am_close) __P((DBC *, db_pgno_t, int *));
2098 int (*am_del) __P((DBC *, u_int32_t));
2099 int (*am_destroy) __P((DBC *));
2100 int (*am_get) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
2101 int (*am_put) __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
2102 int (*am_writelock) __P((DBC *));
2103 /* DBC PRIVATE HANDLE LIST END */
2104
2105/*
2106 * DBC_DONTLOCK and DBC_RECOVER are used during recovery and transaction
2107 * abort. If a transaction is being aborted or recovered then DBC_RECOVER
2108 * will be set and locking and logging will be disabled on this cursor. If
2109 * we are performing a compensating transaction (e.g. free page processing)
2110 * then DB_DONTLOCK will be set to inhibit locking, but logging will still
2111 * be required. DB_DONTLOCK is also used if the whole database is locked.
2112 */
2113#define DBC_ACTIVE 0x00001 /* Cursor in use. */
2114#define DBC_BULK 0x00002 /* Bulk update cursor. */
2115#define DBC_DONTLOCK 0x00004 /* Don't lock on this cursor. */
2116#define DBC_DOWNREV 0x00008 /* Down rev replication master. */
2117#define DBC_DUPLICATE 0x00010 /* Create a duplicate cursor. */
2118#define DBC_ERROR 0x00020 /* Error in this request. */
2119#define DBC_FAMILY 0x00040 /* Part of a locker family. */
2120#define DBC_FROM_DB_GET 0x00080 /* Called from the DB->get() method. */
2121#define DBC_MULTIPLE 0x00100 /* Return Multiple data. */
2122#define DBC_MULTIPLE_KEY 0x00200 /* Return Multiple keys and data. */
2123#define DBC_OPD 0x00400 /* Cursor references off-page dups. */
2124#define DBC_OWN_LID 0x00800 /* Free lock id on destroy. */
2125#define DBC_PARTITIONED 0x01000 /* Cursor for a partitioned db. */
2126#define DBC_READ_COMMITTED 0x02000 /* Cursor has degree 2 isolation. */
2127#define DBC_READ_UNCOMMITTED 0x04000 /* Cursor has degree 1 isolation. */
2128#define DBC_RECOVER 0x08000 /* Recovery cursor; don't log/lock. */
2129#define DBC_RMW 0x10000 /* Acquire write flag in read op. */
2130#define DBC_TRANSIENT 0x20000 /* Cursor is transient. */
2131#define DBC_WAS_READ_COMMITTED 0x40000 /* Cursor holds a read commited lock. */
2132#define DBC_WRITECURSOR 0x80000 /* Cursor may be used to write (CDB). */
2133#define DBC_WRITER 0x100000 /* Cursor immediately writing (CDB). */
2134 u_int32_t flags;
2135};
2136
2137/* Key range statistics structure */
2138struct __key_range {
2139 double less;
2140 double equal;
2141 double greater;
2142};
2143
2144/* Btree/Recno statistics structure. */
2145struct __db_bt_stat { /* SHARED */
2146 u_int32_t bt_magic; /* Magic number. */
2147 u_int32_t bt_version; /* Version number. */
2148 u_int32_t bt_metaflags; /* Metadata flags. */
2149 u_int32_t bt_nkeys; /* Number of unique keys. */
2150 u_int32_t bt_ndata; /* Number of data items. */
2151 u_int32_t bt_pagecnt; /* Page count. */
2152 u_int32_t bt_pagesize; /* Page size. */
2153 u_int32_t bt_minkey; /* Minkey value. */
2154 u_int32_t bt_re_len; /* Fixed-length record length. */
2155 u_int32_t bt_re_pad; /* Fixed-length record pad. */
2156 u_int32_t bt_levels; /* Tree levels. */
2157 u_int32_t bt_int_pg; /* Internal pages. */
2158 u_int32_t bt_leaf_pg; /* Leaf pages. */
2159 u_int32_t bt_dup_pg; /* Duplicate pages. */
2160 u_int32_t bt_over_pg; /* Overflow pages. */
2161 u_int32_t bt_empty_pg; /* Empty pages. */
2162 u_int32_t bt_free; /* Pages on the free list. */
2163 uintmax_t bt_int_pgfree; /* Bytes free in internal pages. */
2164 uintmax_t bt_leaf_pgfree; /* Bytes free in leaf pages. */
2165 uintmax_t bt_dup_pgfree; /* Bytes free in duplicate pages. */
2166 uintmax_t bt_over_pgfree; /* Bytes free in overflow pages. */
2167};
2168
2169struct __db_compact {
2170 /* Input Parameters. */
2171 u_int32_t compact_fillpercent; /* Desired fillfactor: 1-100 */
2172 db_timeout_t compact_timeout; /* Lock timeout. */
2173 u_int32_t compact_pages; /* Max pages to process. */
2174 /* Output Stats. */
2175 u_int32_t compact_empty_buckets; /* Empty hash buckets found. */
2176 u_int32_t compact_pages_free; /* Number of pages freed. */
2177 u_int32_t compact_pages_examine; /* Number of pages examine. */
2178 u_int32_t compact_levels; /* Number of levels removed. */
2179 u_int32_t compact_deadlock; /* Number of deadlocks. */
2180 db_pgno_t compact_pages_truncated; /* Pages truncated to OS. */
2181 /* Internal. */
2182 db_pgno_t compact_truncate; /* Exchange pages above here. */
2183};
2184
2185/* Hash statistics structure. */
2186struct __db_h_stat { /* SHARED */
2187 u_int32_t hash_magic; /* Magic number. */
2188 u_int32_t hash_version; /* Version number. */
2189 u_int32_t hash_metaflags; /* Metadata flags. */
2190 u_int32_t hash_nkeys; /* Number of unique keys. */
2191 u_int32_t hash_ndata; /* Number of data items. */
2192 u_int32_t hash_pagecnt; /* Page count. */
2193 u_int32_t hash_pagesize; /* Page size. */
2194 u_int32_t hash_ffactor; /* Fill factor specified at create. */
2195 u_int32_t hash_buckets; /* Number of hash buckets. */
2196 u_int32_t hash_free; /* Pages on the free list. */
2197 uintmax_t hash_bfree; /* Bytes free on bucket pages. */
2198 u_int32_t hash_bigpages; /* Number of big key/data pages. */
2199 uintmax_t hash_big_bfree; /* Bytes free on big item pages. */
2200 u_int32_t hash_overflows; /* Number of overflow pages. */
2201 uintmax_t hash_ovfl_free; /* Bytes free on ovfl pages. */
2202 u_int32_t hash_dup; /* Number of dup pages. */
2203 uintmax_t hash_dup_free; /* Bytes free on duplicate pages. */
2204};
2205
2206/* Heap statistics structure. */
2207struct __db_heap_stat { /* SHARED */
2208 u_int32_t heap_magic; /* Magic number. */
2209 u_int32_t heap_version; /* Version number. */
2210 u_int32_t heap_metaflags; /* Metadata flags. */
2211 u_int32_t heap_nrecs; /* Number of records. */
2212 u_int32_t heap_pagecnt; /* Page count. */
2213 u_int32_t heap_pagesize; /* Page size. */
2214 u_int32_t heap_nregions; /* Number of regions. */
2215 u_int32_t heap_regionsize; /* Number of pages in a region. */
2216};
2217
2218/* Queue statistics structure. */
2219struct __db_qam_stat { /* SHARED */
2220 u_int32_t qs_magic; /* Magic number. */
2221 u_int32_t qs_version; /* Version number. */
2222 u_int32_t qs_metaflags; /* Metadata flags. */
2223 u_int32_t qs_nkeys; /* Number of unique keys. */
2224 u_int32_t qs_ndata; /* Number of data items. */
2225 u_int32_t qs_pagesize; /* Page size. */
2226 u_int32_t qs_extentsize; /* Pages per extent. */
2227 u_int32_t qs_pages; /* Data pages. */
2228 u_int32_t qs_re_len; /* Fixed-length record length. */
2229 u_int32_t qs_re_pad; /* Fixed-length record pad. */
2230 u_int32_t qs_pgfree; /* Bytes free in data pages. */
2231 u_int32_t qs_first_recno; /* First not deleted record. */
2232 u_int32_t qs_cur_recno; /* Next available record number. */
2233};
2234
2235/*******************************************************
2236 * Environment.
2237 *******************************************************/
2238#define DB_REGION_MAGIC 0x120897 /* Environment magic number. */
2239
2240/*
2241 * Database environment structure.
2242 *
2243 * This is the public database environment handle. The private environment
2244 * handle is the ENV structure. The user owns this structure, the library
2245 * owns the ENV structure. The reason there are two structures is because
2246 * the user's configuration outlives any particular DB_ENV->open call, and
2247 * separate structures allows us to easily discard internal information without
2248 * discarding the user's configuration.
2249 *
2250 * Fields in the DB_ENV structure should normally be set only by application
2251 * DB_ENV handle methods.
2252 */
2253
2254/*
2255 * Memory configuration types.
2256 */
2257typedef enum {
2258 DB_MEM_LOCK=1,
2259 DB_MEM_LOCKOBJECT=2,
2260 DB_MEM_LOCKER=3,
2261 DB_MEM_LOGID=4,
2262 DB_MEM_TRANSACTION=5,
2263 DB_MEM_THREAD=6
2264} DB_MEM_CONFIG;
2265
2266/*
2267 * Backup configuration types.
2268 */
2269typedef enum {
2270 DB_BACKUP_READ_COUNT = 1,
2271 DB_BACKUP_READ_SLEEP = 2,
2272 DB_BACKUP_SIZE = 3,
2273 DB_BACKUP_WRITE_DIRECT = 4
2274} DB_BACKUP_CONFIG;
2275
2276struct __db_env {
2277 ENV *env; /* Linked ENV structure */
2278
2279 /*
2280 * The DB_ENV structure can be used concurrently, so field access is
2281 * protected.
2282 */
2283 db_mutex_t mtx_db_env; /* DB_ENV structure mutex */
2284
2285 /* Error message callback */
2286 void (*db_errcall) __P((const DB_ENV *, const char *, const char *));
2287 FILE *db_errfile; /* Error message file stream */
2288 const char *db_errpfx; /* Error message prefix */
2289
2290 /* Other message callback */
2291 void (*db_msgcall) __P((const DB_ENV *, const char *));
2292 FILE *db_msgfile; /* Other message file stream */
2293
2294 /* Other application callback functions */
2295 int (*app_dispatch) __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
2296 void (*db_event_func) __P((DB_ENV *, u_int32_t, void *));
2297 void (*db_feedback) __P((DB_ENV *, int, int));
2298 void (*db_free) __P((void *));
2299 void (*db_paniccall) __P((DB_ENV *, int));
2300 void *(*db_malloc) __P((size_t));
2301 void *(*db_realloc) __P((void *, size_t));
2302 int (*is_alive) __P((DB_ENV *, pid_t, db_threadid_t, u_int32_t));
2303 void (*thread_id) __P((DB_ENV *, pid_t *, db_threadid_t *));
2304 char *(*thread_id_string) __P((DB_ENV *, pid_t, db_threadid_t, char *));
2305
2306 /* Application specified paths */
2307 char *db_log_dir; /* Database log file directory */
2308 char *db_md_dir; /* Persistent metadata directory */
2309 char *db_tmp_dir; /* Database tmp file directory */
2310
2311 char *db_create_dir; /* Create directory for data files */
2312 char **db_data_dir; /* Database data file directories */
2313 int data_cnt; /* Database data file slots */
2314 int data_next; /* Next database data file slot */
2315
2316 char *intermediate_dir_mode; /* Intermediate directory perms */
2317
2318 long shm_key; /* shmget key */
2319
2320 char *passwd; /* Cryptography support */
2321 size_t passwd_len;
2322
2323 /* Private handle references */
2324 void *app_private; /* Application-private handle */
2325 void *api1_internal; /* C++, Perl API private */
2326 void *api2_internal; /* Java API private */
2327
2328 u_int32_t verbose; /* DB_VERB_XXX flags */
2329
2330 /* Mutex configuration */
2331 u_int32_t mutex_align; /* Mutex alignment */
2332 u_int32_t mutex_cnt; /* Number of mutexes to configure */
2333 u_int32_t mutex_inc; /* Number of mutexes to add */
2334 u_int32_t mutex_max; /* Max number of mutexes */
2335 u_int32_t mutex_tas_spins;/* Test-and-set spin count */
2336
2337 /* Locking configuration */
2338 u_int8_t *lk_conflicts; /* Two dimensional conflict matrix */
2339 int lk_modes; /* Number of lock modes in table */
2340 u_int32_t lk_detect; /* Deadlock detect on all conflicts */
2341 u_int32_t lk_max; /* Maximum number of locks */
2342 u_int32_t lk_max_lockers;/* Maximum number of lockers */
2343 u_int32_t lk_max_objects;/* Maximum number of locked objects */
2344 u_int32_t lk_init; /* Initial number of locks */
2345 u_int32_t lk_init_lockers;/* Initial number of lockers */
2346 u_int32_t lk_init_objects;/* Initial number of locked objects */
2347 u_int32_t lk_partitions ;/* Number of object partitions */
2348 db_timeout_t lk_timeout; /* Lock timeout period */
2349 /* Used during initialization */
2350 u_int32_t locker_t_size; /* Locker hash table size. */
2351 u_int32_t object_t_size; /* Object hash table size. */
2352
2353 /* Logging configuration */
2354 u_int32_t lg_bsize; /* Buffer size */
2355 u_int32_t lg_fileid_init; /* Initial allocation for fname structs */
2356 int lg_filemode; /* Log file permission mode */
2357 u_int32_t lg_regionmax; /* Region size */
2358 u_int32_t lg_size; /* Log file size */
2359 u_int32_t lg_flags; /* Log configuration */
2360
2361 /* Memory pool configuration */
2362 u_int32_t mp_gbytes; /* Cache size: GB */
2363 u_int32_t mp_bytes; /* Cache size: bytes */
2364 u_int32_t mp_max_gbytes; /* Maximum cache size: GB */
2365 u_int32_t mp_max_bytes; /* Maximum cache size: bytes */
2366 size_t mp_mmapsize; /* Maximum file size for mmap */
2367 int mp_maxopenfd; /* Maximum open file descriptors */
2368 int mp_maxwrite; /* Maximum buffers to write */
2369 u_int mp_ncache; /* Initial number of cache regions */
2370 u_int32_t mp_pagesize; /* Average page size */
2371 u_int32_t mp_tablesize; /* Approximate hash table size */
2372 u_int32_t mp_mtxcount; /* Number of mutexs */
2373 /* Sleep after writing max buffers */
2374 db_timeout_t mp_maxwrite_sleep;
2375
2376 /* Transaction configuration */
2377 u_int32_t tx_init; /* Initial number of transactions */
2378 u_int32_t tx_max; /* Maximum number of transactions */
2379 time_t tx_timestamp; /* Recover to specific timestamp */
2380 db_timeout_t tx_timeout; /* Timeout for transactions */
2381
2382 /* Thread tracking configuration */
2383 u_int32_t thr_init; /* Thread count */
2384 u_int32_t thr_max; /* Thread max */
2385 roff_t memory_max; /* Maximum region memory */
2386
2387 /*
2388 * The following fields are not strictly user-owned, but they outlive
2389 * the ENV structure, and so are stored here.
2390 */
2391 DB_FH *registry; /* DB_REGISTER file handle */
2392 u_int32_t registry_off; /*
2393 * Offset of our slot. We can't use
2394 * off_t because its size depends on
2395 * build settings.
2396 */
2397 db_timeout_t envreg_timeout; /* DB_REGISTER wait timeout */
2398
2399#define DB_ENV_AUTO_COMMIT 0x00000001 /* DB_AUTO_COMMIT */
2400#define DB_ENV_CDB_ALLDB 0x00000002 /* CDB environment wide locking */
2401#define DB_ENV_FAILCHK 0x00000004 /* Failchk is running */
2402#define DB_ENV_DIRECT_DB 0x00000008 /* DB_DIRECT_DB set */
2403#define DB_ENV_DSYNC_DB 0x00000010 /* DB_DSYNC_DB set */
2404#define DB_ENV_DATABASE_LOCKING 0x00000020 /* Try database-level locking */
2405#define DB_ENV_MULTIVERSION 0x00000040 /* DB_MULTIVERSION set */
2406#define DB_ENV_NOLOCKING 0x00000080 /* DB_NOLOCKING set */
2407#define DB_ENV_NOMMAP 0x00000100 /* DB_NOMMAP set */
2408#define DB_ENV_NOPANIC 0x00000200 /* Okay if panic set */
2409#define DB_ENV_OVERWRITE 0x00000400 /* DB_OVERWRITE set */
2410#define DB_ENV_REGION_INIT 0x00000800 /* DB_REGION_INIT set */
2411#define DB_ENV_TIME_NOTGRANTED 0x00001000 /* DB_TIME_NOTGRANTED set */
2412#define DB_ENV_TXN_NOSYNC 0x00002000 /* DB_TXN_NOSYNC set */
2413#define DB_ENV_TXN_NOWAIT 0x00004000 /* DB_TXN_NOWAIT set */
2414#define DB_ENV_TXN_SNAPSHOT 0x00008000 /* DB_TXN_SNAPSHOT set */
2415#define DB_ENV_TXN_WRITE_NOSYNC 0x00010000 /* DB_TXN_WRITE_NOSYNC set */
2416#define DB_ENV_YIELDCPU 0x00020000 /* DB_YIELDCPU set */
2417#define DB_ENV_HOTBACKUP 0x00040000 /* DB_HOTBACKUP_IN_PROGRESS set */
2418#define DB_ENV_NOFLUSH 0x00080000 /* DB_NOFLUSH set */
2419 u_int32_t flags;
2420
2421 /* DB_ENV PUBLIC HANDLE LIST BEGIN */
2422 int (*add_data_dir) __P((DB_ENV *, const char *));
2423 int (*backup) __P((DB_ENV *, const char *, u_int32_t));
2424 int (*cdsgroup_begin) __P((DB_ENV *, DB_TXN **));
2425 int (*close) __P((DB_ENV *, u_int32_t));
2426 int (*dbbackup) __P((DB_ENV *, const char *, const char *, u_int32_t));
2427 int (*dbremove) __P((DB_ENV *,
2428 DB_TXN *, const char *, const char *, u_int32_t));
2429 int (*dbrename) __P((DB_ENV *,
2430 DB_TXN *, const char *, const char *, const char *, u_int32_t));
2431 void (*err) __P((const DB_ENV *, int, const char *, ...));
2432 void (*errx) __P((const DB_ENV *, const char *, ...));
2433 int (*failchk) __P((DB_ENV *, u_int32_t));
2434 int (*fileid_reset) __P((DB_ENV *, const char *, u_int32_t));
2435 int (*get_alloc) __P((DB_ENV *, void *(**)(size_t),
2436 void *(**)(void *, size_t), void (**)(void *)));
2437 int (*get_app_dispatch)
2438 __P((DB_ENV *, int (**)(DB_ENV *, DBT *, DB_LSN *, db_recops)));
2439 int (*get_cache_max) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2440 int (*get_cachesize) __P((DB_ENV *, u_int32_t *, u_int32_t *, int *));
2441 int (*get_create_dir) __P((DB_ENV *, const char **));
2442 int (*get_data_dirs) __P((DB_ENV *, const char ***));
2443 int (*get_data_len) __P((DB_ENV *, u_int32_t *));
2444 int (*get_backup_callbacks) __P((DB_ENV *,
2445 int (**)(DB_ENV *, const char *, const char *, void **),
2446 int (**)(DB_ENV *, u_int32_t, u_int32_t, u_int32_t, u_int8_t *, void *),
2447 int (**)(DB_ENV *, const char *, void *)));
2448 int (*get_backup_config) __P((DB_ENV *, DB_BACKUP_CONFIG, u_int32_t *));
2449 int (*get_encrypt_flags) __P((DB_ENV *, u_int32_t *));
2450 void (*get_errcall) __P((DB_ENV *,
2451 void (**)(const DB_ENV *, const char *, const char *)));
2452 void (*get_errfile) __P((DB_ENV *, FILE **));
2453 void (*get_errpfx) __P((DB_ENV *, const char **));
2454 int (*get_flags) __P((DB_ENV *, u_int32_t *));
2455 int (*get_feedback) __P((DB_ENV *, void (**)(DB_ENV *, int, int)));
2456 int (*get_home) __P((DB_ENV *, const char **));
2457 int (*get_intermediate_dir_mode) __P((DB_ENV *, const char **));
2458 int (*get_isalive) __P((DB_ENV *,
2459 int (**)(DB_ENV *, pid_t, db_threadid_t, u_int32_t)));
2460 int (*get_lg_bsize) __P((DB_ENV *, u_int32_t *));
2461 int (*get_lg_dir) __P((DB_ENV *, const char **));
2462 int (*get_lg_filemode) __P((DB_ENV *, int *));
2463 int (*get_lg_max) __P((DB_ENV *, u_int32_t *));
2464 int (*get_lg_regionmax) __P((DB_ENV *, u_int32_t *));
2465 int (*get_lk_conflicts) __P((DB_ENV *, const u_int8_t **, int *));
2466 int (*get_lk_detect) __P((DB_ENV *, u_int32_t *));
2467 int (*get_lk_max_lockers) __P((DB_ENV *, u_int32_t *));
2468 int (*get_lk_max_locks) __P((DB_ENV *, u_int32_t *));
2469 int (*get_lk_max_objects) __P((DB_ENV *, u_int32_t *));
2470 int (*get_lk_partitions) __P((DB_ENV *, u_int32_t *));
2471 int (*get_lk_priority) __P((DB_ENV *, u_int32_t, u_int32_t *));
2472 int (*get_lk_tablesize) __P((DB_ENV *, u_int32_t *));
2473 int (*get_memory_init) __P((DB_ENV *, DB_MEM_CONFIG, u_int32_t *));
2474 int (*get_memory_max) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2475 int (*get_metadata_dir) __P((DB_ENV *, const char **));
2476 int (*get_mp_max_openfd) __P((DB_ENV *, int *));
2477 int (*get_mp_max_write) __P((DB_ENV *, int *, db_timeout_t *));
2478 int (*get_mp_mmapsize) __P((DB_ENV *, size_t *));
2479 int (*get_mp_mtxcount) __P((DB_ENV *, u_int32_t *));
2480 int (*get_mp_pagesize) __P((DB_ENV *, u_int32_t *));
2481 int (*get_mp_tablesize) __P((DB_ENV *, u_int32_t *));
2482 void (*get_msgcall)
2483 __P((DB_ENV *, void (**)(const DB_ENV *, const char *)));
2484 void (*get_msgfile) __P((DB_ENV *, FILE **));
2485 int (*get_open_flags) __P((DB_ENV *, u_int32_t *));
2486 int (*get_shm_key) __P((DB_ENV *, long *));
2487 int (*get_thread_count) __P((DB_ENV *, u_int32_t *));
2488 int (*get_thread_id_fn)
2489 __P((DB_ENV *, void (**)(DB_ENV *, pid_t *, db_threadid_t *)));
2490 int (*get_thread_id_string_fn) __P((DB_ENV *,
2491 char *(**)(DB_ENV *, pid_t, db_threadid_t, char *)));
2492 int (*get_timeout) __P((DB_ENV *, db_timeout_t *, u_int32_t));
2493 int (*get_tmp_dir) __P((DB_ENV *, const char **));
2494 int (*get_tx_max) __P((DB_ENV *, u_int32_t *));
2495 int (*get_tx_timestamp) __P((DB_ENV *, time_t *));
2496 int (*get_verbose) __P((DB_ENV *, u_int32_t, int *));
2497 int (*is_bigendian) __P((void));
2498 int (*lock_detect) __P((DB_ENV *, u_int32_t, u_int32_t, int *));
2499 int (*lock_get) __P((DB_ENV *,
2500 u_int32_t, u_int32_t, DBT *, db_lockmode_t, DB_LOCK *));
2501 int (*lock_id) __P((DB_ENV *, u_int32_t *));
2502 int (*lock_id_free) __P((DB_ENV *, u_int32_t));
2503 int (*lock_put) __P((DB_ENV *, DB_LOCK *));
2504 int (*lock_stat) __P((DB_ENV *, DB_LOCK_STAT **, u_int32_t));
2505 int (*lock_stat_print) __P((DB_ENV *, u_int32_t));
2506 int (*lock_vec) __P((DB_ENV *,
2507 u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
2508 int (*log_archive) __P((DB_ENV *, char **[], u_int32_t));
2509 int (*log_cursor) __P((DB_ENV *, DB_LOGC **, u_int32_t));
2510 int (*log_file) __P((DB_ENV *, const DB_LSN *, char *, size_t));
2511 int (*log_flush) __P((DB_ENV *, const DB_LSN *));
2512 int (*log_get_config) __P((DB_ENV *, u_int32_t, int *));
2513 int (*log_printf) __P((DB_ENV *, DB_TXN *, const char *, ...));
2514 int (*log_put) __P((DB_ENV *, DB_LSN *, const DBT *, u_int32_t));
2515 int (*log_put_record) __P((DB_ENV *, DB *, DB_TXN *, DB_LSN *,
2516 u_int32_t, u_int32_t, u_int32_t, u_int32_t,
2517 DB_LOG_RECSPEC *, ...));
2518 int (*log_read_record) __P((DB_ENV *, DB **,
2519 void *, void *, DB_LOG_RECSPEC *, u_int32_t, void **));
2520 int (*log_set_config) __P((DB_ENV *, u_int32_t, int));
2521 int (*log_stat) __P((DB_ENV *, DB_LOG_STAT **, u_int32_t));
2522 int (*log_stat_print) __P((DB_ENV *, u_int32_t));
2523 int (*log_verify) __P((DB_ENV *, const DB_LOG_VERIFY_CONFIG *));
2524 int (*lsn_reset) __P((DB_ENV *, const char *, u_int32_t));
2525 int (*memp_fcreate) __P((DB_ENV *, DB_MPOOLFILE **, u_int32_t));
2526 int (*memp_register) __P((DB_ENV *, int, int (*)(DB_ENV *, db_pgno_t,
2527 void *, DBT *), int (*)(DB_ENV *, db_pgno_t, void *, DBT *)));
2528 int (*memp_stat) __P((DB_ENV *,
2529 DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, u_int32_t));
2530 int (*memp_stat_print) __P((DB_ENV *, u_int32_t));
2531 int (*memp_sync) __P((DB_ENV *, DB_LSN *));
2532 int (*memp_trickle) __P((DB_ENV *, int, int *));
2533 int (*mutex_alloc) __P((DB_ENV *, u_int32_t, db_mutex_t *));
2534 int (*mutex_free) __P((DB_ENV *, db_mutex_t));
2535 int (*mutex_get_align) __P((DB_ENV *, u_int32_t *));
2536 int (*mutex_get_increment) __P((DB_ENV *, u_int32_t *));
2537 int (*mutex_get_init) __P((DB_ENV *, u_int32_t *));
2538 int (*mutex_get_max) __P((DB_ENV *, u_int32_t *));
2539 int (*mutex_get_tas_spins) __P((DB_ENV *, u_int32_t *));
2540 int (*mutex_lock) __P((DB_ENV *, db_mutex_t));
2541 int (*mutex_set_align) __P((DB_ENV *, u_int32_t));
2542 int (*mutex_set_increment) __P((DB_ENV *, u_int32_t));
2543 int (*mutex_set_init) __P((DB_ENV *, u_int32_t));
2544 int (*mutex_set_max) __P((DB_ENV *, u_int32_t));
2545 int (*mutex_set_tas_spins) __P((DB_ENV *, u_int32_t));
2546 int (*mutex_stat) __P((DB_ENV *, DB_MUTEX_STAT **, u_int32_t));
2547 int (*mutex_stat_print) __P((DB_ENV *, u_int32_t));
2548 int (*mutex_unlock) __P((DB_ENV *, db_mutex_t));
2549 int (*open) __P((DB_ENV *, const char *, u_int32_t, int));
2550 int (*remove) __P((DB_ENV *, const char *, u_int32_t));
2551 int (*rep_elect) __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
2552 int (*rep_flush) __P((DB_ENV *));
2553 int (*rep_get_clockskew) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2554 int (*rep_get_config) __P((DB_ENV *, u_int32_t, int *));
2555 int (*rep_get_limit) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2556 int (*rep_get_nsites) __P((DB_ENV *, u_int32_t *));
2557 int (*rep_get_priority) __P((DB_ENV *, u_int32_t *));
2558 int (*rep_get_request) __P((DB_ENV *, u_int32_t *, u_int32_t *));
2559 int (*rep_get_timeout) __P((DB_ENV *, int, u_int32_t *));
2560 int (*rep_process_message)
2561 __P((DB_ENV *, DBT *, DBT *, int, DB_LSN *));
2562 int (*rep_set_clockskew) __P((DB_ENV *, u_int32_t, u_int32_t));
2563 int (*rep_set_config) __P((DB_ENV *, u_int32_t, int));
2564 int (*rep_set_limit) __P((DB_ENV *, u_int32_t, u_int32_t));
2565 int (*rep_set_nsites) __P((DB_ENV *, u_int32_t));
2566 int (*rep_set_priority) __P((DB_ENV *, u_int32_t));
2567 int (*rep_set_request) __P((DB_ENV *, u_int32_t, u_int32_t));
2568 int (*rep_set_timeout) __P((DB_ENV *, int, db_timeout_t));
2569 int (*rep_set_transport) __P((DB_ENV *, int, int (*)(DB_ENV *,
2570 const DBT *, const DBT *, const DB_LSN *, int, u_int32_t)));
2571 int (*rep_start) __P((DB_ENV *, DBT *, u_int32_t));
2572 int (*rep_stat) __P((DB_ENV *, DB_REP_STAT **, u_int32_t));
2573 int (*rep_stat_print) __P((DB_ENV *, u_int32_t));
2574 int (*rep_sync) __P((DB_ENV *, u_int32_t));
2575 int (*repmgr_channel) __P((DB_ENV *, int, DB_CHANNEL **, u_int32_t));
2576 int (*repmgr_get_ack_policy) __P((DB_ENV *, int *));
2577 int (*repmgr_local_site) __P((DB_ENV *, DB_SITE **));
2578 int (*repmgr_msg_dispatch) __P((DB_ENV *,
2579 void (*)(DB_ENV *, DB_CHANNEL *, DBT *, u_int32_t, u_int32_t),
2580 u_int32_t));
2581 int (*repmgr_set_ack_policy) __P((DB_ENV *, int));
2582 int (*repmgr_site)
2583 __P((DB_ENV *, const char *, u_int, DB_SITE**, u_int32_t));
2584 int (*repmgr_site_by_eid) __P((DB_ENV *, int, DB_SITE**));
2585 int (*repmgr_site_list) __P((DB_ENV *, u_int *, DB_REPMGR_SITE **));
2586 int (*repmgr_start) __P((DB_ENV *, int, u_int32_t));
2587 int (*repmgr_stat) __P((DB_ENV *, DB_REPMGR_STAT **, u_int32_t));
2588 int (*repmgr_stat_print) __P((DB_ENV *, u_int32_t));
2589 int (*set_alloc) __P((DB_ENV *, void *(*)(size_t),
2590 void *(*)(void *, size_t), void (*)(void *)));
2591 int (*set_app_dispatch)
2592 __P((DB_ENV *, int (*)(DB_ENV *, DBT *, DB_LSN *, db_recops)));
2593 int (*set_cache_max) __P((DB_ENV *, u_int32_t, u_int32_t));
2594 int (*set_cachesize) __P((DB_ENV *, u_int32_t, u_int32_t, int));
2595 int (*set_create_dir) __P((DB_ENV *, const char *));
2596 int (*set_data_dir) __P((DB_ENV *, const char *));
2597 int (*set_data_len) __P((DB_ENV *, u_int32_t));
2598 int (*set_backup_callbacks) __P((DB_ENV *,
2599 int (*)(DB_ENV *, const char *, const char *, void **),
2600 int (*)(DB_ENV *, u_int32_t,
2601 u_int32_t, u_int32_t, u_int8_t *, void *),
2602 int (*)(DB_ENV *, const char *, void *)));
2603 int (*set_backup_config) __P((DB_ENV *, DB_BACKUP_CONFIG, u_int32_t));
2604 int (*set_encrypt) __P((DB_ENV *, const char *, u_int32_t));
2605 void (*set_errcall) __P((DB_ENV *,
2606 void (*)(const DB_ENV *, const char *, const char *)));
2607 void (*set_errfile) __P((DB_ENV *, FILE *));
2608 void (*set_errpfx) __P((DB_ENV *, const char *));
2609 int (*set_event_notify)
2610 __P((DB_ENV *, void (*)(DB_ENV *, u_int32_t, void *)));
2611 int (*set_feedback) __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
2612 int (*set_flags) __P((DB_ENV *, u_int32_t, int));
2613 int (*set_intermediate_dir_mode) __P((DB_ENV *, const char *));
2614 int (*set_isalive) __P((DB_ENV *,
2615 int (*)(DB_ENV *, pid_t, db_threadid_t, u_int32_t)));
2616 int (*set_lg_bsize) __P((DB_ENV *, u_int32_t));
2617 int (*set_lg_dir) __P((DB_ENV *, const char *));
2618 int (*set_lg_filemode) __P((DB_ENV *, int));
2619 int (*set_lg_max) __P((DB_ENV *, u_int32_t));
2620 int (*set_lg_regionmax) __P((DB_ENV *, u_int32_t));
2621 int (*set_lk_conflicts) __P((DB_ENV *, u_int8_t *, int));
2622 int (*set_lk_detect) __P((DB_ENV *, u_int32_t));
2623 int (*set_lk_max_lockers) __P((DB_ENV *, u_int32_t));
2624 int (*set_lk_max_locks) __P((DB_ENV *, u_int32_t));
2625 int (*set_lk_max_objects) __P((DB_ENV *, u_int32_t));
2626 int (*set_lk_partitions) __P((DB_ENV *, u_int32_t));
2627 int (*set_lk_priority) __P((DB_ENV *, u_int32_t, u_int32_t));
2628 int (*set_lk_tablesize) __P((DB_ENV *, u_int32_t));
2629 int (*set_memory_init) __P((DB_ENV *, DB_MEM_CONFIG, u_int32_t));
2630 int (*set_memory_max) __P((DB_ENV *, u_int32_t, u_int32_t));
2631 int (*set_metadata_dir) __P((DB_ENV *, const char *));
2632 int (*set_mp_max_openfd) __P((DB_ENV *, int));
2633 int (*set_mp_max_write) __P((DB_ENV *, int, db_timeout_t));
2634 int (*set_mp_mmapsize) __P((DB_ENV *, size_t));
2635 int (*set_mp_mtxcount) __P((DB_ENV *, u_int32_t));
2636 int (*set_mp_pagesize) __P((DB_ENV *, u_int32_t));
2637 int (*set_mp_tablesize) __P((DB_ENV *, u_int32_t));
2638 void (*set_msgcall)
2639 __P((DB_ENV *, void (*)(const DB_ENV *, const char *)));
2640 void (*set_msgfile) __P((DB_ENV *, FILE *));
2641 int (*set_paniccall) __P((DB_ENV *, void (*)(DB_ENV *, int)));
2642 int (*set_shm_key) __P((DB_ENV *, long));
2643 int (*set_thread_count) __P((DB_ENV *, u_int32_t));
2644 int (*set_thread_id)
2645 __P((DB_ENV *, void (*)(DB_ENV *, pid_t *, db_threadid_t *)));
2646 int (*set_thread_id_string) __P((DB_ENV *,
2647 char *(*)(DB_ENV *, pid_t, db_threadid_t, char *)));
2648 int (*set_timeout) __P((DB_ENV *, db_timeout_t, u_int32_t));
2649 int (*set_tmp_dir) __P((DB_ENV *, const char *));
2650 int (*set_tx_max) __P((DB_ENV *, u_int32_t));
2651 int (*set_tx_timestamp) __P((DB_ENV *, time_t *));
2652 int (*set_verbose) __P((DB_ENV *, u_int32_t, int));
2653 int (*txn_applied) __P((DB_ENV *,
2654 DB_TXN_TOKEN *, db_timeout_t, u_int32_t));
2655 int (*stat_print) __P((DB_ENV *, u_int32_t));
2656 int (*txn_begin) __P((DB_ENV *, DB_TXN *, DB_TXN **, u_int32_t));
2657 int (*txn_checkpoint) __P((DB_ENV *, u_int32_t, u_int32_t, u_int32_t));
2658 int (*txn_recover) __P((DB_ENV *,
2659 DB_PREPLIST *, long, long *, u_int32_t));
2660 int (*txn_stat) __P((DB_ENV *, DB_TXN_STAT **, u_int32_t));
2661 int (*txn_stat_print) __P((DB_ENV *, u_int32_t));
2662 /* DB_ENV PUBLIC HANDLE LIST END */
2663
2664 /* DB_ENV PRIVATE HANDLE LIST BEGIN */
2665 int (*prdbt) __P((DBT *, int,
2666 const char *, void *, int (*)(void *, const void *), int, int));
2667 /* DB_ENV PRIVATE HANDLE LIST END */
2668};
2669
2670/*
2671 * Dispatch structure for recovery, log verification and print routines. Since
2672 * internal and external routines take different arguments (ENV versus DB_ENV),
2673 * we need something more elaborate than a single pointer and size.
2674 */
2675struct __db_distab {
2676 int (**int_dispatch) __P((ENV *, DBT *, DB_LSN *, db_recops, void *));
2677 size_t int_size;
2678 int (**ext_dispatch) __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
2679 size_t ext_size;
2680};
2681
2682/*
2683 * Log verification configuration structure.
2684 */
2685struct __db_logvrfy_config {
2686 int continue_after_fail, verbose;
2687 u_int32_t cachesize;
2688 const char *temp_envhome;
2689 const char *dbfile, *dbname;
2690 DB_LSN start_lsn, end_lsn;
2691 time_t start_time, end_time;
2692};
2693
2694struct __db_channel {
2695 CHANNEL *channel; /* Pointer to internal state details. */
2696 int eid; /* Env. ID passed in constructor. */
2697 db_timeout_t timeout;
2698
2699 /* DB_CHANNEL PUBLIC HANDLE LIST BEGIN */
2700 int (*close) __P((DB_CHANNEL *, u_int32_t));
2701 int (*send_msg) __P((DB_CHANNEL *, DBT *, u_int32_t, u_int32_t));
2702 int (*send_request) __P((DB_CHANNEL *,
2703 DBT *, u_int32_t, DBT *, db_timeout_t, u_int32_t));
2704 int (*set_timeout) __P((DB_CHANNEL *, db_timeout_t));
2705 /* DB_CHANNEL PUBLIC HANDLE LIST END */
2706};
2707
2708struct __db_site {
2709 ENV *env;
2710 int eid;
2711 const char *host;
2712 u_int port;
2713 u_int32_t flags;
2714
2715 /* DB_SITE PUBLIC HANDLE LIST BEGIN */
2716 int (*get_address) __P((DB_SITE *, const char **, u_int *));
2717 int (*get_config) __P((DB_SITE *, u_int32_t, u_int32_t *));
2718 int (*get_eid) __P((DB_SITE *, int *));
2719 int (*set_config) __P((DB_SITE *, u_int32_t, u_int32_t));
2720 int (*remove) __P((DB_SITE *));
2721 int (*close) __P((DB_SITE *));
2722 /* DB_SITE PUBLIC HANDLE LIST END */
2723};
2724
2725#if DB_DBM_HSEARCH != 0
2726/*******************************************************
2727 * Dbm/Ndbm historic interfaces.
2728 *******************************************************/
2729typedef struct __db DBM;
2730
2731#define DBM_INSERT 0 /* Flags to dbm_store(). */
2732#define DBM_REPLACE 1
2733
2734/*
2735 * The DB support for ndbm(3) always appends this suffix to the
2736 * file name to avoid overwriting the user's original database.
2737 */
2738#define DBM_SUFFIX ".db"
2739
2740#if defined(_XPG4_2)
2741typedef struct {
2742 char *dptr;
2743 size_t dsize;
2744} datum;
2745#else
2746typedef struct {
2747 char *dptr;
2748 int dsize;
2749} datum;
2750#endif
2751
2752/*
2753 * Translate NDBM calls into DB calls so that DB doesn't step on the
2754 * application's name space.
2755 */
2756#define dbm_clearerr(a) __db_ndbm_clearerr(a)
2757#define dbm_close(a) __db_ndbm_close(a)
2758#define dbm_delete(a, b) __db_ndbm_delete(a, b)
2759#define dbm_dirfno(a) __db_ndbm_dirfno(a)
2760#define dbm_error(a) __db_ndbm_error(a)
2761#define dbm_fetch(a, b) __db_ndbm_fetch(a, b)
2762#define dbm_firstkey(a) __db_ndbm_firstkey(a)
2763#define dbm_nextkey(a) __db_ndbm_nextkey(a)
2764#define dbm_open(a, b, c) __db_ndbm_open(a, b, c)
2765#define dbm_pagfno(a) __db_ndbm_pagfno(a)
2766#define dbm_rdonly(a) __db_ndbm_rdonly(a)
2767#define dbm_store(a, b, c, d) \
2768 __db_ndbm_store(a, b, c, d)
2769
2770/*
2771 * Translate DBM calls into DB calls so that DB doesn't step on the
2772 * application's name space.
2773 *
2774 * The global variables dbrdonly, dirf and pagf were not retained when 4BSD
2775 * replaced the dbm interface with ndbm, and are not supported here.
2776 */
2777#define dbminit(a) __db_dbm_init(a)
2778#define dbmclose __db_dbm_close
2779#if !defined(__cplusplus)
2780#define delete(a) __db_dbm_delete(a)
2781#endif
2782#define fetch(a) __db_dbm_fetch(a)
2783#define firstkey __db_dbm_firstkey
2784#define nextkey(a) __db_dbm_nextkey(a)
2785#define store(a, b) __db_dbm_store(a, b)
2786
2787/*******************************************************
2788 * Hsearch historic interface.
2789 *******************************************************/
2790typedef enum {
2791 FIND, ENTER
2792} ACTION;
2793
2794typedef struct entry {
2795 char *key;
2796 char *data;
2797} ENTRY;
2798
2799#define hcreate(a) __db_hcreate(a)
2800#define hdestroy __db_hdestroy
2801#define hsearch(a, b) __db_hsearch(a, b)
2802
2803#endif /* DB_DBM_HSEARCH */
2804
2805#if defined(__cplusplus)
2806}
2807#endif
2808
2809
2810#endif /* !_DB_H_ */
2811/* DO NOT EDIT: automatically built by dist/s_apiflags. */
2812#define DB_AGGRESSIVE 0x00000001
2813#define DB_ARCH_ABS 0x00000001
2814#define DB_ARCH_DATA 0x00000002
2815#define DB_ARCH_LOG 0x00000004
2816#define DB_ARCH_REMOVE 0x00000008
2817#define DB_AUTO_COMMIT 0x00000100
2818#define DB_BACKUP_CLEAN 0x00000002
2819#define DB_BACKUP_FILES 0x00000008
2820#define DB_BACKUP_NO_LOGS 0x00000010
2821#define DB_BACKUP_SINGLE_DIR 0x00000020
2822#define DB_BACKUP_UPDATE 0x00000040
2823#define DB_BOOTSTRAP_HELPER 0x00000001
2824#define DB_CDB_ALLDB 0x00000040
2825#define DB_CHKSUM 0x00000008
2826#define DB_CKP_INTERNAL 0x00000002
2827#define DB_CREATE 0x00000001
2828#define DB_CURSOR_BULK 0x00000001
2829#define DB_CURSOR_TRANSIENT 0x00000008
2830#define DB_CXX_NO_EXCEPTIONS 0x00000002
2831#define DB_DATABASE_LOCKING 0x00000080
2832#define DB_DIRECT 0x00000020
2833#define DB_DIRECT_DB 0x00000200
2834#define DB_DSYNC_DB 0x00000400
2835#define DB_DUP 0x00000010
2836#define DB_DUPSORT 0x00000002
2837#define DB_DURABLE_UNKNOWN 0x00000040
2838#define DB_ENCRYPT 0x00000001
2839#define DB_ENCRYPT_AES 0x00000001
2840#define DB_EXCL 0x00000004
2841#define DB_EXTENT 0x00000100
2842#define DB_FAILCHK 0x00000010
2843#define DB_FAILCHK_ISALIVE 0x00000040
2844#define DB_FAST_STAT 0x00000001
2845#define DB_FCNTL_LOCKING 0x00000800
2846#define DB_FLUSH 0x00000002
2847#define DB_FORCE 0x00000001
2848#define DB_FORCESYNC 0x00000001
2849#define DB_FOREIGN_ABORT 0x00000001
2850#define DB_FOREIGN_CASCADE 0x00000002
2851#define DB_FOREIGN_NULLIFY 0x00000004
2852#define DB_FREELIST_ONLY 0x00000001
2853#define DB_FREE_SPACE 0x00000002
2854#define DB_GROUP_CREATOR 0x00000002
2855#define DB_HOTBACKUP_IN_PROGRESS 0x00000800
2856#define DB_IGNORE_LEASE 0x00001000
2857#define DB_IMMUTABLE_KEY 0x00000002
2858#define DB_INIT_CDB 0x00000080
2859#define DB_INIT_LOCK 0x00000100
2860#define DB_INIT_LOG 0x00000200
2861#define DB_INIT_MPOOL 0x00000400
2862#define DB_INIT_MUTEX 0x00000800
2863#define DB_INIT_REP 0x00001000
2864#define DB_INIT_TXN 0x00002000
2865#define DB_INORDER 0x00000020
2866#define DB_INTERNAL_PERSISTENT_DB 0x00001000
2867#define DB_INTERNAL_TEMPORARY_DB 0x00002000
2868#define DB_JOIN_NOSORT 0x00000001
2869#define DB_LEGACY 0x00000004
2870#define DB_LOCAL_SITE 0x00000008
2871#define DB_LOCKDOWN 0x00004000
2872#define DB_LOCK_CHECK 0x00000001
2873#define DB_LOCK_IGNORE_REC 0x00000002
2874#define DB_LOCK_NOWAIT 0x00000004
2875#define DB_LOCK_RECORD 0x00000008
2876#define DB_LOCK_SET_TIMEOUT 0x00000010
2877#define DB_LOCK_SWITCH 0x00000020
2878#define DB_LOCK_UPGRADE 0x00000040
2879#define DB_LOG_AUTO_REMOVE 0x00000001
2880#define DB_LOG_CHKPNT 0x00000001
2881#define DB_LOG_COMMIT 0x00000004
2882#define DB_LOG_DIRECT 0x00000002
2883#define DB_LOG_DSYNC 0x00000004
2884#define DB_LOG_IN_MEMORY 0x00000008
2885#define DB_LOG_NOCOPY 0x00000008
2886#define DB_LOG_NOT_DURABLE 0x00000010
2887#define DB_LOG_NO_DATA 0x00000002
2888#define DB_LOG_VERIFY_CAF 0x00000001
2889#define DB_LOG_VERIFY_DBFILE 0x00000002
2890#define DB_LOG_VERIFY_ERR 0x00000004
2891#define DB_LOG_VERIFY_FORWARD 0x00000008
2892#define DB_LOG_VERIFY_INTERR 0x00000010
2893#define DB_LOG_VERIFY_PARTIAL 0x00000020
2894#define DB_LOG_VERIFY_VERBOSE 0x00000040
2895#define DB_LOG_VERIFY_WARNING 0x00000080
2896#define DB_LOG_WRNOSYNC 0x00000020
2897#define DB_LOG_ZERO 0x00000010
2898#define DB_MPOOL_CREATE 0x00000001
2899#define DB_MPOOL_DIRTY 0x00000002
2900#define DB_MPOOL_DISCARD 0x00000001
2901#define DB_MPOOL_EDIT 0x00000004
2902#define DB_MPOOL_FREE 0x00000008
2903#define DB_MPOOL_LAST 0x00000010
2904#define DB_MPOOL_NEW 0x00000020
2905#define DB_MPOOL_NOFILE 0x00000001
2906#define DB_MPOOL_NOLOCK 0x00000004
2907#define DB_MPOOL_TRY 0x00000040
2908#define DB_MPOOL_UNLINK 0x00000002
2909#define DB_MULTIPLE 0x00000800
2910#define DB_MULTIPLE_KEY 0x00004000
2911#define DB_MULTIVERSION 0x00000008
2912#define DB_MUTEX_ALLOCATED 0x00000001
2913#define DB_MUTEX_LOCKED 0x00000002
2914#define DB_MUTEX_LOGICAL_LOCK 0x00000004
2915#define DB_MUTEX_PROCESS_ONLY 0x00000008
2916#define DB_MUTEX_SELF_BLOCK 0x00000010
2917#define DB_MUTEX_SHARED 0x00000020
2918#define DB_NOERROR 0x00004000
2919#define DB_NOFLUSH 0x00001000
2920#define DB_NOLOCKING 0x00002000
2921#define DB_NOMMAP 0x00000010
2922#define DB_NOORDERCHK 0x00000002
2923#define DB_NOPANIC 0x00004000
2924#define DB_NOSYNC 0x00000001
2925#define DB_NO_AUTO_COMMIT 0x00008000
2926#define DB_NO_CHECKPOINT 0x00008000
2927#define DB_ODDFILESIZE 0x00000080
2928#define DB_ORDERCHKONLY 0x00000004
2929#define DB_OVERWRITE 0x00008000
2930#define DB_PANIC_ENVIRONMENT 0x00010000
2931#define DB_PRINTABLE 0x00000008
2932#define DB_PRIVATE 0x00010000
2933#define DB_PR_PAGE 0x00000010
2934#define DB_PR_RECOVERYTEST 0x00000020
2935#define DB_RDONLY 0x00000400
2936#define DB_RDWRMASTER 0x00010000
2937#define DB_READ_COMMITTED 0x00000400
2938#define DB_READ_UNCOMMITTED 0x00000200
2939#define DB_RECNUM 0x00000040
2940#define DB_RECOVER 0x00000002
2941#define DB_RECOVER_FATAL 0x00020000
2942#define DB_REGION_INIT 0x00020000
2943#define DB_REGISTER 0x00040000
2944#define DB_RENUMBER 0x00000080
2945#define DB_REPMGR_CONF_2SITE_STRICT 0x00000001
2946#define DB_REPMGR_CONF_ELECTIONS 0x00000002
2947#define DB_REPMGR_NEED_RESPONSE 0x00000001
2948#define DB_REPMGR_PEER 0x00000010
2949#define DB_REP_ANYWHERE 0x00000001
2950#define DB_REP_CLIENT 0x00000001
2951#define DB_REP_CONF_AUTOINIT 0x00000004
2952#define DB_REP_CONF_AUTOROLLBACK 0x00000008
2953#define DB_REP_CONF_BULK 0x00000010
2954#define DB_REP_CONF_DELAYCLIENT 0x00000020
2955#define DB_REP_CONF_INMEM 0x00000040
2956#define DB_REP_CONF_LEASE 0x00000080
2957#define DB_REP_CONF_NOWAIT 0x00000100
2958#define DB_REP_ELECTION 0x00000004
2959#define DB_REP_MASTER 0x00000002
2960#define DB_REP_NOBUFFER 0x00000002
2961#define DB_REP_PERMANENT 0x00000004
2962#define DB_REP_REREQUEST 0x00000008
2963#define DB_REVSPLITOFF 0x00000100
2964#define DB_RMW 0x00002000
2965#define DB_SALVAGE 0x00000040
2966#define DB_SA_SKIPFIRSTKEY 0x00000080
2967#define DB_SA_UNKNOWNKEY 0x00000100
2968#define DB_SEQ_DEC 0x00000001
2969#define DB_SEQ_INC 0x00000002
2970#define DB_SEQ_RANGE_SET 0x00000004
2971#define DB_SEQ_WRAP 0x00000008
2972#define DB_SEQ_WRAPPED 0x00000010
2973#define DB_SET_LOCK_TIMEOUT 0x00000001
2974#define DB_SET_REG_TIMEOUT 0x00000004
2975#define DB_SET_TXN_NOW 0x00000008
2976#define DB_SET_TXN_TIMEOUT 0x00000002
2977#define DB_SHALLOW_DUP 0x00000100
2978#define DB_SNAPSHOT 0x00000200
2979#define DB_STAT_ALL 0x00000004
2980#define DB_STAT_ALLOC 0x00000008
2981#define DB_STAT_CLEAR 0x00000001
2982#define DB_STAT_LOCK_CONF 0x00000010
2983#define DB_STAT_LOCK_LOCKERS 0x00000020
2984#define DB_STAT_LOCK_OBJECTS 0x00000040
2985#define DB_STAT_LOCK_PARAMS 0x00000080
2986#define DB_STAT_MEMP_HASH 0x00000010
2987#define DB_STAT_MEMP_NOERROR 0x00000020
2988#define DB_STAT_SUBSYSTEM 0x00000002
2989#define DB_STAT_SUMMARY 0x00000010
2990#define DB_ST_DUPOK 0x00000200
2991#define DB_ST_DUPSET 0x00000400
2992#define DB_ST_DUPSORT 0x00000800
2993#define DB_ST_IS_RECNO 0x00001000
2994#define DB_ST_OVFL_LEAF 0x00002000
2995#define DB_ST_RECNUM 0x00004000
2996#define DB_ST_RELEN 0x00008000
2997#define DB_ST_TOPLEVEL 0x00010000
2998#define DB_SYSTEM_MEM 0x00080000
2999#define DB_THREAD 0x00000020
3000#define DB_TIME_NOTGRANTED 0x00040000
3001#define DB_TRUNCATE 0x00020000
3002#define DB_TXN_BULK 0x00000010
3003#define DB_TXN_FAMILY 0x00000040
3004#define DB_TXN_NOSYNC 0x00000001
3005#define DB_TXN_NOT_DURABLE 0x00000004
3006#define DB_TXN_NOWAIT 0x00000002
3007#define DB_TXN_SNAPSHOT 0x00000004
3008#define DB_TXN_SYNC 0x00000008
3009#define DB_TXN_WAIT 0x00000080
3010#define DB_TXN_WRITE_NOSYNC 0x00000020
3011#define DB_UNREF 0x00020000
3012#define DB_UPGRADE 0x00000001
3013#define DB_USE_ENVIRON 0x00000004
3014#define DB_USE_ENVIRON_ROOT 0x00000008
3015#define DB_VERB_BACKUP 0x00000001
3016#define DB_VERB_DEADLOCK 0x00000002
3017#define DB_VERB_FILEOPS 0x00000004
3018#define DB_VERB_FILEOPS_ALL 0x00000008
3019#define DB_VERB_RECOVERY 0x00000010
3020#define DB_VERB_REGISTER 0x00000020
3021#define DB_VERB_REPLICATION 0x00000040
3022#define DB_VERB_REPMGR_CONNFAIL 0x00000080
3023#define DB_VERB_REPMGR_MISC 0x00000100
3024#define DB_VERB_REP_ELECT 0x00000200
3025#define DB_VERB_REP_LEASE 0x00000400
3026#define DB_VERB_REP_MISC 0x00000800
3027#define DB_VERB_REP_MSGS 0x00001000
3028#define DB_VERB_REP_SYNC 0x00002000
3029#define DB_VERB_REP_SYSTEM 0x00004000
3030#define DB_VERB_REP_TEST 0x00008000
3031#define DB_VERB_WAITSFOR 0x00010000
3032#define DB_VERIFY 0x00000002
3033#define DB_VERIFY_PARTITION 0x00040000
3034#define DB_WRITECURSOR 0x00000010
3035#define DB_WRITELOCK 0x00000020
3036#define DB_WRITEOPEN 0x00040000
3037#define DB_XA_CREATE 0x00000001
3038#define DB_YIELDCPU 0x00080000
3039
3040/* DO NOT EDIT: automatically built by dist/s_include. */
3041#ifndef _DB_EXT_PROT_IN_
3042#define _DB_EXT_PROT_IN_
3043
3044#if defined(__cplusplus)
3045extern "C" {
3046#endif
3047
3048int db_copy __P((DB_ENV *, const char *, const char *, const char *));
3049int db_create __P((DB **, DB_ENV *, u_int32_t));
3050char *db_strerror __P((int));
3051int db_env_set_func_assert __P((void (*)(const char *, const char *, int)));
3052int db_env_set_func_close __P((int (*)(int)));
3053int db_env_set_func_dirfree __P((void (*)(char **, int)));
3054int db_env_set_func_dirlist __P((int (*)(const char *, char ***, int *)));
3055int db_env_set_func_exists __P((int (*)(const char *, int *)));
3056int db_env_set_func_free __P((void (*)(void *)));
3057int db_env_set_func_fsync __P((int (*)(int)));
3058int db_env_set_func_ftruncate __P((int (*)(int, off_t)));
3059int db_env_set_func_ioinfo __P((int (*)(const char *, int, u_int32_t *, u_int32_t *, u_int32_t *)));
3060int db_env_set_func_malloc __P((void *(*)(size_t)));
3061int db_env_set_func_file_map __P((int (*)(DB_ENV *, char *, size_t, int, void **), int (*)(DB_ENV *, void *)));
3062int db_env_set_func_region_map __P((int (*)(DB_ENV *, char *, size_t, int *, void **), int (*)(DB_ENV *, void *)));
3063int db_env_set_func_pread __P((ssize_t (*)(int, void *, size_t, off_t)));
3064int db_env_set_func_pwrite __P((ssize_t (*)(int, const void *, size_t, off_t)));
3065int db_env_set_func_open __P((int (*)(const char *, int, ...)));
3066int db_env_set_func_read __P((ssize_t (*)(int, void *, size_t)));
3067int db_env_set_func_realloc __P((void *(*)(void *, size_t)));
3068int db_env_set_func_rename __P((int (*)(const char *, const char *)));
3069int db_env_set_func_seek __P((int (*)(int, off_t, int)));
3070int db_env_set_func_unlink __P((int (*)(const char *)));
3071int db_env_set_func_write __P((ssize_t (*)(int, const void *, size_t)));
3072int db_env_set_func_yield __P((int (*)(u_long, u_long)));
3073int db_env_create __P((DB_ENV **, u_int32_t));
3074char *db_version __P((int *, int *, int *));
3075char *db_full_version __P((int *, int *, int *, int *, int *));
3076int log_compare __P((const DB_LSN *, const DB_LSN *));
3077#if defined(DB_WIN32) && !defined(DB_WINCE)
3078int db_env_set_win_security __P((SECURITY_ATTRIBUTES *sa));
3079#endif
3080int db_sequence_create __P((DB_SEQUENCE **, DB *, u_int32_t));
3081#if DB_DBM_HSEARCH != 0
3082int __db_ndbm_clearerr __P((DBM *));
3083void __db_ndbm_close __P((DBM *));
3084int __db_ndbm_delete __P((DBM *, datum));
3085int __db_ndbm_dirfno __P((DBM *));
3086int __db_ndbm_error __P((DBM *));
3087datum __db_ndbm_fetch __P((DBM *, datum));
3088datum __db_ndbm_firstkey __P((DBM *));
3089datum __db_ndbm_nextkey __P((DBM *));
3090DBM *__db_ndbm_open __P((const char *, int, int));
3091int __db_ndbm_pagfno __P((DBM *));
3092int __db_ndbm_rdonly __P((DBM *));
3093int __db_ndbm_store __P((DBM *, datum, datum, int));
3094int __db_dbm_close __P((void));
3095int __db_dbm_delete __P((datum));
3096datum __db_dbm_fetch __P((datum));
3097datum __db_dbm_firstkey __P((void));
3098int __db_dbm_init __P((char *));
3099datum __db_dbm_nextkey __P((datum));
3100int __db_dbm_store __P((datum, datum));
3101#endif
3102#if DB_DBM_HSEARCH != 0
3103int __db_hcreate __P((size_t));
3104ENTRY *__db_hsearch __P((ENTRY, ACTION));
3105void __db_hdestroy __P((void));
3106#endif
3107
3108#if defined(__cplusplus)
3109}
3110#endif
3111#endif /* !_DB_EXT_PROT_IN_ */
3112

Warning: That file was not part of the compilation database. It may have many parsing errors.