From: Kurt Zeilenga Date: Tue, 19 Sep 2000 20:13:41 +0000 (+0000) Subject: Add new nextid code. X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~1948 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=67e3f970979ba608de5db558721e3e0aaab9c467;p=openldap Add new nextid code. --- diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index ae2f78f524..8d6e0dd7fe 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -29,9 +29,9 @@ LDAP_BEGIN_DECL #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; @@ -56,9 +56,9 @@ struct bdb_info { 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 diff --git a/servers/slapd/back-bdb/backbdb.dsp b/servers/slapd/back-bdb/backbdb.dsp index 45d3786ea3..7d22533f37 100644 --- a/servers/slapd/back-bdb/backbdb.dsp +++ b/servers/slapd/back-bdb/backbdb.dsp @@ -143,6 +143,10 @@ SOURCE=.\init.c # 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 diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index a93d53e2d6..b33811061f 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -168,7 +168,7 @@ bi_back_db_destroy( BackendDB *be ) } #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) ); @@ -181,7 +181,7 @@ int back_bi_LTX_init_module( int argc, char *argv[] ) { #endif /* SLAPD_BDB_DYNAMIC */ int -bi_back_initialize( +bdb_back_initialize( BackendInfo *bi ) { diff --git a/servers/slapd/back-bdb/nextid.c b/servers/slapd/back-bdb/nextid.c new file mode 100644 index 0000000000..92af935603 --- /dev/null +++ b/servers/slapd/back-bdb/nextid.c @@ -0,0 +1,58 @@ +/* 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 + +#include +#include + +#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; +} diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index a5434711cf..1cad0d6cc6 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -14,6 +14,20 @@ LDAP_BEGIN_DECL */ 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 */ diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index 8282961f97..113a5e33e6 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -135,8 +135,8 @@ ID bdb_tool_entry_put( 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; } @@ -144,27 +144,26 @@ ID bdb_tool_entry_put( 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; @@ -172,9 +171,9 @@ done: } else { txn_abort( tid ); + e->e_id = NOID; } - ber_bvfree( bv ); return e->e_id; }