back-bdb.h 3.3 KB
Newer Older
1
/* back-bdb.h - bdb back-end header file */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
2
3
/* $OpenLDAP$ */
/*
Kurt Zeilenga's avatar
Kurt Zeilenga committed
4
 * Copyright 2000-2002 The OpenLDAP Foundation, All Rights Reserved.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
5
6
7
8
9
10
11
12
13
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */

#ifndef _BACK_BDB_H_
#define _BACK_BDB_H_

#include <portable.h>
#include <db.h>

14
15
#include "slap.h"

Kurt Zeilenga's avatar
Kurt Zeilenga committed
16
17
LDAP_BEGIN_DECL

18
#define BDB_FILTER_INDICES 1
Howard Chu's avatar
Howard Chu committed
19
#define BDB_IDL_MULTI		1
20
/* #define BDB_HIER		1 */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
21

Kurt Zeilenga's avatar
Kurt Zeilenga committed
22
23
24
25
#define DN_BASE_PREFIX		SLAP_INDEX_EQUALITY_PREFIX
#define DN_ONE_PREFIX	 	'%'
#define DN_SUBTREE_PREFIX 	'@'

26
27
28
29
30
31
#define DBTzero(t)			(memset((t), 0, sizeof(DBT)))
#define DBT2bv(t,bv)		((bv)->bv_val = (t)->data, \
								(bv)->bv_len = (t)->size)
#define bv2DBT(bv,t)		((t)->data = (bv)->bv_val, \
								(t)->size = (bv)->bv_len )

Kurt Zeilenga's avatar
Kurt Zeilenga committed
32
#define DEFAULT_MODE		0600
Kurt Zeilenga's avatar
Kurt Zeilenga committed
33

Kurt Zeilenga's avatar
Kurt Zeilenga committed
34
35
#define BDB_TXN_RETRIES	16

36
37
38
#ifdef BDB_HIER
#define BDB_DBENV_HOME	LDAP_RUNDIR LDAP_DIRSEP "openldap-hdb"
#else
39
#define BDB_DBENV_HOME	LDAP_RUNDIR LDAP_DIRSEP "openldap-bdb"
40
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
41

42
#ifdef BDB_SUBDIRS
43
44
45
#define BDB_TMP_SUBDIR	LDAP_DIRSEP "tmp"
#define BDB_LG_SUBDIR	LDAP_DIRSEP "log"
#define BDB_DATA_SUBDIR	LDAP_DIRSEP "data"
46
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
47

48
#define BDB_SUFFIX		".bdb"
49
#define BDB_ID2ENTRY	0
50
51
52
#ifdef BDB_HIER
#define BDB_ID2PARENT		1
#else
53
#define BDB_DN2ID		1
54
#endif
55
#define BDB_NDB			2
56

57
58
59
/* The bdb on-disk entry format is pretty space-inefficient. Average
 * sized user entries are 3-4K each. You need at least two entries to
 * fit into a single database page, more is better. 64K is BDB's
60
61
 * upper bound. The same issues arise with IDLs in the index databases,
 * but it's nearly impossible to avoid overflows there.
62
 *
63
64
 * When using BDB_IDL_MULTI, the IDL size is no longer an issue. Smaller
 * pages are better for concurrency.
65
 */
66
67
68
69
#ifndef BDB_ID2ENTRY_PAGESIZE
#define	BDB_ID2ENTRY_PAGESIZE	16384
#endif

70
#ifndef BDB_PAGESIZE
71
72
73
#ifdef BDB_IDL_MULTI
#define	BDB_PAGESIZE	4096	/* BDB's original default */
#else
74
#define	BDB_PAGESIZE	16384
75
#endif
76
#endif
77

78
#define BDB_INDICES		128
79
80

struct bdb_db_info {
81
	char		*bdi_name;
82
83
84
85
86
87
	DB			*bdi_db;
};

struct bdb_info {
	DB_ENV		*bi_dbenv;

88
89
	/* DB_ENV parameters */
	/* The DB_ENV can be tuned via DB_CONFIG */
90
91
92
93
94
	char		*bi_dbenv_home;
	u_int32_t	bi_dbenv_xflags; /* extra flags */
	int			bi_dbenv_mode;

	int			bi_ndatabases;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
95
	struct bdb_db_info **bi_databases;
96
	ldap_pvt_thread_mutex_t	bi_database_mutex;
97
	int		bi_db_opflags;	/* db-specific flags */
98
99
100

	slap_mask_t	bi_defaultmask;
	Avlnode		*bi_attrs;
101
102
103
104
105
106
#ifdef BDB_HIER
	Avlnode		*bi_tree;
	ldap_pvt_thread_rdwr_t	bi_tree_rdwr;
	void		*bi_troot;
	int		bi_nrdns;
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
107

108
	int		bi_txn;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
109
110
111
	int			bi_txn_cp;
	u_int32_t	bi_txn_cp_min;
	u_int32_t	bi_txn_cp_kbyte;
112
113
114
115
116
117

#ifndef NO_THREADS
	int			bi_lock_detect;
	int			bi_lock_detect_seconds;
	ldap_pvt_thread_t	bi_lock_detect_tid;
#endif
118
119

	ID			bi_lastid;
120
	ldap_pvt_thread_mutex_t	bi_lastid_mutex;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
121
};
122

123
#define bi_id2entry	bi_databases[BDB_ID2ENTRY]
124
125
126
#ifdef BDB_HIER
#define bi_id2parent	bi_databases[BDB_ID2PARENT]
#else
Kurt Zeilenga's avatar
Kurt Zeilenga committed
127
#define bi_dn2id	bi_databases[BDB_DN2ID]
128
#endif
Kurt Zeilenga's avatar
Kurt Zeilenga committed
129

130
131
132
133
134
135
struct bdb_op_info {
	BackendDB*	boi_bdb;
	DB_TXN*		boi_txn;
	int			boi_err;
};

136
137
138
139
140
141
142
143
#if DB_VERSION_MAJOR < 4
#define	TXN_CHECKPOINT(env, k, m, f)	txn_checkpoint(env, k, m, f)
#define	LOCK_DETECT(env, f, t, a)	lock_detect(env, f, t, a)
#else
#define	TXN_CHECKPOINT(env, k, m, f)	(env)->txn_checkpoint(env, k, m, f)
#define	LOCK_DETECT(env, f, t, a)	(env)->lock_detect(env, f, t, a)
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
144
145
LDAP_END_DECL

Kurt Zeilenga's avatar
Kurt Zeilenga committed
146
147
#include "proto-bdb.h"

Kurt Zeilenga's avatar
Kurt Zeilenga committed
148
#endif /* _BACK_BDB_H_ */