]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb2/close.c
Factor out ldif2* intialization to ldif2common.c
[openldap] / servers / slapd / back-bdb2 / close.c
index 90dda95068a2e5d4b0c69e860974a16d9fe77923..eafdf164f4b91fc7b01d46378b613fd6b5085975 100644 (file)
@@ -1,4 +1,4 @@
-/* close.c - close bdb2 backend */
+/* close.c - close bdb2 backend database */
 
 #include "portable.h"
 
 #include "back-bdb2.h"
 
 static int
-bdb2i_back_db_close_internal( Backend *be )
+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 );
+       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 ( slapMode != SLAP_TOOL_MODE ) {
+
+               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 );
+               }
        }
 
-       Debug( LDAP_DEBUG_TRACE, "bdb2 backend syncing\n", 0, 0, 0 );
-       bdb2i_cache_flush_all( be );
-       Debug( LDAP_DEBUG_TRACE, "bdb2 backend done syncing\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 );
+       Debug( LDAP_DEBUG_TRACE, "bdb2 backend done closing DB files\n", 0, 0, 0 );
 
        return 0;
 }
 
 
 int
-bdb2_back_db_close( Backend *be )
+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 );
 }