]> git.sur5r.net Git - openldap/blob - servers/slapd/back-mdb/back-mdb.h
435fdbff84ec81aa1bd692a0e26bfff2bea76b62
[openldap] / servers / slapd / back-mdb / back-mdb.h
1 /* back-mdb.h - mdb back-end header file */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2017 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
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>.
15  */
16
17 #ifndef _BACK_MDB_H_
18 #define _BACK_MDB_H_
19
20 #include <portable.h>
21 #include "slap.h"
22 #include "lmdb.h"
23
24 LDAP_BEGIN_DECL
25
26 #undef  MDB_TOOL_IDL_CACHING    /* currently no perf gain */
27
28 #define DN_BASE_PREFIX          SLAP_INDEX_EQUALITY_PREFIX
29 #define DN_ONE_PREFIX           '%'
30 #define DN_SUBTREE_PREFIX       '@'
31
32 #define MDB_AD2ID               0
33 #define MDB_DN2ID               1
34 #define MDB_ID2ENTRY    2
35 #define MDB_ID2VAL              3
36 #define MDB_NDB                 4
37
38 /* The default search IDL stack cache depth */
39 #define DEFAULT_SEARCH_STACK_DEPTH      16
40
41 /* The minimum we can function with */
42 #define MINIMUM_SEARCH_STACK_DEPTH      8
43
44 #define MDB_INDICES             128
45
46 #define MDB_MAXADS      65536
47
48 /* Default to 10MB max */
49 #define DEFAULT_MAPSIZE (10*1048576)
50
51 /* Most users will never see this */
52 #define DEFAULT_RTXN_SIZE       10000
53
54 #ifdef LDAP_DEVEL
55 #define MDB_MONITOR_IDX
56 #endif
57
58 typedef struct mdb_monitor_t {
59         void            *mdm_cb;
60         struct berval   mdm_ndn;
61 } mdb_monitor_t;
62
63 /* From ldap_rq.h */
64 struct re_s;
65
66 struct mdb_info {
67         MDB_env         *mi_dbenv;
68
69         /* DB_ENV parameters */
70         char            *mi_dbenv_home;
71         uint32_t        mi_dbenv_flags;
72         int                     mi_dbenv_mode;
73
74         size_t          mi_mapsize;
75         ID                      mi_nextid;
76         size_t          mi_maxentrysize;
77
78         slap_mask_t     mi_defaultmask;
79         int                     mi_nattrs;
80         struct mdb_attrinfo             **mi_attrs;
81         void            *mi_search_stack;
82         int                     mi_search_stack_depth;
83         int                     mi_readers;
84
85         uint32_t        mi_rtxn_size;
86         int                     mi_txn_cp;
87         uint32_t        mi_txn_cp_min;
88         uint32_t        mi_txn_cp_kbyte;
89
90         struct re_s             *mi_txn_cp_task;
91         struct re_s             *mi_index_task;
92
93         mdb_monitor_t   mi_monitor;
94
95 #ifdef MDB_MONITOR_IDX
96         ldap_pvt_thread_mutex_t mi_idx_mutex;
97         Avlnode         *mi_idx;
98 #endif /* MDB_MONITOR_IDX */
99
100         int             mi_flags;
101 #define MDB_IS_OPEN             0x01
102 #define MDB_OPEN_INDEX  0x02
103 #define MDB_DEL_INDEX   0x08
104 #define MDB_RE_OPEN             0x10
105 #define MDB_NEED_UPGRADE        0x20
106
107         int mi_numads;
108
109         unsigned        mi_multi_hi;
110                 /* more than this many values in an attr goes
111                  * into a separate DB */
112         unsigned        mi_multi_lo;
113                 /* less than this many values in an attr goes
114                  * back into main blob */
115
116         MDB_dbi mi_dbis[MDB_NDB];
117         AttributeDescription *mi_ads[MDB_MAXADS];
118         int mi_adxs[MDB_MAXADS];
119 };
120
121 #define mi_id2entry     mi_dbis[MDB_ID2ENTRY]
122 #define mi_dn2id        mi_dbis[MDB_DN2ID]
123 #define mi_ad2id        mi_dbis[MDB_AD2ID]
124 #define mi_id2val       mi_dbis[MDB_ID2VAL]
125
126 typedef struct mdb_op_info {
127         OpExtra         moi_oe;
128         MDB_txn*        moi_txn;
129         int                     moi_ref;
130         char            moi_flag;
131 } mdb_op_info;
132 #define MOI_READER      0x01
133 #define MOI_FREEIT      0x02
134 #define MOI_KEEPER      0x04
135
136 LDAP_END_DECL
137
138 /* for the cache of attribute information (which are indexed, etc.) */
139 typedef struct mdb_attrinfo {
140         AttributeDescription *ai_desc; /* attribute description cn;lang-en */
141         slap_mask_t ai_indexmask;       /* how the attr is indexed      */
142         slap_mask_t ai_newmask; /* new settings to replace old mask */
143 #ifdef LDAP_COMP_MATCH
144         ComponentReference* ai_cr; /*component indexing*/
145 #endif
146         TAvlnode *ai_root;              /* for tools */
147         MDB_cursor *ai_cursor;  /* for tools */
148         int ai_idx;     /* position in AI array */
149         MDB_dbi ai_dbi;
150 } AttrInfo;
151
152 /* tool threaded indexer state */
153 typedef struct mdb_attrixinfo {
154         OpExtra ai_oe;
155         void *ai_flist;
156         void *ai_clist;
157         AttrInfo *ai_ai;
158 } AttrIxInfo;
159
160 /* These flags must not clash with SLAP_INDEX flags or ops in slap.h! */
161 #define MDB_INDEX_DELETING      0x8000U /* index is being modified */
162 #define MDB_INDEX_UPDATE_OP     0x03    /* performing an index update */
163
164 /* For slapindex to record which attrs in an entry belong to which
165  * index database 
166  */
167 typedef struct AttrList {
168         struct AttrList *next;
169         Attribute *attr;
170 } AttrList;
171
172 #ifndef CACHELINE
173 #define CACHELINE       64
174 #endif
175
176 #if defined(__i386) || defined(__x86_64)
177 #define MISALIGNED_OK   1
178 #else
179 #define ALIGNER (sizeof(size_t)-1)
180 #endif
181
182 typedef struct IndexRbody {
183         AttrInfo *ai;
184         AttrList *attrs;
185         void *tptr;
186         int i;
187 } IndexRbody;
188
189 typedef struct IndexRec {
190         union {
191                 IndexRbody irb;
192 #define ir_ai   iru.irb.ai
193 #define ir_attrs        iru.irb.attrs
194 #define ir_tptr iru.irb.tptr
195 #define ir_i    iru.irb.i
196                 /* cache line alignment */
197                 char pad[(sizeof(IndexRbody)+CACHELINE-1) & (!CACHELINE-1)];
198         } iru;
199 } IndexRec;
200
201 #define MAXRDNS SLAP_LDAPDN_MAXLEN/4
202
203 #include "proto-mdb.h"
204
205 #endif /* _BACK_MDB_H_ */