]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/back-ldbm.h
Add GIANT rwlock! This should resolve nasty concurrency issues.
[openldap] / servers / slapd / back-ldbm / back-ldbm.h
1 /* back-ldbm.h - ldap ldbm back-end header file */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #ifndef _BACK_LDBM_H_
9 #define _BACK_LDBM_H_
10
11 #include "ldbm.h"
12
13 LDAP_BEGIN_DECL
14
15 #define DEFAULT_CACHE_SIZE      1000
16
17 #if defined(HAVE_BERKELEY_DB) && DB_VERSION_MAJOR >= 2
18 #       define DEFAULT_DBCACHE_SIZE (100 * DEFAULT_DB_PAGE_SIZE)
19 #else
20 #       define DEFAULT_DBCACHE_SIZE 100000
21 #endif
22
23 #define DEFAULT_DB_DIRECTORY    LDAP_RUNDIR LDAP_DIRSEP "openldap-ldbm"
24 #define DEFAULT_MODE            0600
25
26 #define DN_BASE_PREFIX          SLAP_INDEX_EQUALITY_PREFIX
27 #define DN_ONE_PREFIX           '%'
28 #define DN_SUBTREE_PREFIX       '@'
29
30 /*
31  * there is a single index for each attribute.  these prefixes ensure
32  * that there is no collision among keys.
33  */
34
35 /* allow PREFIX + byte for continuate number */
36 #define SLAP_INDEX_CONT_SIZE ( sizeof(SLAP_INDEX_CONT_PREFIX) + sizeof(unsigned char) )
37
38 #define DEFAULT_BLOCKSIZE       8192
39
40 /*
41  * This structure represents an id block on disk and an id list
42  * in core.
43  *
44  * The fields have the following meanings:
45  *
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
53  */
54
55 typedef ID ID_BLOCK;
56
57 #define ID_BLOCK_NMAX_OFFSET    0
58 #define ID_BLOCK_NIDS_OFFSET    1
59 #define ID_BLOCK_IDS_OFFSET             2
60
61 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
62
63 #define ID_BLOCK_NMAX(b)                ((b)[ID_BLOCK_NMAX_OFFSET])
64
65 /* Use this macro to get the value, but not to set it.
66  * By default this is identical to above.
67  */
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)])
71
72 #define ID_BLOCK_NOID(b, n)             (ID_BLOCK_ID((b),(n)) == NOID)
73
74 #define ID_BLOCK_ALLIDS_VALUE   0
75 #define ID_BLOCK_ALLIDS(b)              (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
76
77 #define ID_BLOCK_INDIRECT_VALUE 0
78 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
79
80 #define USE_INDIRECT_NIDS       1
81
82 #ifdef USE_INDIRECT_NIDS
83 /*
84  * Use the high bit of ID_BLOCK_NMAX to indicate an INDIRECT block, thus
85  * freeing up the ID_BLOCK_NIDS to store an actual count. This allows us
86  * to use binary search on INDIRECT blocks.
87  */
88 #undef  ID_BLOCK_NMAXN
89 #define ID_BLOCK_NMAXN(b)               ((b)[ID_BLOCK_NMAX_OFFSET]&0x7fffffff)
90 #undef  ID_BLOCK_INDIRECT_VALUE
91 #define ID_BLOCK_INDIRECT_VALUE 0x80000000
92 #undef  ID_BLOCK_INDIRECT
93 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NMAX(b) & ID_BLOCK_INDIRECT_VALUE)
94
95 #endif  /* USE_INDIRECT_NIDS */
96
97 /* for the in-core cache of entries */
98 typedef struct ldbm_cache {
99         int             c_maxsize;
100         int             c_cursize;
101         Avlnode         *c_dntree;
102         Avlnode         *c_idtree;
103         Entry           *c_lruhead;     /* lru - add accessed entries here */
104         Entry           *c_lrutail;     /* lru - rem lru entries from here */
105         ldap_pvt_thread_mutex_t c_mutex;
106 } Cache;
107
108 #define CACHE_READ_LOCK         0
109 #define CACHE_WRITE_LOCK        1
110
111 /* for the cache of open index files */
112 typedef struct ldbm_dbcache {
113         int             dbc_refcnt;
114         int             dbc_maxids;
115         int             dbc_maxindirect;
116         int             dbc_dirty;
117         int             dbc_flags;
118         time_t  dbc_lastref;
119         long    dbc_blksize;
120         char    *dbc_name;
121         LDBM    dbc_db;
122         ldap_pvt_thread_mutex_t dbc_write_mutex;
123 } DBCache;
124
125 #define MAXDBCACHE      128
126
127 struct ldbminfo {
128         ldap_pvt_thread_rdwr_t          li_giant_rwlock;
129         ID                      li_nextid;
130         int                     li_mode;
131         slap_mask_t     li_defaultmask;
132         char                    *li_directory;
133         Cache           li_cache;
134         Avlnode                 *li_attrs;
135         int                     li_dblocking;   /* lock databases */
136         int                     li_dbwritesync; /* write sync */
137         int                     li_dbcachesize;
138         DBCache         li_dbcache[MAXDBCACHE];
139         ldap_pvt_thread_mutex_t         li_dbcache_mutex;
140         ldap_pvt_thread_cond_t          li_dbcache_cv;
141         DB_ENV                  *li_dbenv;
142         int                     li_envdirok;
143         int                     li_dbsyncfreq;
144         int                     li_dbsyncwaitn;
145         int                     li_dbsyncwaitinterval;
146         ldap_pvt_thread_t       li_dbsynctid;
147         int                     li_dbshutdown;
148 };
149
150 LDAP_END_DECL
151
152 #include "proto-back-ldbm.h"
153
154 #endif /* _back_ldbm_h_ */