mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-01-07 23:51:21 -05:00
Add new nextid code.
This commit is contained in:
parent
22e739b736
commit
67e3f97097
6 changed files with 88 additions and 13 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
{
|
||||
|
|
|
|||
58
servers/slapd/back-bdb/nextid.c
Normal file
58
servers/slapd/back-bdb/nextid.c
Normal file
|
|
@ -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 <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;
|
||||
}
|
||||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue