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-2005 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>.
25 #define LDBM_SUBENTRIES 1
27 #define DEFAULT_CACHE_SIZE 1000
29 #if defined(HAVE_BERKELEY_DB) && DB_VERSION_MAJOR >= 2
30 # define DEFAULT_DBCACHE_SIZE (100 * DEFAULT_DB_PAGE_SIZE)
32 # define DEFAULT_DBCACHE_SIZE 100000
35 #define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX
36 #define DN_ONE_PREFIX '%'
37 #define DN_SUBTREE_PREFIX '@'
40 * there is a single index for each attribute. these prefixes ensure
41 * that there is no collision among keys.
44 /* allow PREFIX + byte for continuate number */
45 #define SLAP_INDEX_CONT_SIZE ( sizeof(SLAP_INDEX_CONT_PREFIX) + sizeof(unsigned char) )
47 #define DEFAULT_BLOCKSIZE 8192
50 * This structure represents an id block on disk and an id list
53 * The fields have the following meanings:
55 * b_nmax maximum number of ids in this block. if this is == ALLIDSBLOCK,
56 * then this block represents all ids.
57 * b_nids current number of ids in use in this block. if this
58 * is == INDBLOCK, then this block is an indirect block
59 * containing a list of other blocks containing actual ids.
60 * the list is terminated by an id of NOID.
61 * b_ids a list of the actual ids themselves
66 #define ID_BLOCK_NMAX_OFFSET 0
67 #define ID_BLOCK_NIDS_OFFSET 1
68 #define ID_BLOCK_IDS_OFFSET 2
70 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
72 #define ID_BLOCK_NMAX(b) ((b)[ID_BLOCK_NMAX_OFFSET])
74 /* Use this macro to get the value, but not to set it.
75 * By default this is identical to above.
77 #define ID_BLOCK_NMAXN(b) ID_BLOCK_NMAX(b)
78 #define ID_BLOCK_NIDS(b) ((b)[ID_BLOCK_NIDS_OFFSET])
79 #define ID_BLOCK_ID(b, n) ((b)[ID_BLOCK_IDS_OFFSET+(n)])
81 #define ID_BLOCK_NOID(b, n) (ID_BLOCK_ID((b),(n)) == NOID)
83 #define ID_BLOCK_ALLIDS_VALUE 0
84 #define ID_BLOCK_ALLIDS(b) (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
86 #define ID_BLOCK_INDIRECT_VALUE 0
87 #define ID_BLOCK_INDIRECT(b) (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
89 #define USE_INDIRECT_NIDS 1
91 #ifdef USE_INDIRECT_NIDS
93 * Use the high bit of ID_BLOCK_NMAX to indicate an INDIRECT block, thus
94 * freeing up the ID_BLOCK_NIDS to store an actual count. This allows us
95 * to use binary search on INDIRECT blocks.
98 #define ID_BLOCK_NMAXN(b) ((b)[ID_BLOCK_NMAX_OFFSET]&0x7fffffff)
99 #undef ID_BLOCK_INDIRECT_VALUE
100 #define ID_BLOCK_INDIRECT_VALUE 0x80000000
101 #undef ID_BLOCK_INDIRECT
102 #define ID_BLOCK_INDIRECT(b) (ID_BLOCK_NMAX(b) & ID_BLOCK_INDIRECT_VALUE)
104 #endif /* USE_INDIRECT_NIDS */
106 /* for the in-core cache of entries */
107 typedef struct ldbm_cache {
112 Entry *c_lruhead; /* lru - add accessed entries here */
113 Entry *c_lrutail; /* lru - rem lru entries from here */
114 ldap_pvt_thread_mutex_t c_mutex;
117 #define CACHE_READ_LOCK 0
118 #define CACHE_WRITE_LOCK 1
120 /* for the cache of open index files */
121 typedef struct ldbm_dbcache {
131 ldap_pvt_thread_mutex_t dbc_write_mutex;
134 #define MAXDBCACHE 128
137 ldap_pvt_thread_rdwr_t li_giant_rwlock;
140 slap_mask_t li_defaultmask;
144 int li_dblocking; /* lock databases */
145 int li_dbwritesync; /* write sync */
147 DBCache li_dbcache[MAXDBCACHE];
148 ldap_pvt_thread_mutex_t li_dbcache_mutex;
149 ldap_pvt_thread_cond_t li_dbcache_cv;
154 int li_dbsyncwaitinterval;
155 int li_dbsyncwaitcount;
156 alock_info_t li_alock_info;
161 #include "proto-back-ldbm.h"
163 #endif /* _back_ldbm_h_ */