X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-bdb2%2Fclose.c;h=98d68c7c68e3a5c3eeba8325f7b68e1657b1bb36;hb=403f4479bc9f9a864122d4aeecf7284408918302;hp=647ba757ba4280fe2185b840c9dfb35a0fb61924;hpb=42f6e78dd4e2d481c1bc75b8bc6d38fe9c62bc07;p=openldap diff --git a/servers/slapd/back-bdb2/close.c b/servers/slapd/back-bdb2/close.c index 647ba757ba..98d68c7c68 100644 --- a/servers/slapd/back-bdb2/close.c +++ b/servers/slapd/back-bdb2/close.c @@ -1,4 +1,5 @@ /* close.c - close bdb2 backend database */ +/* $OpenLDAP$ */ #include "portable.h" @@ -12,11 +13,28 @@ static int bdb2i_back_db_close_internal( BackendDB *be ) { - Debug( LDAP_DEBUG_TRACE, "bdb2 backend saving nextid\n", 0, 0, 0 ); - if ( bdb2i_next_id_save( be ) < 0 ) { - Debug( LDAP_DEBUG_ANY, "bdb2 backend nextid save failed!\n", 0, 0, 0 ); + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + DB_LOCK lock; + + /* since close will probably write the NEXTID file, + wee need transaction control */ + if ( bdb2i_enter_backend_w( &lock ) != 0 ) { + return( -1 ); + } + + if ( li->li_nextid != NOID ) { + Debug( LDAP_DEBUG_TRACE, "bdb2 backend saving nextid\n", 0, 0, 0 ); + if ( bdb2i_next_id_save( be ) < 0 ) { + Debug( LDAP_DEBUG_ANY, "bdb2 backend nextid save failed!\n", + 0, 0, 0 ); + } } + /* before closing all files, leave the backend (thus commiting + all writes) and set a last checkpoint */ + (void) bdb2i_leave_backend_w( lock ); + (void) bdb2i_set_txn_checkpoint( bdb2i_dbEnv.tx_info, 1 ); + /* close all DB files */ Debug( LDAP_DEBUG_TRACE, "bdb2 backend closing DB files\n", 0, 0, 0 ); bdb2i_txn_close_files( be ); @@ -29,23 +47,14 @@ bdb2i_back_db_close_internal( BackendDB *be ) int bdb2_back_db_close( BackendDB *be ) { - struct timeval time1, time2; - char *elapsed_time; - int ret; + struct timeval time1; + int ret; - gettimeofday( &time1, NULL ); + bdb2i_start_timing( be->bd_info, &time1 ); ret = bdb2i_back_db_close_internal( be ); - if ( bdb2i_do_timing ) { - - gettimeofday( &time2, NULL); - elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "CLOSE elapsed=%s\n", - elapsed_time, 0, 0 ); - free( elapsed_time ); - - } + bdb2i_stop_timing( be->bd_info, time1, "CLOSE", NULL, NULL ); return( ret ); }