1999-08-07 07:07:46 +08:00
|
|
|
/* back-ldbm.h - ldap ldbm back-end header file */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-29 05:08:20 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2004-01-02 03:15:16 +08:00
|
|
|
* Copyright 1998-2004 The OpenLDAP Foundation.
|
2003-11-29 05:08:20 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
1999-08-05 07:59:13 +08:00
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
#ifndef _BACK_LDBM_H_
|
|
|
|
#define _BACK_LDBM_H_
|
|
|
|
|
|
|
|
#include "ldbm.h"
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
LDAP_BEGIN_DECL
|
|
|
|
|
2003-07-15 08:55:58 +08:00
|
|
|
#define LDBM_SUBENTRIES 1
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#define DEFAULT_CACHE_SIZE 1000
|
1998-09-03 08:50:13 +08:00
|
|
|
|
2000-05-26 13:47:02 +08:00
|
|
|
#if defined(HAVE_BERKELEY_DB) && DB_VERSION_MAJOR >= 2
|
1998-09-03 08:50:13 +08:00
|
|
|
# define DEFAULT_DBCACHE_SIZE (100 * DEFAULT_DB_PAGE_SIZE)
|
|
|
|
#else
|
|
|
|
# define DEFAULT_DBCACHE_SIZE 100000
|
|
|
|
#endif
|
|
|
|
|
2000-06-05 06:59:38 +08:00
|
|
|
#define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX
|
|
|
|
#define DN_ONE_PREFIX '%'
|
|
|
|
#define DN_SUBTREE_PREFIX '@'
|
1999-08-13 08:55:08 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
1999-08-08 05:14:24 +08:00
|
|
|
* there is a single index for each attribute. these prefixes ensure
|
1998-08-09 08:43:13 +08:00
|
|
|
* that there is no collision among keys.
|
|
|
|
*/
|
|
|
|
|
2000-06-05 06:59:38 +08:00
|
|
|
/* allow PREFIX + byte for continuate number */
|
|
|
|
#define SLAP_INDEX_CONT_SIZE ( sizeof(SLAP_INDEX_CONT_PREFIX) + sizeof(unsigned char) )
|
1998-12-28 08:44:15 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#define DEFAULT_BLOCKSIZE 8192
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This structure represents an id block on disk and an id list
|
|
|
|
* in core.
|
|
|
|
*
|
|
|
|
* The fields have the following meanings:
|
|
|
|
*
|
|
|
|
* b_nmax maximum number of ids in this block. if this is == ALLIDSBLOCK,
|
|
|
|
* then this block represents all ids.
|
|
|
|
* b_nids current number of ids in use in this block. if this
|
|
|
|
* is == INDBLOCK, then this block is an indirect block
|
|
|
|
* containing a list of other blocks containing actual ids.
|
|
|
|
* the list is terminated by an id of NOID.
|
|
|
|
* b_ids a list of the actual ids themselves
|
|
|
|
*/
|
1999-01-31 15:55:53 +08:00
|
|
|
|
1999-02-03 03:26:00 +08:00
|
|
|
typedef ID ID_BLOCK;
|
|
|
|
|
|
|
|
#define ID_BLOCK_NMAX_OFFSET 0
|
|
|
|
#define ID_BLOCK_NIDS_OFFSET 1
|
|
|
|
#define ID_BLOCK_IDS_OFFSET 2
|
|
|
|
|
|
|
|
/* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
|
|
|
|
|
|
|
|
#define ID_BLOCK_NMAX(b) ((b)[ID_BLOCK_NMAX_OFFSET])
|
2001-09-22 14:52:32 +08:00
|
|
|
|
|
|
|
/* Use this macro to get the value, but not to set it.
|
|
|
|
* By default this is identical to above.
|
|
|
|
*/
|
|
|
|
#define ID_BLOCK_NMAXN(b) ID_BLOCK_NMAX(b)
|
1999-02-03 03:26:00 +08:00
|
|
|
#define ID_BLOCK_NIDS(b) ((b)[ID_BLOCK_NIDS_OFFSET])
|
|
|
|
#define ID_BLOCK_ID(b, n) ((b)[ID_BLOCK_IDS_OFFSET+(n)])
|
|
|
|
|
|
|
|
#define ID_BLOCK_NOID(b, n) (ID_BLOCK_ID((b),(n)) == NOID)
|
|
|
|
|
|
|
|
#define ID_BLOCK_ALLIDS_VALUE 0
|
|
|
|
#define ID_BLOCK_ALLIDS(b) (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
|
|
|
|
|
|
|
|
#define ID_BLOCK_INDIRECT_VALUE 0
|
|
|
|
#define ID_BLOCK_INDIRECT(b) (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2002-01-14 06:25:51 +08:00
|
|
|
#define USE_INDIRECT_NIDS 1
|
|
|
|
|
2001-09-22 14:52:32 +08:00
|
|
|
#ifdef USE_INDIRECT_NIDS
|
|
|
|
/*
|
|
|
|
* Use the high bit of ID_BLOCK_NMAX to indicate an INDIRECT block, thus
|
|
|
|
* freeing up the ID_BLOCK_NIDS to store an actual count. This allows us
|
|
|
|
* to use binary search on INDIRECT blocks.
|
|
|
|
*/
|
|
|
|
#undef ID_BLOCK_NMAXN
|
|
|
|
#define ID_BLOCK_NMAXN(b) ((b)[ID_BLOCK_NMAX_OFFSET]&0x7fffffff)
|
|
|
|
#undef ID_BLOCK_INDIRECT_VALUE
|
|
|
|
#define ID_BLOCK_INDIRECT_VALUE 0x80000000
|
|
|
|
#undef ID_BLOCK_INDIRECT
|
|
|
|
#define ID_BLOCK_INDIRECT(b) (ID_BLOCK_NMAX(b) & ID_BLOCK_INDIRECT_VALUE)
|
|
|
|
|
|
|
|
#endif /* USE_INDIRECT_NIDS */
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/* for the in-core cache of entries */
|
1999-07-20 03:40:33 +08:00
|
|
|
typedef struct ldbm_cache {
|
1998-08-09 08:43:13 +08:00
|
|
|
int c_maxsize;
|
|
|
|
int c_cursize;
|
|
|
|
Avlnode *c_dntree;
|
|
|
|
Avlnode *c_idtree;
|
|
|
|
Entry *c_lruhead; /* lru - add accessed entries here */
|
|
|
|
Entry *c_lrutail; /* lru - rem lru entries from here */
|
1999-02-03 03:26:00 +08:00
|
|
|
ldap_pvt_thread_mutex_t c_mutex;
|
1999-07-20 03:40:33 +08:00
|
|
|
} Cache;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-02-12 01:46:56 +08:00
|
|
|
#define CACHE_READ_LOCK 0
|
|
|
|
#define CACHE_WRITE_LOCK 1
|
1999-02-11 02:28:25 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/* for the cache of open index files */
|
1999-07-20 03:40:33 +08:00
|
|
|
typedef struct ldbm_dbcache {
|
1998-08-09 08:43:13 +08:00
|
|
|
int dbc_refcnt;
|
|
|
|
int dbc_maxids;
|
|
|
|
int dbc_maxindirect;
|
2000-06-05 13:10:30 +08:00
|
|
|
int dbc_dirty;
|
2000-06-15 02:23:43 +08:00
|
|
|
int dbc_flags;
|
1999-02-03 03:26:00 +08:00
|
|
|
time_t dbc_lastref;
|
|
|
|
long dbc_blksize;
|
|
|
|
char *dbc_name;
|
|
|
|
LDBM dbc_db;
|
2001-10-12 02:12:53 +08:00
|
|
|
ldap_pvt_thread_mutex_t dbc_write_mutex;
|
1999-07-20 03:40:33 +08:00
|
|
|
} DBCache;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2000-06-03 11:37:02 +08:00
|
|
|
#define MAXDBCACHE 128
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
struct ldbminfo {
|
2002-01-30 01:58:36 +08:00
|
|
|
ldap_pvt_thread_rdwr_t li_giant_rwlock;
|
1998-08-09 08:43:13 +08:00
|
|
|
ID li_nextid;
|
|
|
|
int li_mode;
|
2000-08-23 05:26:25 +08:00
|
|
|
slap_mask_t li_defaultmask;
|
1998-08-09 08:43:13 +08:00
|
|
|
char *li_directory;
|
1999-07-20 03:40:33 +08:00
|
|
|
Cache li_cache;
|
1998-08-09 08:43:13 +08:00
|
|
|
Avlnode *li_attrs;
|
1999-09-24 03:49:20 +08:00
|
|
|
int li_dblocking; /* lock databases */
|
|
|
|
int li_dbwritesync; /* write sync */
|
1998-08-09 08:43:13 +08:00
|
|
|
int li_dbcachesize;
|
1999-07-20 03:40:33 +08:00
|
|
|
DBCache li_dbcache[MAXDBCACHE];
|
1999-02-03 03:26:00 +08:00
|
|
|
ldap_pvt_thread_mutex_t li_dbcache_mutex;
|
|
|
|
ldap_pvt_thread_cond_t li_dbcache_cv;
|
2001-06-22 02:54:56 +08:00
|
|
|
DB_ENV *li_dbenv;
|
|
|
|
int li_envdirok;
|
2001-06-28 17:20:33 +08:00
|
|
|
int li_dbsyncfreq;
|
|
|
|
int li_dbsyncwaitn;
|
|
|
|
int li_dbsyncwaitinterval;
|
|
|
|
ldap_pvt_thread_t li_dbsynctid;
|
|
|
|
int li_dbshutdown;
|
1998-08-09 08:43:13 +08:00
|
|
|
};
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
LDAP_END_DECL
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
#include "proto-back-ldbm.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#endif /* _back_ldbm_h_ */
|