]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/back-ldbm.h
81dca3e949cad7e23fe5022aa537d6e1ebc5b126
[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          '='
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 #define EQ_PREFIX       '='     /* prefix for equality keys     */
37 #define APPROX_PREFIX   '~'     /* prefix for approx keys       */
38 #define SUB_PREFIX      '*'     /* prefix for substring keys    */
39 #define CONT_PREFIX     '\\'    /* prefix for continuation keys */
40
41 /* allow 3 characters per byte + PREFIX + EOS */
42 #define CONT_SIZE ( sizeof(long)*3 + 1 + 1 )
43
44 #define UNKNOWN_PREFIX  '?'     /* prefix for unknown keys    */
45
46 #define DEFAULT_BLOCKSIZE       8192
47
48 /*
49  * This structure represents an id block on disk and an id list
50  * in core.
51  *
52  * The fields have the following meanings:
53  *
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
61  */
62
63 typedef ID ID_BLOCK;
64
65 #define ID_BLOCK_NMAX_OFFSET    0
66 #define ID_BLOCK_NIDS_OFFSET    1
67 #define ID_BLOCK_IDS_OFFSET             2
68
69 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
70
71 #define ID_BLOCK_NMAX(b)                ((b)[ID_BLOCK_NMAX_OFFSET])
72 #define ID_BLOCK_NIDS(b)                ((b)[ID_BLOCK_NIDS_OFFSET])
73 #define ID_BLOCK_ID(b, n)               ((b)[ID_BLOCK_IDS_OFFSET+(n)])
74
75 #define ID_BLOCK_NOID(b, n)             (ID_BLOCK_ID((b),(n)) == NOID)
76
77 #define ID_BLOCK_ALLIDS_VALUE   0
78 #define ID_BLOCK_ALLIDS(b)              (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
79
80 #define ID_BLOCK_INDIRECT_VALUE 0
81 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
82
83 /* for the in-core cache of entries */
84 typedef struct ldbm_cache {
85         int             c_maxsize;
86         int             c_cursize;
87         Avlnode         *c_dntree;
88         Avlnode         *c_idtree;
89         Entry           *c_lruhead;     /* lru - add accessed entries here */
90         Entry           *c_lrutail;     /* lru - rem lru entries from here */
91         ldap_pvt_thread_mutex_t c_mutex;
92 } Cache;
93
94 #define CACHE_READ_LOCK         0
95 #define CACHE_WRITE_LOCK        1
96
97 /* for the cache of open index files */
98 typedef struct ldbm_dbcache {
99         int             dbc_refcnt;
100         int             dbc_maxids;
101         int             dbc_maxindirect;
102         time_t  dbc_lastref;
103         long    dbc_blksize;
104         char    *dbc_name;
105         LDBM    dbc_db;
106 } DBCache;
107
108 #define MAXDBCACHE      16
109
110 struct ldbminfo {
111         ID                      li_nextid;
112         ldap_pvt_thread_mutex_t         li_nextid_mutex;
113         ldap_pvt_thread_mutex_t         li_root_mutex;
114         ldap_pvt_thread_mutex_t         li_add_mutex;
115         int                     li_mode;
116         char                    *li_directory;
117         Cache           li_cache;
118         Avlnode                 *li_attrs;
119         int                     li_dblocking;   /* lock databases */
120         int                     li_dbwritesync; /* write sync */
121         int                     li_dbcachesize;
122         DBCache         li_dbcache[MAXDBCACHE];
123         ldap_pvt_thread_mutex_t         li_dbcache_mutex;
124         ldap_pvt_thread_cond_t          li_dbcache_cv;
125 #if 0
126 #if defined(HAVE_BERKELEY_DB) && DB_VERSION_MAJOR >= 2
127         DB_ENV                      *li_db_env;
128 #endif
129 #endif
130 };
131
132 LDAP_END_DECL
133
134 #include "proto-back-ldbm.h"
135
136 #endif /* _back_ldbm_h_ */