]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/back-ldbm.h
Prepare for unifdef -DSLAPD_SCHEMA_NOT_COMPAT
[openldap] / servers / slapd / back-ldbm / back-ldbm.h
1 /* back-ldbm.h - ldap ldbm back-end header file */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 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 SUBLEN                  3
27
28 #define DN_BASE_PREFIX          SLAP_INDEX_EQUALITY_PREFIX
29 #define DN_ONE_PREFIX           '%'
30 #define DN_SUBTREE_PREFIX       '@'
31
32 /*
33  * there is a single index for each attribute.  these prefixes ensure
34  * that there is no collision among keys.
35  */
36
37 /* allow PREFIX + byte for continuate number */
38 #define SLAP_INDEX_CONT_SIZE ( sizeof(SLAP_INDEX_CONT_PREFIX) + sizeof(unsigned char) )
39
40 #define DEFAULT_BLOCKSIZE       8192
41
42 /*
43  * This structure represents an id block on disk and an id list
44  * in core.
45  *
46  * The fields have the following meanings:
47  *
48  *      b_nmax  maximum number of ids in this block. if this is == ALLIDSBLOCK,
49  *              then this block represents all ids.
50  *      b_nids  current number of ids in use in this block.  if this
51  *              is == INDBLOCK, then this block is an indirect block
52  *              containing a list of other blocks containing actual ids.
53  *              the list is terminated by an id of NOID.
54  *      b_ids   a list of the actual ids themselves
55  */
56
57 typedef ID ID_BLOCK;
58
59 #define ID_BLOCK_NMAX_OFFSET    0
60 #define ID_BLOCK_NIDS_OFFSET    1
61 #define ID_BLOCK_IDS_OFFSET             2
62
63 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
64
65 #define ID_BLOCK_NMAX(b)                ((b)[ID_BLOCK_NMAX_OFFSET])
66 #define ID_BLOCK_NIDS(b)                ((b)[ID_BLOCK_NIDS_OFFSET])
67 #define ID_BLOCK_ID(b, n)               ((b)[ID_BLOCK_IDS_OFFSET+(n)])
68
69 #define ID_BLOCK_NOID(b, n)             (ID_BLOCK_ID((b),(n)) == NOID)
70
71 #define ID_BLOCK_ALLIDS_VALUE   0
72 #define ID_BLOCK_ALLIDS(b)              (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
73
74 #define ID_BLOCK_INDIRECT_VALUE 0
75 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
76
77 /* for the in-core cache of entries */
78 typedef struct ldbm_cache {
79         int             c_maxsize;
80         int             c_cursize;
81         Avlnode         *c_dntree;
82         Avlnode         *c_idtree;
83         Entry           *c_lruhead;     /* lru - add accessed entries here */
84         Entry           *c_lrutail;     /* lru - rem lru entries from here */
85         ldap_pvt_thread_mutex_t c_mutex;
86 } Cache;
87
88 #define CACHE_READ_LOCK         0
89 #define CACHE_WRITE_LOCK        1
90
91 /* for the cache of open index files */
92 typedef struct ldbm_dbcache {
93         int             dbc_refcnt;
94         int             dbc_maxids;
95         int             dbc_maxindirect;
96         int             dbc_dirty;
97         time_t  dbc_lastref;
98         long    dbc_blksize;
99         char    *dbc_name;
100         LDBM    dbc_db;
101 } DBCache;
102
103 #define MAXDBCACHE      128
104
105 struct ldbminfo {
106         ID                      li_nextid;
107         ldap_pvt_thread_mutex_t         li_nextid_mutex;
108         ldap_pvt_thread_mutex_t         li_root_mutex;
109         ldap_pvt_thread_mutex_t         li_add_mutex;
110         int                     li_mode;
111         slap_index      li_defaultmask;
112         char                    *li_directory;
113         Cache           li_cache;
114         Avlnode                 *li_attrs;
115         int                     li_dblocking;   /* lock databases */
116         int                     li_dbwritesync; /* write sync */
117         int                     li_dbcachesize;
118         DBCache         li_dbcache[MAXDBCACHE];
119         ldap_pvt_thread_mutex_t         li_dbcache_mutex;
120         ldap_pvt_thread_cond_t          li_dbcache_cv;
121 };
122
123 LDAP_END_DECL
124
125 #include "proto-back-ldbm.h"
126
127 #endif /* _back_ldbm_h_ */