1 /* init.c - initialize bdb backend */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
15 int bdb_next_id( BackendDB *be, DB_TXN *tid, ID *out )
17 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
25 key.data = (char *) &kid;
26 key.size = sizeof( kid );
29 data.data = (char *) &id;
30 data.ulen = sizeof( id );
31 data.flags = DB_DBT_USERMEM;
34 retry: if( tid != NULL ) {
35 /* nested transaction, abort and return */
36 (void) txn_abort( ltid );
37 Debug( LDAP_DEBUG_ANY,
38 "=> bdb_next_id: aborted!\n",
42 rc = txn_abort( ltid );
44 Debug( LDAP_DEBUG_ANY,
45 "=> bdb_next_id: txn_abort failed: %s (%d)\n",
46 db_strerror(rc), rc, 0 );
51 rc = txn_begin( bdb->bi_dbenv, tid, <id, 0 );
53 Debug( LDAP_DEBUG_ANY,
54 "=> bdb_next_id: txn_begin failed: %s (%d)\n",
55 db_strerror(rc), rc, 0 );
59 /* get existing value for read/modify/write */
60 rc = bdb->bi_nextid->bdi_db->get( bdb->bi_nextid->bdi_db,
61 ltid, &key, &data, DB_RMW );
64 case DB_LOCK_DEADLOCK:
65 case DB_LOCK_NOTGRANTED:
73 if ( data.size != sizeof( id ) ) {
74 Debug( LDAP_DEBUG_ANY,
75 "=> bdb_next_id: get size mismatch: expected %ld, got %ld\n",
76 (long) sizeof( id ), (long) data.size, 0 );
83 Debug( LDAP_DEBUG_ANY,
84 "=> bdb_next_id: get failed: %s (%d)\n",
85 db_strerror(rc), rc, 0 );
89 if( bdb->bi_lastid > id ) id = bdb->bi_lastid;
92 data.size = sizeof( id );
95 rc = bdb->bi_nextid->bdi_db->put( bdb->bi_nextid->bdi_db,
96 ltid, &key, &data, 0 );
99 case DB_LOCK_DEADLOCK:
100 case DB_LOCK_NOTGRANTED:
108 rc = txn_commit( ltid, 0 );
111 Debug( LDAP_DEBUG_ANY,
112 "=> bdb_next_id: commit failed: %s (%d)\n",
113 db_strerror(rc), rc, 0 );
118 Debug( LDAP_DEBUG_ANY,
119 "=> bdb_next_id: put failed: %s (%d)\n",
120 db_strerror(rc), rc, 0 );
121 done: (void) txn_abort( ltid );
127 int bdb_last_id( BackendDB *be, DB_TXN *tid )
129 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
136 key.data = (char *) &kid;
137 key.size = sizeof( kid );
140 data.data = (char *) &id;
141 data.ulen = sizeof( id );
142 data.flags = DB_DBT_USERMEM;
144 /* get existing value for read/modify/write */
145 rc = bdb->bi_nextid->bdi_db->get( bdb->bi_nextid->bdi_db,
146 tid, &key, &data, 0 );
155 if ( data.size != sizeof( id ) ) {
156 Debug( LDAP_DEBUG_ANY,
157 "=> bdb_last_id: get size mismatch: expected %ld, got %ld\n",
158 (long) sizeof( id ), (long) data.size, 0 );
165 Debug( LDAP_DEBUG_ANY,
166 "=> bdb_next_id: get failed: %s (%d)\n",
167 db_strerror(rc), rc, 0 );