/* txn.c - TP support functions of the bdb2 backend */
+#include "portable.h"
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
#include "txn.h"
fileinfo->dbc_refcnt = 1;
- sprintf( buf, "%s%s%s", li->li_directory, DEFAULT_DIRSEP,
- fileinfo->dbc_name );
+ sprintf( buf, "%s" LDAP_DIRSEP "%s",
+ li->li_directory, fileinfo->dbc_name );
+
if ( stat( buf, &st ) == 0 ) {
fileinfo->dbc_blksize = st.st_blksize;
} else {
if ( open && strcasecmp( fileName, "objectclass" )) {
/* re-use filename to get the complete path */
- sprintf( fileName, "%s%s%s",
- li->li_directory, DEFAULT_DIRSEP, p->dbc_name );
+ sprintf( fileName, "%s" LDAP_DIRSEP "%s",
+ li->li_directory, p->dbc_name );
/* since we have an mpool, we should not define a cache size */
- p->dbc_db = ldbm_open( fileName, LDBM_WRCREAT, li->li_mode, 0 );
+ p->dbc_db = bdb2i_db_open( fileName, DB_TYPE,
+ LDBM_WRCREAT, li->li_mode, 0 );
/* if the files could not be opened, something is wrong;
complain */
BDB2_TXN_HEAD *head = &li->li_txn_head;
LDBM db = NULL;
DB_INFO dbinfo;
- DB_ENV *dbenv = get_dbenv( be );
char fileName[MAXPATHLEN];
- sprintf( fileName, "%s%s%s",
- li->li_directory, DEFAULT_DIRSEP, NEXTID_NAME );
+ sprintf( fileName, "%s" LDAP_DIRSEP "%s",
+ li->li_directory, NEXTID_NAME );
/* try to open the file for read and write */
memset( &dbinfo, 0, sizeof( dbinfo ));
dbinfo.db_malloc = ldbm_malloc;
(void) db_open( fileName, DB_RECNO, DB_CREATE | DB_THREAD,
- li->li_mode, dbenv, &dbinfo, &db );
+ li->li_mode, &bdb2i_dbEnv, &dbinfo, &db );
if ( db == NULL ) {
for ( dbFile = head->dbFiles; dbFile; dbFile = dbFile->next ) {
char fileName[MAXPATHLEN];
- sprintf( fileName, "%s%s%s",
- li->li_directory, DEFAULT_DIRSEP, dbFile->dbc_name );
+ sprintf( fileName, "%s" LDAP_DIRSEP "%s",
+ li->li_directory, dbFile->dbc_name );
/* since we have an mpool, we should not define a cache size */
- dbFile->dbc_db = ldbm_open( fileName, LDBM_WRCREAT, li->li_mode, 0 );
+ dbFile->dbc_db = bdb2i_db_open( fileName, DB_TYPE,
+ LDBM_WRCREAT, li->li_mode, 0 );
/* if the files could not be opened, something is wrong; complain */
if ( dbFile->dbc_db == NULL ) {
}
- ldbm_close( head->nextidFile );
+ if ( head->nextidFile )
+ ldbm_close( head->nextidFile );
}
struct dirent *file;
if ( ( datadir = opendir( li->li_directory ) ) == NULL ) {
+ int err = errno;
Debug( LDAP_DEBUG_ANY,
"bdb2i_check_additional_attr_index(): ERROR while opening datadir: %s\n",
- strerror( errno ), 0, 0 );
+ strerror( err ), 0, 0 );
return( 1 );
}
}
-/* BDB2 backend-private functions of ldbm_store and ldbm_delete */
+/* BDB2 backend-private functions of libldbm */
+LDBM
+bdb2i_db_open(
+ char *name,
+ int type,
+ int rw,
+ int mode,
+ int dbcachesize )
+{
+ LDBM ret = NULL;
+ DB_INFO dbinfo;
+
+ memset( &dbinfo, 0, sizeof( dbinfo ));
+ if ( bdb2i_dbEnv.mp_info == NULL )
+ dbinfo.db_cachesize = dbcachesize;
+ dbinfo.db_pagesize = DEFAULT_DB_PAGE_SIZE;
+ dbinfo.db_malloc = ldbm_malloc;
+
+ (void) db_open( name, type, rw, mode, &bdb2i_dbEnv, &dbinfo, &ret );
+
+ return( ret );
+}
+
+
int
bdb2i_db_store( LDBM ldbm, Datum key, Datum data, int flags )
{
txn_do_abort = 1;
}
+ key.flags = 0;
return( key );
} else {
*dbch = dbci;
if ( (*dbci->c_get)( dbci, &key, &data, DB_NEXT ) == 0 ) {
- if ( data.dptr ) free( data.dptr );
+ ldbm_datum_free( ldbm, data );
} else {
if ( txnid != NULL ) {
txn_do_abort = 1;
}
- if ( key.dptr ) free( key.dptr );
+ ldbm_datum_free( ldbm, key );
+ key.flags = 0;
key.dptr = NULL;
key.dsize = 0;
}
{
Datum data;
int rc;
- void *oldKey = key.dptr;
ldbm_datum_init( data );
- data.flags = DB_DBT_MALLOC;
+ ldbm_datum_free( ldbm, key );
+ key.flags = data.flags = DB_DBT_MALLOC;
if ( (*dbcp->c_get)( dbcp, &key, &data, DB_NEXT ) == 0 ) {
- if ( data.dptr ) free( data.dptr );
+ ldbm_datum_free( ldbm, data );
} else {
if ( txnid != NULL ) {
txn_do_abort = 1;
}
+ key.flags = 0;
key.dptr = NULL;
key.dsize = 0;
}
- if ( oldKey ) free( oldKey );
-
return( key );
}
txn_do_abort = 0;
if (( rc = txn_begin( txmgr, NULL, &txnid )) != 0 ) {
+ int err = errno;
Debug( LDAP_DEBUG_ANY, "bdb2i_start_transction failed: %d: errno=%s\n",
- rc, strerror( errno ), 0 );
+ rc, strerror( err ), 0 );
if ( txnid != NULL )
(void) txn_abort( txnid );
logsize = forced ? (u_int32_t) 0 : txn_max_pending_log;
mins = forced ? (u_int32_t) 0 : txn_max_pending_time;
- ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
- time( ¤ttime );
- now = currenttime;
- ldap_pvt_thread_mutex_unlock( ¤ttime_mutex );
+ now = slap_get_time();
rc = txn_checkpoint( txmgr, logsize, mins );