1 /* back-ldbm.h - ldap ldbm back-end header file */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
15 #define DEFAULT_CACHE_SIZE 1000
17 #if defined(HAVE_BERKELEY_DB) && DB_VERSION_MAJOR >= 2
18 # define DEFAULT_DBCACHE_SIZE (100 * DEFAULT_DB_PAGE_SIZE)
20 # define DEFAULT_DBCACHE_SIZE 100000
23 #define DEFAULT_DB_DIRECTORY LDAP_RUNDIR LDAP_DIRSEP "openldap-ldbm"
24 #define DEFAULT_MODE 0600
26 #define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX
27 #define DN_ONE_PREFIX '%'
28 #define DN_SUBTREE_PREFIX '@'
31 * there is a single index for each attribute. these prefixes ensure
32 * that there is no collision among keys.
35 /* allow PREFIX + byte for continuate number */
36 #define SLAP_INDEX_CONT_SIZE ( sizeof(SLAP_INDEX_CONT_PREFIX) + sizeof(unsigned char) )
38 #define DEFAULT_BLOCKSIZE 8192
41 * This structure represents an id block on disk and an id list
44 * The fields have the following meanings:
46 * b_nmax maximum number of ids in this block. if this is == ALLIDSBLOCK,
47 * then this block represents all ids.
48 * b_nids current number of ids in use in this block. if this
49 * is == INDBLOCK, then this block is an indirect block
50 * containing a list of other blocks containing actual ids.
51 * the list is terminated by an id of NOID.
52 * b_ids a list of the actual ids themselves
57 #define ID_BLOCK_NMAX_OFFSET 0
58 #define ID_BLOCK_NIDS_OFFSET 1
59 #define ID_BLOCK_IDS_OFFSET 2
61 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
63 #define ID_BLOCK_NMAX(b) ((b)[ID_BLOCK_NMAX_OFFSET])
65 /* Use this macro to get the value, but not to set it.
66 * By default this is identical to above.
68 #define ID_BLOCK_NMAXN(b) ID_BLOCK_NMAX(b)
69 #define ID_BLOCK_NIDS(b) ((b)[ID_BLOCK_NIDS_OFFSET])
70 #define ID_BLOCK_ID(b, n) ((b)[ID_BLOCK_IDS_OFFSET+(n)])
72 #define ID_BLOCK_NOID(b, n) (ID_BLOCK_ID((b),(n)) == NOID)
74 #define ID_BLOCK_ALLIDS_VALUE 0
75 #define ID_BLOCK_ALLIDS(b) (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
77 #define ID_BLOCK_INDIRECT_VALUE 0
78 #define ID_BLOCK_INDIRECT(b) (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
80 #ifdef USE_INDIRECT_NIDS
82 * Use the high bit of ID_BLOCK_NMAX to indicate an INDIRECT block, thus
83 * freeing up the ID_BLOCK_NIDS to store an actual count. This allows us
84 * to use binary search on INDIRECT blocks.
87 #define ID_BLOCK_NMAXN(b) ((b)[ID_BLOCK_NMAX_OFFSET]&0x7fffffff)
88 #undef ID_BLOCK_INDIRECT_VALUE
89 #define ID_BLOCK_INDIRECT_VALUE 0x80000000
90 #undef ID_BLOCK_INDIRECT
91 #define ID_BLOCK_INDIRECT(b) (ID_BLOCK_NMAX(b) & ID_BLOCK_INDIRECT_VALUE)
93 #endif /* USE_INDIRECT_NIDS */
95 /* for the in-core cache of entries */
96 typedef struct ldbm_cache {
101 Entry *c_lruhead; /* lru - add accessed entries here */
102 Entry *c_lrutail; /* lru - rem lru entries from here */
103 ldap_pvt_thread_mutex_t c_mutex;
106 #define CACHE_READ_LOCK 0
107 #define CACHE_WRITE_LOCK 1
109 /* for the cache of open index files */
110 typedef struct ldbm_dbcache {
122 #define MAXDBCACHE 128
126 ldap_pvt_thread_mutex_t li_nextid_mutex;
127 ldap_pvt_thread_mutex_t li_root_mutex;
128 ldap_pvt_thread_mutex_t li_add_mutex;
130 slap_mask_t li_defaultmask;
134 int li_dblocking; /* lock databases */
135 int li_dbwritesync; /* write sync */
137 DBCache li_dbcache[MAXDBCACHE];
138 ldap_pvt_thread_mutex_t li_dbcache_mutex;
139 ldap_pvt_thread_cond_t li_dbcache_cv;
144 int li_dbsyncwaitinterval;
145 ldap_pvt_thread_t li_dbsynctid;
151 #include "proto-back-ldbm.h"
153 #endif /* _back_ldbm_h_ */