#define DEFAULT_DB_LG_DIR DEFAULT_DBENV_HOME LDAP_DIRSEP "log"
#define DEFAULT_DB_DATA_DIR DEFAULT_DBENV_HOME LDAP_DIRSEP "data"
-#define BDB_ID 0
+#define BDB_NEXTID 0
#define BDB_ENTRIES 1
-#define BDB_DNS 2
+#define BDB_DN2ID 2
struct bdb_db_info {
DB *bdi_db;
int bi_ndatabases;
struct bdb_db_info **bdi_databases;
};
-#define bi_id bdi_databases[BDB_ID]
+#define bi_nextid bdi_databases[BDB_NEXTID]
#define bi_entries bdi_databases[BDB_ENTRIES]
-#define bi_dns bdi_databases[BDB_DNS]
+#define bi_dn2id bdi_databases[BDB_DN2ID]
LDAP_END_DECL
# End Source File
# Begin Source File
+SOURCE=.\nextid.c
+# End Source File
+# Begin Source File
+
SOURCE=".\proto-bdb.h"
# End Source File
# Begin Source File
}
#ifdef SLAPD_BDB_DYNAMIC
-int back_bi_LTX_init_module( int argc, char *argv[] ) {
+int back_bdb_LTX_init_module( int argc, char *argv[] ) {
BackendInfo bi;
memset( &bi, '\0', sizeof(bi) );
#endif /* SLAPD_BDB_DYNAMIC */
int
-bi_back_initialize(
+bdb_back_initialize(
BackendInfo *bi
)
{
--- /dev/null
+/* init.c - initialize bdb backend */
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+
+#include "portable.h"
+
+#include <stdio.h>
+
+#include <ac/string.h>
+#include <ac/socket.h>
+
+#include "back-bdb.h"
+
+int bdb_next_id( BackendDB *be, DB_TXN *tid, ID *out )
+{
+ struct bdb_info *bdb = (struct bdb_info *) be->be_private;
+ int rc;
+ ID kid = NOID;
+ ID id;
+ DBT key, data;
+
+ DBTzero( &key );
+ key.data = (char *) &kid;
+ key.size = sizeof( kid );
+
+ DBTzero( &data );
+ data.data = (char *) &id;
+ data.ulen = sizeof( id );
+ data.flags = DB_DBT_USERMEM;
+
+ /* get exiting value (with write lock) */
+ rc = bdb->bi_entries->bdi_db->get( bdb->bi_nextid->bdi_db,
+ tid, &key, &data, DB_RMW );
+
+ if( rc == DB_NOTFOUND ) {
+ /* must be first add */
+ id = NOID;
+
+ } else if( rc != 0 ) {
+ return rc;
+
+ } else if ( data.size != sizeof(ID) ) {
+ /* size mismatch! */
+ return -1;
+ }
+
+ id++;
+
+ /* store new value */
+ rc = bdb->bi_entries->bdi_db->put( bdb->bi_nextid->bdi_db,
+ tid, &key, &data, 0 );
+
+ *out = id;
+ return rc;
+}
*/
void bdb_errcall( const char *pfx, char * msg );
+/*
+ * dn.c
+ */
+int bdb_index_dn_add(
+ BackendDB *be,
+ DB_TXN *tid,
+ const char *dn,
+ ID id );
+
+/*
+ * nextid.c
+ */
+int bdb_next_id( BackendDB *be, DB_TXN *tid, ID *id );
+
LDAP_END_DECL
#endif /* _PROTO_BDB_H */
return NOID;
}
- e->e_id = bdb_next_id( be, tid );
- if( e->e_id == NOID ) {
+ rc = bdb_next_id( be, tid, &e->e_id );
+ if( rc != 0 ) {
goto done;
}
rc = bdb->bi_entries->bdi_db->put( bdb->bi_entries->bdi_db,
tid, &key, &data, DB_NOOVERWRITE );
if( rc != 0 ) {
- e->e_id = NOID;
goto done;
}
/* add dn indices */
rc = bdb_index_dn_add( be, tid, e->e_ndn, e->e_id );
if( rc != 0 ) {
- e->e_id = NOID;
goto done;
}
#if 0
rc = bdb_index_entry_add( be, tid, e, e->e_attrs );
if( rc != 0 ) {
- e->e_id = NOID;
goto done;
}
#endif
done:
- if( e->e_id != NOID ) {
+ ber_bvfree( bv );
+
+ if( rc == 0 ) {
rc = txn_commit( tid, 0 );
if( rc != 0 ) {
e->e_id = NOID;
} else {
txn_abort( tid );
+ e->e_id = NOID;
}
- ber_bvfree( bv );
return e->e_id;
}