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