#include "portable.h"
#include <stdio.h>
-#include <errno.h>
+#include <ac/errno.h>
#include <ac/string.h>
int
-bdb2i_enter_backend_rw( DB_ENV *dbEnv, DB_LOCK *lock, int writer )
+bdb2i_enter_backend_rw( DB_LOCK *lock, int writer )
{
u_int32_t locker;
db_lockmode_t lock_type;
case SLAP_SERVER_MODE:
case SLAP_TIMEDSERVER_MODE:
case SLAP_TOOL_MODE:
- if ( ( ret = lock_id( dbEnv->lk_info, &locker )) != 0 ) {
+ case SLAP_TOOLID_MODE:
+ if ( ( ret = lock_id( bdb2i_dbEnv.lk_info, &locker )) != 0 ) {
Debug( LDAP_DEBUG_ANY,
"bdb2i_enter_backend(): unable to get locker id -- %s\n",
lock_dbt.data = PORTER_OBJ;
lock_dbt.size = strlen( PORTER_OBJ );
- switch ( ( ret = lock_get( dbEnv->lk_info, locker, 0, &lock_dbt,
- lock_type, lock ))) {
+ switch ( ( ret = lock_get( bdb2i_dbEnv.lk_info, locker, 0,
+ &lock_dbt, lock_type, lock ))) {
case 0:
Debug( LDAP_DEBUG_TRACE,
writer ? "write" : "read", 0, 0 );
break;
- default:
+ default:
+ ret = errno;
Debug( LDAP_DEBUG_ANY,
"bdb2i_enter_backend() -- %s lock returned ERROR: %s\n",
- writer ? "write" : "read", strerror( errno ), 0 );
- ret = errno;
+ writer ? "write" : "read", strerror( ret ), 0 );
break;
}
break;
}
+ /* if we are a writer and we have the backend lock,
+ start transaction control */
+ if ( writer && ( ret == 0 )) {
+
+ ret = bdb2i_start_transction( bdb2i_dbEnv.tx_info );
+
+ }
+
return( ret );
}
int
-bdb2i_leave_backend_rw( DB_ENV *dbEnv, DB_LOCK lock, int writer )
+bdb2i_leave_backend_rw( DB_LOCK lock, int writer )
{
- int ret = 0;
+ /* since one or more error can occure,
+ we must have several return codes that are or'ed at the end */
+ int ret_transaction = 0;
+ int ret_lock = 0;
+
+ /* if we are a writer, finish the transaction */
+ if ( writer ) {
+ ret_transaction = bdb2i_finish_transaction();
+
+ }
+
+ /* check whether checkpointing is needed */
+ ret_transaction |= bdb2i_set_txn_checkpoint( bdb2i_dbEnv.tx_info, 0 );
+
+ /* now release the lock */
switch ( slapMode ) {
case SLAP_SERVER_MODE:
case SLAP_TIMEDSERVER_MODE:
case SLAP_TOOL_MODE:
- switch( ( ret = lock_put( dbEnv->lk_info, lock ))) {
+ case SLAP_TOOLID_MODE:
+ switch( ( ret_lock = lock_put( bdb2i_dbEnv.lk_info, lock ))) {
case 0:
Debug( LDAP_DEBUG_TRACE,
break;
default:
+ ret_lock = errno;
Debug( LDAP_DEBUG_ANY,
"bdb2i_leave_backend() -- %s lock returned ERROR: %s\n",
- writer ? "write" : "read", strerror( errno ), 0 );
- ret = errno;
+ writer ? "write" : "read", strerror( ret_lock ), 0 );
break;
}
break;
}
- return( ret );
-
+ return( ret_transaction | ret_lock );
}