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-2006 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 DEFAULT_CACHE_SIZE 1000
27 #if defined(HAVE_BERKELEY_DB) && DB_VERSION_MAJOR >= 2
28 # define DEFAULT_DBCACHE_SIZE (100 * DEFAULT_DB_PAGE_SIZE)
30 # define DEFAULT_DBCACHE_SIZE 100000
33 #define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX
34 #define DN_ONE_PREFIX '%'
35 #define DN_SUBTREE_PREFIX '@'
38 * there is a single index for each attribute. these prefixes ensure
39 * that there is no collision among keys.
42 /* allow PREFIX + byte for continuate number */
43 #define SLAP_INDEX_CONT_SIZE ( sizeof(SLAP_INDEX_CONT_PREFIX) + sizeof(unsigned char) )
45 #define DEFAULT_BLOCKSIZE 8192
48 * This structure represents an id block on disk and an id list
51 * The fields have the following meanings:
53 * b_nmax maximum number of ids in this block. if this is == ALLIDSBLOCK,
54 * then this block represents all ids.
55 * b_nids current number of ids in use in this block. if this
56 * is == INDBLOCK, then this block is an indirect block
57 * containing a list of other blocks containing actual ids.
58 * the list is terminated by an id of NOID.
59 * b_ids a list of the actual ids themselves
64 #define ID_BLOCK_NMAX_OFFSET 0
65 #define ID_BLOCK_NIDS_OFFSET 1
66 #define ID_BLOCK_IDS_OFFSET 2
68 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
70 #define ID_BLOCK_NMAX(b) ((b)[ID_BLOCK_NMAX_OFFSET])
72 /* Use this macro to get the value, but not to set it.
73 * By default this is identical to above.
75 #define ID_BLOCK_NMAXN(b) ID_BLOCK_NMAX(b)
76 #define ID_BLOCK_NIDS(b) ((b)[ID_BLOCK_NIDS_OFFSET])
77 #define ID_BLOCK_ID(b, n) ((b)[ID_BLOCK_IDS_OFFSET+(n)])
79 #define ID_BLOCK_NOID(b, n) (ID_BLOCK_ID((b),(n)) == NOID)
81 #define ID_BLOCK_ALLIDS_VALUE 0
82 #define ID_BLOCK_ALLIDS(b) (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
84 #define ID_BLOCK_INDIRECT_VALUE 0
85 #define ID_BLOCK_INDIRECT(b) (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
87 #define USE_INDIRECT_NIDS 1
89 #ifdef USE_INDIRECT_NIDS
91 * Use the high bit of ID_BLOCK_NMAX to indicate an INDIRECT block, thus
92 * freeing up the ID_BLOCK_NIDS to store an actual count. This allows us
93 * to use binary search on INDIRECT blocks.
96 #define ID_BLOCK_NMAXN(b) ((b)[ID_BLOCK_NMAX_OFFSET]&0x7fffffff)
97 #undef ID_BLOCK_INDIRECT_VALUE
98 #define ID_BLOCK_INDIRECT_VALUE 0x80000000
99 #undef ID_BLOCK_INDIRECT
100 #define ID_BLOCK_INDIRECT(b) (ID_BLOCK_NMAX(b) & ID_BLOCK_INDIRECT_VALUE)
102 #endif /* USE_INDIRECT_NIDS */
104 /* for the in-core cache of entries */
105 typedef struct ldbm_cache {
110 Entry *c_lruhead; /* lru - add accessed entries here */
111 Entry *c_lrutail; /* lru - rem lru entries from here */
112 ldap_pvt_thread_mutex_t c_mutex;
115 #define CACHE_READ_LOCK 0
116 #define CACHE_WRITE_LOCK 1
118 /* for the cache of open index files */
119 typedef struct ldbm_dbcache {
129 ldap_pvt_thread_mutex_t dbc_write_mutex;
132 #define MAXDBCACHE 128
135 ldap_pvt_thread_rdwr_t li_giant_rwlock;
138 slap_mask_t li_defaultmask;
142 int li_dblocking; /* lock databases */
143 int li_dbwritesync; /* write sync */
145 DBCache li_dbcache[MAXDBCACHE];
146 ldap_pvt_thread_mutex_t li_dbcache_mutex;
147 ldap_pvt_thread_cond_t li_dbcache_cv;
152 int li_dbsyncwaitinterval;
153 int li_dbsyncwaitcount;
154 alock_info_t li_alock_info;
159 #include "proto-back-ldbm.h"
161 #endif /* _back_ldbm_h_ */