From: Kurt Zeilenga Date: Tue, 31 Jul 2001 04:24:29 +0000 (+0000) Subject: Fix basic operations X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~1184 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0bcc892fdf387a231736681e261cfd3b7702f549;p=openldap Fix basic operations --- diff --git a/servers/slapd/back-bdb/idl.h b/servers/slapd/back-bdb/idl.h index 3ce8e19ed1..f7574ff791 100644 --- a/servers/slapd/back-bdb/idl.h +++ b/servers/slapd/back-bdb/idl.h @@ -12,11 +12,11 @@ #include "slap.h" -#define BDB_IDL_DB_SIZE (1<<16) /* 64K IDL on disk */ +#define BDB_IDL_DB_SIZE (1<<8) /* 64K IDL on disk */ #define BDB_IDL_DB_MAX (BDB_IDL_DB_SIZE-32) /* #define BDB_IDL_DB_ALLOC (BDB_IDL_DB_SIZE * sizeof(ID)) */ -#define BDB_IDL_SIZE (1<<17) /* 128K IDL in memory */ +#define BDB_IDL_SIZE (1<<10) /* 128K IDL in memory */ #define BDB_IDL_MAX (BDB_IDL_DB_SIZE-32) /* #define BDB_IDL_DB_ALLOC (BDB_IDL_DB_SIZE * sizeof(ID)) */ @@ -54,4 +54,4 @@ LDAP_BEGIN_DECL LDAP_END_DECL -#endif \ No newline at end of file +#endif diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index af3e2c3b02..f64e5a3570 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -209,6 +209,16 @@ bdb_db_open( BackendDB *be ) bdb->bi_databases[i] = db; } + /* get nextid */ + rc = bdb_last_id( be, NULL ); + if( rc != 0 ) { + Debug( LDAP_DEBUG_ANY, + "bdb_db_open: last_id(%s) failed: %s (%d)\n", + bdb->bi_dbenv_home, db_strerror(rc), rc ); + return rc; + } + + /* open (and create) index databases */ diff --git a/servers/slapd/back-bdb/nextid.c b/servers/slapd/back-bdb/nextid.c index a534840ae3..7ceda5f9cf 100644 --- a/servers/slapd/back-bdb/nextid.c +++ b/servers/slapd/back-bdb/nextid.c @@ -121,3 +121,58 @@ done: (void) txn_abort( ltid ); return rc; } + +int bdb_last_id( BackendDB *be, DB_TXN *tid ) +{ + 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; + +retry: + /* get existing value for read/modify/write */ + rc = bdb->bi_nextid->bdi_db->get( bdb->bi_nextid->bdi_db, + tid, &key, &data, 0 ); + + switch(rc) { + case DB_LOCK_DEADLOCK: + case DB_LOCK_NOTGRANTED: + goto retry; + + case DB_NOTFOUND: + id = 0; + rc = 0; + break; + + case 0: + if ( data.size != sizeof( id ) ) { + Debug( LDAP_DEBUG_ANY, + "=> bdb_last_id: get size mismatch: expected %ld, got %ld\n", + (long) sizeof( id ), (long) data.size, 0 ); + rc = -1; + goto done; + } + break; + + default: + Debug( LDAP_DEBUG_ANY, + "=> bdb_next_id: get failed: %s (%d)\n", + db_strerror(rc), rc, 0 ); + goto done; + } + + bdb->bi_lastid = id; + +done: + return rc; +} diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 1c473150a9..60d11f2cba 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -181,6 +181,7 @@ bdb_key_read( * nextid.c */ int bdb_next_id( BackendDB *be, DB_TXN *tid, ID *id ); +int bdb_last_id( BackendDB *be, DB_TXN *tid ); /* * modify.c