1 /* back-ldbm.h - ldap ldbm back-end header file */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
24 #define LDBM_SUBENTRIES 1
26 #define DEFAULT_CACHE_SIZE 1000
28 #if defined(HAVE_BERKELEY_DB) && DB_VERSION_MAJOR >= 2
29 # define DEFAULT_DBCACHE_SIZE (100 * DEFAULT_DB_PAGE_SIZE)
31 # define DEFAULT_DBCACHE_SIZE 100000
34 #define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX
35 #define DN_ONE_PREFIX '%'
36 #define DN_SUBTREE_PREFIX '@'
39 * there is a single index for each attribute. these prefixes ensure
40 * that there is no collision among keys.
43 /* allow PREFIX + byte for continuate number */
44 #define SLAP_INDEX_CONT_SIZE ( sizeof(SLAP_INDEX_CONT_PREFIX) + sizeof(unsigned char) )
46 #define DEFAULT_BLOCKSIZE 8192
49 * This structure represents an id block on disk and an id list
52 * The fields have the following meanings:
54 * b_nmax maximum number of ids in this block. if this is == ALLIDSBLOCK,
55 * then this block represents all ids.
56 * b_nids current number of ids in use in this block. if this
57 * is == INDBLOCK, then this block is an indirect block
58 * containing a list of other blocks containing actual ids.
59 * the list is terminated by an id of NOID.
60 * b_ids a list of the actual ids themselves
65 #define ID_BLOCK_NMAX_OFFSET 0
66 #define ID_BLOCK_NIDS_OFFSET 1
67 #define ID_BLOCK_IDS_OFFSET 2
69 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
71 #define ID_BLOCK_NMAX(b) ((b)[ID_BLOCK_NMAX_OFFSET])
73 /* Use this macro to get the value, but not to set it.
74 * By default this is identical to above.
76 #define ID_BLOCK_NMAXN(b) ID_BLOCK_NMAX(b)
77 #define ID_BLOCK_NIDS(b) ((b)[ID_BLOCK_NIDS_OFFSET])
78 #define ID_BLOCK_ID(b, n) ((b)[ID_BLOCK_IDS_OFFSET+(n)])
80 #define ID_BLOCK_NOID(b, n) (ID_BLOCK_ID((b),(n)) == NOID)
82 #define ID_BLOCK_ALLIDS_VALUE 0
83 #define ID_BLOCK_ALLIDS(b) (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
85 #define ID_BLOCK_INDIRECT_VALUE 0
86 #define ID_BLOCK_INDIRECT(b) (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
88 #define USE_INDIRECT_NIDS 1
90 #ifdef USE_INDIRECT_NIDS
92 * Use the high bit of ID_BLOCK_NMAX to indicate an INDIRECT block, thus
93 * freeing up the ID_BLOCK_NIDS to store an actual count. This allows us
94 * to use binary search on INDIRECT blocks.
97 #define ID_BLOCK_NMAXN(b) ((b)[ID_BLOCK_NMAX_OFFSET]&0x7fffffff)
98 #undef ID_BLOCK_INDIRECT_VALUE
99 #define ID_BLOCK_INDIRECT_VALUE 0x80000000
100 #undef ID_BLOCK_INDIRECT
101 #define ID_BLOCK_INDIRECT(b) (ID_BLOCK_NMAX(b) & ID_BLOCK_INDIRECT_VALUE)
103 #endif /* USE_INDIRECT_NIDS */
105 /* for the in-core cache of entries */
106 typedef struct ldbm_cache {
111 Entry *c_lruhead; /* lru - add accessed entries here */
112 Entry *c_lrutail; /* lru - rem lru entries from here */
113 ldap_pvt_thread_mutex_t c_mutex;
116 #define CACHE_READ_LOCK 0
117 #define CACHE_WRITE_LOCK 1
119 /* for the cache of open index files */
120 typedef struct ldbm_dbcache {
130 ldap_pvt_thread_mutex_t dbc_write_mutex;
133 #define MAXDBCACHE 128
136 ldap_pvt_thread_rdwr_t li_giant_rwlock;
139 slap_mask_t li_defaultmask;
143 int li_dblocking; /* lock databases */
144 int li_dbwritesync; /* write sync */
146 DBCache li_dbcache[MAXDBCACHE];
147 ldap_pvt_thread_mutex_t li_dbcache_mutex;
148 ldap_pvt_thread_cond_t li_dbcache_cv;
153 int li_dbsyncwaitinterval;
154 ldap_pvt_thread_t li_dbsynctid;
160 #include "proto-back-ldbm.h"
162 #endif /* _back_ldbm_h_ */