]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/proto-bdb.h
adaptive caching implementation
[openldap] / servers / slapd / back-bdb / proto-bdb.h
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 2000-2004 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15
16 #ifndef _PROTO_BDB_H
17 #define _PROTO_BDB_H
18
19 LDAP_BEGIN_DECL
20
21 #ifdef BDB_HIER
22 #define BDB_SYMBOL(x)   LDAP_CONCAT(hdb_,x)
23 #define BDB_UCTYPE      "HDB"
24 #else
25 #define BDB_SYMBOL(x)   LDAP_CONCAT(bdb_,x)
26 #define BDB_UCTYPE      "BDB"
27 #endif
28
29 /*
30  * attr.c
31  */
32
33 #define bdb_attr_mask                           BDB_SYMBOL(attr_mask)
34 #define bdb_attr_index_config           BDB_SYMBOL(attr_index_config)
35 #define bdb_attr_index_destroy          BDB_SYMBOL(attr_index_destroy)
36
37 void bdb_attr_mask( struct bdb_info *bdb,
38         AttributeDescription *desc,
39         slap_mask_t *indexmask );
40
41 int bdb_attr_index_config LDAP_P(( struct bdb_info *bdb,
42         const char *fname, int lineno,
43         int argc, char **argv ));
44
45 void bdb_attr_index_destroy LDAP_P(( Avlnode *tree ));
46
47 /*
48  * ctxcsn.c
49  */
50 #define bdb_csn_commit                          BDB_SYMBOL(csn_commit)
51 #define bdb_get_commit_csn                      BDB_SYMBOL(get_commit_csn)
52
53 int bdb_csn_commit LDAP_P(( Operation *op, SlapReply *rs, DB_TXN *tid,
54                                                 EntryInfo *ei, EntryInfo **suffix_ei, Entry **ctxcsn_e,
55                                                 int *ctxcsn_added, u_int32_t locker ));
56
57 int bdb_get_commit_csn LDAP_P(( Operation *op, SlapReply *rs,
58                                                 struct berval **search_context_csn,
59                                                 u_int32_t locker, DB_LOCK *ctxcsn_lock ));
60
61 /*
62  * dbcache.c
63  */
64 #define bdb_db_cache                            BDB_SYMBOL(db_cache)
65
66 int
67 bdb_db_cache(
68     Backend     *be,
69     const char *name,
70         DB **db );
71
72 /*
73  * dn2entry.c
74  */
75 #define bdb_dn2entry                            BDB_SYMBOL(dn2entry)
76
77 int bdb_dn2entry LDAP_P(( Operation *op, DB_TXN *tid,
78         struct berval *dn, EntryInfo **e, int matched,
79         u_int32_t locker, DB_LOCK *lock ));
80
81 /*
82  * dn2id.c
83  */
84 #define bdb_dn2id                                       BDB_SYMBOL(dn2id)
85 #define bdb_dn2id_add                           BDB_SYMBOL(dn2id_add)
86 #define bdb_dn2id_delete                        BDB_SYMBOL(dn2id_delete)
87 #define bdb_dn2id_children                      BDB_SYMBOL(dn2id_children)
88 #define bdb_dn2idl                                      BDB_SYMBOL(dn2idl)
89
90 int bdb_dn2id(
91         Operation *op,
92         DB_TXN *tid,
93         struct berval *dn,
94         EntryInfo *ei );
95
96 int bdb_dn2id_add(
97         Operation *op,
98         DB_TXN *tid,
99         EntryInfo *eip,
100         Entry *e );
101
102 int bdb_dn2id_delete(
103         Operation *op,
104         DB_TXN *tid,
105         EntryInfo *eip,
106         Entry *e );
107
108 int bdb_dn2id_children(
109         Operation *op,
110         DB_TXN *tid,
111         Entry *e );
112
113 int bdb_dn2idl(
114         Operation *op,
115         Entry *e,
116         ID *ids,
117         ID *stack );
118
119 #ifdef BDB_HIER
120 #define bdb_dn2id_parent                        BDB_SYMBOL(dn2id_parent)
121 #define bdb_dup_compare                         BDB_SYMBOL(dup_compare)
122 #define bdb_fix_dn                                      BDB_SYMBOL(fix_dn)
123
124 int bdb_dn2id_parent(
125         Operation *op,
126         DB_TXN *txn,
127         EntryInfo *ei,
128         ID *idp );
129
130 int bdb_dup_compare(
131         DB *db,
132         const DBT *usrkey,
133         const DBT *curkey );
134
135 int bdb_fix_dn( Entry *e, int checkit );
136 #endif
137
138
139 /*
140  * error.c
141  */
142 #define bdb_errcall                                     BDB_SYMBOL(errcall)
143
144 #if DB_VERSION_FULL < 0x04030000
145 void bdb_errcall( const char *pfx, char * msg );
146 #else
147 void bdb_errcall( const DB_ENV *env, const char *pfx, const char * msg );
148 #endif
149
150 #ifdef HAVE_EBCDIC
151 #define ebcdic_dberror                          BDB_SYMBOL(ebcdic_dberror)
152
153 char *ebcdic_dberror( int rc );
154 #define db_strerror(x)  ebcdic_dberror(x)
155 #endif
156
157 /*
158  * filterentry.c
159  */
160 #define bdb_filter_candidates           BDB_SYMBOL(filter_candidates)
161
162 int bdb_filter_candidates(
163         Operation *op,
164         Filter  *f,
165         ID *ids,
166         ID *tmp,
167         ID *stack );
168
169 /*
170  * id2entry.c
171  */
172 #define bdb_id2entry                            BDB_SYMBOL(id2entry)
173 #define bdb_id2entry_add                        BDB_SYMBOL(id2entry_add)
174 #define bdb_id2entry_update                     BDB_SYMBOL(id2entry_update)
175 #define bdb_id2entry_delete                     BDB_SYMBOL(id2entry_delete)
176
177 int bdb_id2entry_add(
178         BackendDB *be,
179         DB_TXN *tid,
180         Entry *e );
181
182 int bdb_id2entry_update(
183         BackendDB *be,
184         DB_TXN *tid,
185         Entry *e );
186
187 int bdb_id2entry_delete(
188         BackendDB *be,
189         DB_TXN *tid,
190         Entry *e);
191
192 #ifdef SLAP_ZONE_ALLOC
193 #else
194 int bdb_id2entry(
195         BackendDB *be,
196         DB_TXN *tid,
197         ID id,
198         Entry **e);
199 #endif
200
201 #define bdb_entry_free                          BDB_SYMBOL(entry_free)
202 #define bdb_entry_return                        BDB_SYMBOL(entry_return)
203 #define bdb_entry_release                       BDB_SYMBOL(entry_release)
204 #define bdb_entry_get                           BDB_SYMBOL(entry_get)
205
206 void bdb_entry_free ( Entry *e );
207 #ifdef SLAP_ZONE_ALLOC
208 int bdb_entry_return( struct bdb_info *bdb, Entry *e, int seqno );
209 #else
210 int bdb_entry_return( Entry *e );
211 #endif
212 BI_entry_release_rw bdb_entry_release;
213 BI_entry_get_rw bdb_entry_get;
214
215
216 /*
217  * idl.c
218  */
219
220 #define bdb_idl_cache_get                       BDB_SYMBOL(idl_cache_get)
221 #define bdb_idl_cache_put                       BDB_SYMBOL(idl_cache_put)
222 #define bdb_idl_cache_del                       BDB_SYMBOL(idl_cache_del)
223
224 int bdb_idl_cache_get(
225         struct bdb_info *bdb,
226         DB *db,
227         DBT *key,
228         ID *ids );
229
230 void
231 bdb_idl_cache_put(
232         struct bdb_info *bdb,
233         DB              *db,
234         DBT             *key,
235         ID              *ids,
236         int             rc );
237
238 void
239 bdb_idl_cache_del(
240         struct bdb_info *bdb,
241         DB              *db,
242         DBT             *key );
243
244 #define bdb_idl_first                           BDB_SYMBOL(idl_first)
245 #define bdb_idl_next                            BDB_SYMBOL(idl_next)
246 #define bdb_idl_search                          BDB_SYMBOL(idl_search)
247 #define bdb_idl_insert                          BDB_SYMBOL(idl_insert)
248 #define bdb_idl_intersection            BDB_SYMBOL(idl_intersection)
249 #define bdb_idl_union                           BDB_SYMBOL(idl_union)
250
251 #define bdb_idl_fetch_key                       BDB_SYMBOL(idl_fetch_key)
252 #define bdb_idl_insert_key                      BDB_SYMBOL(idl_insert_key)
253 #define bdb_idl_delete_key                      BDB_SYMBOL(idl_delete_key)
254
255 unsigned bdb_idl_search( ID *ids, ID id );
256
257 int bdb_idl_fetch_key(
258         BackendDB       *be,
259         DB                      *db,
260         DB_TXN          *tid,
261         DBT                     *key,
262         ID                      *ids,
263         DBC                     **saved_cursor,
264         int                     get_flag );
265
266 int bdb_idl_insert( ID *ids, ID id );
267
268 int bdb_idl_insert_key(
269         BackendDB *be,
270         DB *db,
271         DB_TXN *txn,
272         DBT *key,
273         ID id );
274
275 int bdb_idl_delete_key(
276         BackendDB *be,
277         DB *db,
278         DB_TXN *txn,
279         DBT *key,
280         ID id );
281
282 int
283 bdb_idl_intersection(
284         ID *a,
285         ID *b );
286
287 int
288 bdb_idl_union(
289         ID *a,
290         ID *b );
291
292 ID bdb_idl_first( ID *ids, ID *cursor );
293 ID bdb_idl_next( ID *ids, ID *cursor );
294
295
296 #define bdb_bt_compare                          BDB_SYMBOL(bt_compare)
297
298 int bdb_bt_compare(
299         DB *db,
300         const DBT *a,
301         const DBT *b );
302
303
304 /*
305  * index.c
306  */
307 #define bdb_index_is_indexed            BDB_SYMBOL(index_is_indexed)
308 #define bdb_index_param                         BDB_SYMBOL(index_param)
309 #define bdb_index_values                        BDB_SYMBOL(index_values)
310 #define bdb_index_entry                         BDB_SYMBOL(index_entry)
311
312 extern int
313 bdb_index_is_indexed LDAP_P((
314         Backend *be,
315         AttributeDescription *desc ));
316
317 extern int
318 bdb_index_param LDAP_P((
319         Backend *be,
320         AttributeDescription *desc,
321         int ftype,
322         DB **db,
323         slap_mask_t *mask,
324         struct berval *prefix ));
325
326 extern int
327 bdb_index_values LDAP_P((
328         Operation *op,
329         DB_TXN *txn,
330         AttributeDescription *desc,
331         BerVarray vals,
332         ID id,
333         int opid ));
334
335 int bdb_index_entry LDAP_P(( Operation *op, DB_TXN *t, int r, Entry *e ));
336
337 #define bdb_index_entry_add(op,t,e) \
338         bdb_index_entry((op),(t),SLAP_INDEX_ADD_OP,(e))
339 #define bdb_index_entry_del(op,t,e) \
340         bdb_index_entry((op),(t),SLAP_INDEX_DELETE_OP,(e))
341
342 /*
343  * init.c
344  */
345 #define bdb_uuid                                        BDB_SYMBOL(uuid)
346
347 extern struct berval bdb_uuid;
348
349 /*
350  * key.c
351  */
352 #define bdb_key_read                            BDB_SYMBOL(key_read)
353 #define bdb_key_change                          BDB_SYMBOL(key_change)
354
355 extern int
356 bdb_key_read(
357     Backend     *be,
358         DB *db,
359         DB_TXN *txn,
360     struct berval *k,
361         ID *ids,
362     DBC **saved_cursor,
363         int get_flags );
364
365 extern int
366 bdb_key_change(
367     Backend      *be,
368     DB *db,
369         DB_TXN *txn,
370     struct berval *k,
371     ID id,
372     int op );
373         
374 /*
375  * nextid.c
376  */
377 #define bdb_next_id                                     BDB_SYMBOL(next_id)
378 #define bdb_last_id                                     BDB_SYMBOL(last_id)
379
380 int bdb_next_id( BackendDB *be, DB_TXN *tid, ID *id );
381 int bdb_last_id( BackendDB *be, DB_TXN *tid );
382
383 /*
384  * modify.c
385  */
386 #define bdb_modify_internal                     BDB_SYMBOL(modify_internal)
387
388 int bdb_modify_internal(
389         Operation *op,
390         DB_TXN *tid,
391         Modifications *modlist,
392         Entry *e,
393         const char **text,
394         char *textbuf,
395         size_t textlen );
396
397
398 /*
399  * cache.c
400  */
401 #define bdb_cache_entry_db_unlock       BDB_SYMBOL(cache_entry_db_unlock)
402
403 #define bdb_cache_entryinfo_lock(e) \
404         ldap_pvt_thread_mutex_lock( &(e)->bei_kids_mutex )
405 #define bdb_cache_entryinfo_unlock(e) \
406         ldap_pvt_thread_mutex_unlock( &(e)->bei_kids_mutex )
407
408 /* What a mess. Hopefully the current cache scheme will stabilize
409  * and we can trim out all of this stuff.
410  */
411 #if 0
412 void bdb_cache_return_entry_rw( DB_ENV *env, Cache *cache, Entry *e,
413         int rw, DB_LOCK *lock );
414 #else
415 #define bdb_cache_return_entry_rw( env, cache, e, rw, lock ) \
416         bdb_cache_entry_db_unlock( env, lock )
417 #define bdb_cache_return_entry( env, lock ) \
418         bdb_cache_entry_db_unlock( env, lock )
419 #endif
420 #define bdb_cache_return_entry_r(env, c, e, l) \
421         bdb_cache_return_entry_rw((env), (c), (e), 0, (l))
422 #define bdb_cache_return_entry_w(env, c, e, l) \
423         bdb_cache_return_entry_rw((env), (c), (e), 1, (l))
424 #if 0
425 void bdb_unlocked_cache_return_entry_rw( Cache *cache, Entry *e, int rw );
426 #else
427 #define bdb_unlocked_cache_return_entry_rw( a, b, c )
428 #endif
429 #define bdb_unlocked_cache_return_entry_r( c, e ) \
430         bdb_unlocked_cache_return_entry_rw((c), (e), 0)
431 #define bdb_unlocked_cache_return_entry_w( c, e ) \
432         bdb_unlocked_cache_return_entry_rw((c), (e), 1)
433
434 #define bdb_cache_add                           BDB_SYMBOL(cache_add)
435 #define bdb_cache_children                      BDB_SYMBOL(cache_children)
436 #define bdb_cache_delete                        BDB_SYMBOL(cache_delete)
437 #define bdb_cache_delete_cleanup        BDB_SYMBOL(cache_delete_cleanup)
438 #define bdb_cache_find_id                       BDB_SYMBOL(cache_find_id)
439 #define bdb_cache_find_info                     BDB_SYMBOL(cache_find_info)
440 #define bdb_cache_find_ndn                      BDB_SYMBOL(cache_find_ndn)
441 #define bdb_cache_modify                        BDB_SYMBOL(cache_modify)
442 #define bdb_cache_modrdn                        BDB_SYMBOL(cache_modrdn)
443 #define bdb_cache_release_all           BDB_SYMBOL(cache_release_all)
444 #define bdb_cache_delete_entry          BDB_SYMBOL(cache_delete_entry)
445
446 int bdb_cache_children(
447         Operation *op,
448         DB_TXN *txn,
449         Entry *e
450 );
451 int bdb_cache_add(
452         struct bdb_info *bdb,
453         EntryInfo *pei,
454         Entry   *e,
455         struct berval *nrdn,
456         u_int32_t locker
457 );
458 int bdb_cache_modrdn(
459         Entry   *e,
460         struct berval *nrdn,
461         Entry   *new,
462         EntryInfo *ein,
463         DB_ENV *env,
464         u_int32_t locker,
465         DB_LOCK *lock
466 );
467 int bdb_cache_modify(
468         Entry *e,
469         Attribute *newAttrs,
470         DB_ENV *env,
471         u_int32_t locker,
472         DB_LOCK *lock
473 );
474 int bdb_cache_find_ndn(
475         Operation *op,
476         DB_TXN  *txn,
477         struct berval   *ndn,
478         EntryInfo       **res
479 );
480 EntryInfo * bdb_cache_find_info(
481         struct bdb_info *bdb,
482         ID id
483 );
484 int bdb_cache_find_id(
485         Operation *op,
486         DB_TXN  *tid,
487         ID              id,
488         EntryInfo **eip,
489         int     islocked,
490         u_int32_t       locker,
491         DB_LOCK         *lock
492 );
493 int bdb_cache_delete(
494         Cache   *cache,
495         Entry   *e,
496         DB_ENV  *env,
497         u_int32_t locker,
498         DB_LOCK *lock
499 );
500 void bdb_cache_delete_cleanup(
501         Cache   *cache,
502         EntryInfo *ei
503 );
504 void bdb_cache_release_all( Cache *cache );
505 void bdb_cache_delete_entry(
506         struct bdb_info *bdb,
507         EntryInfo *ei,
508         u_int32_t locker,
509         DB_LOCK *lock
510 );
511
512 #ifdef BDB_HIER
513 int hdb_cache_load(
514         struct bdb_info *bdb,
515         EntryInfo *ei,
516         EntryInfo **res
517 );
518 #endif
519
520 #define bdb_cache_entry_db_relock               BDB_SYMBOL(cache_entry_db_relock)
521 int bdb_cache_entry_db_relock(
522         DB_ENV *env,
523         u_int32_t locker,
524         EntryInfo *ei,
525         int rw,
526         int tryOnly,
527         DB_LOCK *lock );
528
529 int bdb_cache_entry_db_unlock(
530         DB_ENV *env,
531         DB_LOCK *lock );
532
533 #ifdef BDB_REUSE_LOCKERS
534
535 #define bdb_locker_id                           BDB_SYMBOL(locker_id)
536 int bdb_locker_id( Operation *op, DB_ENV *env, int *locker );
537
538 #define LOCK_ID_FREE(env, locker)
539 #define LOCK_ID(env, locker)    bdb_locker_id(op, env, locker)
540
541 #else
542
543 #define LOCK_ID_FREE(env, locker)       XLOCK_ID_FREE(env, locker)
544 #define LOCK_ID(env, locker)            XLOCK_ID(env, locker)
545
546 #endif
547
548 /*
549  * search.c
550  */
551
552 #define bdb_abandon                                     BDB_SYMBOL(abandon)
553 #define bdb_cancel                                      BDB_SYMBOL(cancel)
554 #define bdb_do_search                           BDB_SYMBOL(do_search)
555 #define bdb_psearch                             BDB_SYMBOL(psearch)
556
557 BI_op_abandon bdb_abandon;
558 BI_op_cancel bdb_cancel;
559
560 int bdb_psearch(
561         Operation       *op,
562         SlapReply       *rs,
563         Operation       *ps_op,
564         Entry           *entry,
565         int             psearch_type
566 );
567
568 int bdb_do_search(
569         Operation       *op,
570         SlapReply       *rs,
571         Operation       *ps_op,
572         Entry           *entry,
573         int             psearch_type
574 );
575
576 /*
577  * trans.c
578  */
579 #define bdb_trans_backoff                       BDB_SYMBOL(trans_backoff)
580
581 void
582 bdb_trans_backoff( int num_retries );
583
584 /*
585  * former external.h
586  */
587
588 #define bdb_back_initialize             BDB_SYMBOL(back_initialize)
589 #define bdb_db_config                   BDB_SYMBOL(db_config)
590 #define bdb_add                         BDB_SYMBOL(add)
591 #define bdb_bind                        BDB_SYMBOL(bind)
592 #define bdb_compare                     BDB_SYMBOL(compare)
593 #define bdb_delete                      BDB_SYMBOL(delete)
594 #define bdb_modify                      BDB_SYMBOL(modify)
595 #define bdb_modrdn                      BDB_SYMBOL(modrdn)
596 #define bdb_search                      BDB_SYMBOL(search)
597 #define bdb_extended                    BDB_SYMBOL(extended)
598 #define bdb_referrals                   BDB_SYMBOL(referrals)
599 #define bdb_operational                 BDB_SYMBOL(operational)
600 #define bdb_hasSubordinates             BDB_SYMBOL(hasSubordinates)
601 #define bdb_tool_entry_open             BDB_SYMBOL(tool_entry_open)
602 #define bdb_tool_entry_close            BDB_SYMBOL(tool_entry_close)
603 #define bdb_tool_entry_next             BDB_SYMBOL(tool_entry_next)
604 #define bdb_tool_entry_get              BDB_SYMBOL(tool_entry_get)
605 #define bdb_tool_entry_put              BDB_SYMBOL(tool_entry_put)
606 #define bdb_tool_entry_reindex          BDB_SYMBOL(tool_entry_reindex)
607 #define bdb_tool_dn2id_get              BDB_SYMBOL(tool_dn2id_get)
608 #define bdb_tool_id2entry_get           BDB_SYMBOL(tool_id2entry_get)
609 #define bdb_tool_entry_modify           BDB_SYMBOL(tool_entry_modify)
610
611 extern BI_init                          bdb_back_initialize;
612
613 extern BI_db_config                     bdb_db_config;
614
615 extern BI_op_add                        bdb_add;
616 extern BI_op_bind                       bdb_bind;
617 extern BI_op_compare                    bdb_compare;
618 extern BI_op_delete                     bdb_delete;
619 extern BI_op_modify                     bdb_modify;
620 extern BI_op_modrdn                     bdb_modrdn;
621 extern BI_op_search                     bdb_search;
622 extern BI_op_extended                   bdb_extended;
623
624 extern BI_chk_referrals                 bdb_referrals;
625
626 extern BI_operational                   bdb_operational;
627
628 extern BI_has_subordinates              bdb_hasSubordinates;
629
630 /* tools.c */
631 extern BI_tool_entry_open               bdb_tool_entry_open;
632 extern BI_tool_entry_close              bdb_tool_entry_close;
633 extern BI_tool_entry_next               bdb_tool_entry_next;
634 extern BI_tool_entry_get                bdb_tool_entry_get;
635 extern BI_tool_entry_put                bdb_tool_entry_put;
636 extern BI_tool_entry_reindex            bdb_tool_entry_reindex;
637 extern BI_tool_dn2id_get                bdb_tool_dn2id_get;
638 extern BI_tool_id2entry_get             bdb_tool_id2entry_get;
639 extern BI_tool_entry_modify             bdb_tool_entry_modify;
640
641 LDAP_END_DECL
642
643 #endif /* _PROTO_BDB_H */