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 );
52 rc = txn_begin( bdb->bi_dbenv, tid, <id, 0 );
54 Debug( LDAP_DEBUG_ANY,
55 "=> bdb_next_id: txn_begin failed: %s (%d)\n",
56 db_strerror(rc), rc, 0 );
61 /* get existing value for read/modify/write */
62 rc = bdb->bi_nextid->bdi_db->get( bdb->bi_nextid->bdi_db,
63 ltid, &key, &data, DB_RMW );
66 case DB_LOCK_DEADLOCK:
67 case DB_LOCK_NOTGRANTED:
75 if ( data.size != sizeof( id ) ) {
76 Debug( LDAP_DEBUG_ANY,
77 "=> bdb_next_id: get size mismatch: expected %ld, got %ld\n",
78 (long) sizeof( id ), (long) data.size, 0 );
85 Debug( LDAP_DEBUG_ANY,
86 "=> bdb_next_id: get failed: %s (%d)\n",
87 db_strerror(rc), rc, 0 );
91 if( bdb->bi_lastid > id ) id = bdb->bi_lastid;
94 data.size = sizeof( id );
97 rc = bdb->bi_nextid->bdi_db->put( bdb->bi_nextid->bdi_db,
98 ltid, &key, &data, 0 );
101 case DB_LOCK_DEADLOCK:
102 case DB_LOCK_NOTGRANTED:
111 rc = txn_commit( ltid, 0 );
116 Debug( LDAP_DEBUG_ANY,
117 "=> bdb_next_id: commit failed: %s (%d)\n",
118 db_strerror(rc), rc, 0 );
123 Debug( LDAP_DEBUG_ANY,
124 "=> bdb_next_id: put failed: %s (%d)\n",
125 db_strerror(rc), rc, 0 );
126 done: (void) txn_abort( ltid );
132 int bdb_last_id( BackendDB *be, DB_TXN *tid )
134 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
141 key.data = (char *) &kid;
142 key.size = sizeof( kid );
145 data.data = (char *) &id;
146 data.ulen = sizeof( id );
147 data.flags = DB_DBT_USERMEM;
149 /* get existing value for read/modify/write */
150 rc = bdb->bi_nextid->bdi_db->get( bdb->bi_nextid->bdi_db,
151 tid, &key, &data, 0 );
160 if ( data.size != sizeof( id ) ) {
161 Debug( LDAP_DEBUG_ANY,
162 "=> bdb_last_id: get size mismatch: expected %ld, got %ld\n",
163 (long) sizeof( id ), (long) data.size, 0 );
170 Debug( LDAP_DEBUG_ANY,
171 "=> bdb_next_id: get failed: %s (%d)\n",
172 db_strerror(rc), rc, 0 );