2 #include "system/filesys.h"
3 #include "system/time.h"
5 #include "ldb_module.h"
10 typedef int (*ldb_kv_traverse_fn)(struct ldb_kv_private *ldb_kv,
18 int (*store)(struct ldb_kv_private *ldb_kv,
22 int (*delete)(struct ldb_kv_private *ldb_kv, struct ldb_val key);
23 int (*iterate)(struct ldb_kv_private *ldb_kv,
24 ldb_kv_traverse_fn fn,
26 int (*update_in_iterate)(struct ldb_kv_private *ldb_kv,
31 int (*fetch_and_parse)(struct ldb_kv_private *ldb_kv,
33 int (*parser)(struct ldb_val key,
37 int (*iterate_range)(struct ldb_kv_private *ldb_kv,
38 struct ldb_val start_key,
39 struct ldb_val end_key,
40 ldb_kv_traverse_fn fn,
42 int (*lock_read)(struct ldb_module *);
43 int (*unlock_read)(struct ldb_module *);
44 int (*begin_write)(struct ldb_kv_private *);
45 int (*prepare_write)(struct ldb_kv_private *);
46 int (*abort_write)(struct ldb_kv_private *);
47 int (*finish_write)(struct ldb_kv_private *);
48 int (*error)(struct ldb_kv_private *ldb_kv);
49 const char *(*errorstr)(struct ldb_kv_private *ldb_kv);
50 const char *(*name)(struct ldb_kv_private *ldb_kv);
51 bool (*has_changed)(struct ldb_kv_private *ldb_kv);
52 bool (*transaction_active)(struct ldb_kv_private *ldb_kv);
53 size_t (*get_size)(struct ldb_kv_private *ldb_kv);
54 int (*begin_nested_write)(struct ldb_kv_private *);
55 int (*finish_nested_write)(struct ldb_kv_private *);
56 int (*abort_nested_write)(struct ldb_kv_private *);
59 /* this private structure is used by the key value backends in the
61 struct ldb_kv_private {
62 const struct kv_db_ops *kv_ops;
63 struct ldb_module *module;
65 struct lmdb_private *lmdb_private;
66 unsigned int connect_flags;
68 unsigned long long sequence_number;
69 uint32_t pack_format_version;
70 uint32_t target_pack_format_version;
71 uint32_t pack_format_override;
73 /* the low level tdb seqnum - used to avoid loading BASEINFO when
78 struct ldb_message *indexlist;
79 bool one_level_indexes;
80 bool attribute_indexes;
81 const char *GUID_index_attribute;
82 const char *GUID_index_dn_component;
87 bool disallow_dn_filter;
89 * To improve the performance of batch operations we maintain a cache
90 * of index records, these entries get written to disk in the
91 * prepare_commit phase.
93 struct ldb_kv_idxptr *idxptr;
95 * To ensure that the indexes in idxptr are consistent we cache any
96 * index updates during an operation, i.e. ldb_kv_add, ldb_kv_delete ...
97 * Once the changes to the data record have been commited to disk
98 * the contents of this cache are copied to idxptr
100 struct ldb_kv_idxptr *nested_idx_ptr;
102 * If batch mode is set the sub transactions and index caching
103 * wrapping individual operations is disabled.
104 * This is to improve the performance of large batch operations
109 * Has an operation failed, if true and we're in batch_mode
110 * the transaction commit will fail.
112 bool operation_failed;
114 bool prepared_commit;
124 const struct ldb_schema_syntax *GUID_index_syntax;
127 * Maximum index key length. If non zero keys longer than this length
128 * will be truncated for non unique indexes. Keys for unique indexes
129 * greater than this length will be rejected.
131 unsigned max_key_length;
134 * To allow testing that ensures the DB does not fall back
137 bool disable_full_db_scan;
140 * The PID that opened this database so we don't work in a
146 * The size to be used for the index transaction cache
148 size_t index_transaction_cache_size;
151 struct ldb_kv_context {
152 struct ldb_module *module;
153 struct ldb_request *req;
156 * Required as we might not get to the event loop before the
157 * timeout, so we need some old-style cooperative multitasking
160 struct timeval timeout_timeval;
162 /* Used to throttle calls to gettimeofday() */
163 size_t timeout_counter;
165 bool request_terminated;
166 struct ldb_kv_req_spy *spy;
169 const struct ldb_parse_tree *tree;
171 enum ldb_scope scope;
172 const char * const *attrs;
173 struct tevent_timer *timeout_event;
179 struct ldb_kv_reindex_context {
184 struct ldb_kv_repack_context {
187 bool normal_record_seen;
188 uint32_t old_version;
192 /* special record types */
193 #define LDB_KV_INDEX "@INDEX"
194 #define LDB_KV_INDEXLIST "@INDEXLIST"
195 #define LDB_KV_IDX "@IDX"
196 #define LDB_KV_IDXVERSION "@IDXVERSION"
197 #define LDB_KV_IDXATTR "@IDXATTR"
198 #define LDB_KV_IDXONE "@IDXONE"
199 #define LDB_KV_IDXDN "@IDXDN"
200 #define LDB_KV_IDXGUID "@IDXGUID"
201 #define LDB_KV_IDX_DN_GUID "@IDX_DN_GUID"
204 * This will be used to indicate when a new, yet to be developed
205 * sub-database version of the indicies are in use, to ensure we do
206 * not load future databases unintentionally.
209 #define LDB_KV_IDX_LMDB_SUBDB "@IDX_LMDB_SUBDB"
211 #define LDB_KV_BASEINFO "@BASEINFO"
212 #define LDB_KV_OPTIONS "@OPTIONS"
213 #define LDB_KV_ATTRIBUTES "@ATTRIBUTES"
215 /* special attribute types */
216 #define LDB_KV_SEQUENCE_NUMBER "sequenceNumber"
217 #define LDB_KV_CHECK_BASE "checkBaseOnSearch"
218 #define LDB_KV_DISALLOW_DN_FILTER "disallowDNFilter"
219 #define LDB_KV_MOD_TIMESTAMP "whenChanged"
220 #define LDB_KV_OBJECTCLASS "objectClass"
223 #define LDB_KV_GUID_KEY_PREFIX "GUID="
224 #define LDB_KV_GUID_SIZE 16
225 #define LDB_KV_GUID_KEY_SIZE (LDB_KV_GUID_SIZE + sizeof(LDB_KV_GUID_KEY_PREFIX) - 1)
229 * This allows pointers to be referenced after the callback to any variant of
230 * iterate or fetch_and_parse -- as long as an overall read lock is held.
232 #define LDB_KV_OPTION_STABLE_READ_LOCK 0x00000001
235 * The following definitions come from lib/ldb/ldb_key_value/ldb_kv_cache.c
238 int ldb_kv_cache_reload(struct ldb_module *module);
239 int ldb_kv_cache_load(struct ldb_module *module);
240 int ldb_kv_increase_sequence_number(struct ldb_module *module);
241 int ldb_kv_check_at_attributes_values(const struct ldb_val *value);
244 * The following definitions come from lib/ldb/ldb_key_value/ldb_kv_index.c
248 * The default size of the in memory TDB used to cache index records
249 * The value chosen gives a prime modulo for the hash table and keeps the
250 * tdb memory overhead under 4 kB
252 #define DEFAULT_INDEX_CACHE_SIZE 491
254 struct ldb_parse_tree;
256 int ldb_kv_search_indexed(struct ldb_kv_context *ctx, uint32_t *);
257 int ldb_kv_index_add_new(struct ldb_module *module,
258 struct ldb_kv_private *ldb_kv,
259 const struct ldb_message *msg);
260 int ldb_kv_index_delete(struct ldb_module *module,
261 const struct ldb_message *msg);
262 int ldb_kv_index_del_element(struct ldb_module *module,
263 struct ldb_kv_private *ldb_kv,
264 const struct ldb_message *msg,
265 struct ldb_message_element *el);
266 int ldb_kv_index_add_element(struct ldb_module *module,
267 struct ldb_kv_private *ldb_kv,
268 const struct ldb_message *msg,
269 struct ldb_message_element *el);
270 int ldb_kv_index_del_value(struct ldb_module *module,
271 struct ldb_kv_private *ldb_kv,
272 const struct ldb_message *msg,
273 struct ldb_message_element *el,
275 int ldb_kv_reindex(struct ldb_module *module);
276 int ldb_kv_repack(struct ldb_module *module);
277 int ldb_kv_index_transaction_start(
278 struct ldb_module *module,
280 int ldb_kv_index_transaction_commit(struct ldb_module *module);
281 int ldb_kv_index_transaction_cancel(struct ldb_module *module);
282 int ldb_kv_key_dn_from_idx(struct ldb_module *module,
283 struct ldb_kv_private *ldb_kv,
286 struct ldb_val *key);
289 * The following definitions come from lib/ldb/ldb_key_value/ldb_kv_search.c
291 int ldb_kv_search_dn1(struct ldb_module *module,
293 struct ldb_message *msg,
294 unsigned int unpack_flags);
295 int ldb_kv_search_base(struct ldb_module *module,
298 struct ldb_dn **ret_dn);
299 int ldb_kv_search_key(struct ldb_module *module,
300 struct ldb_kv_private *ldb_kv,
301 const struct ldb_val ldb_key,
302 struct ldb_message *msg,
303 unsigned int unpack_flags);
304 int ldb_kv_filter_attrs_in_place(struct ldb_message *msg,
305 const char *const *attrs);
306 int ldb_kv_search(struct ldb_kv_context *ctx);
309 * The following definitions come from lib/ldb/ldb_key_value/ldb_kv.c */
311 * Determine if this key could hold a normal record. We allow the new
312 * GUID index, the old DN index and a possible future ID= but not
315 bool ldb_kv_key_is_normal_record(struct ldb_val key);
316 struct ldb_val ldb_kv_key_dn(TALLOC_CTX *mem_ctx,
318 struct ldb_val ldb_kv_key_msg(struct ldb_module *module,
320 const struct ldb_message *msg);
321 int ldb_kv_guid_to_key(const struct ldb_val *GUID_val,
322 struct ldb_val *key);
323 int ldb_kv_idx_to_key(struct ldb_module *module,
324 struct ldb_kv_private *ldb_kv,
326 const struct ldb_val *idx_val,
327 struct ldb_val *key);
328 int ldb_kv_store(struct ldb_module *module,
329 const struct ldb_message *msg,
331 int ldb_kv_modify_internal(struct ldb_module *module,
332 const struct ldb_message *msg,
333 struct ldb_request *req);
334 int ldb_kv_delete_noindex(struct ldb_module *module,
335 const struct ldb_message *msg);
336 int ldb_kv_init_store(struct ldb_kv_private *ldb_kv,
338 struct ldb_context *ldb,
339 const char *options[],
340 struct ldb_module **_module);
341 int ldb_kv_index_sub_transaction_start(struct ldb_kv_private *ldb_kv);
342 int ldb_kv_index_sub_transaction_cancel(struct ldb_kv_private *ldb_kv);
343 int ldb_kv_index_sub_transaction_commit(struct ldb_kv_private *ldb_kv);
344 #endif /* __LDB_KV_H__ */