]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/close.c
slap_set_time() is no longer necessary.
[openldap] / servers / slapd / back-bdb2 / close.c
1 /* close.c - close bdb2 backend database */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/socket.h>
8
9 #include "slap.h"
10 #include "back-bdb2.h"
11
12 static int
13 bdb2i_back_db_close_internal( BackendDB *be )
14 {
15         DB_LOCK         lock;
16
17         /*  since close will probably write the NEXTID file,
18                 wee need transaction control  */
19         if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
20                 return( -1 );
21         }
22
23         if ( slapMode != SLAP_TOOL_MODE ) {
24
25                 Debug( LDAP_DEBUG_TRACE, "bdb2 backend saving nextid\n", 0, 0, 0 );
26                 if ( bdb2i_next_id_save( be ) < 0 ) {
27                         Debug( LDAP_DEBUG_ANY, "bdb2 backend nextid save failed!\n",
28                                         0, 0, 0 );
29                 }
30         }
31
32         /*  before closing all files, leave the backend (thus commiting
33                 all writes) and set a last checkpoint  */
34         (void) bdb2i_leave_backend_w( lock );
35         (void) bdb2i_set_txn_checkpoint( bdb2i_dbEnv.tx_info, 1 );
36
37         /*  close all DB files  */
38         Debug( LDAP_DEBUG_TRACE, "bdb2 backend closing DB files\n", 0, 0, 0 );
39         bdb2i_txn_close_files( be );
40         Debug( LDAP_DEBUG_TRACE, "bdb2 backend done closing DB files\n", 0, 0, 0 );
41
42         return 0;
43 }
44
45
46 int
47 bdb2_back_db_close( BackendDB *be )
48 {
49         struct timeval  time1;
50         int             ret;
51
52         bdb2i_start_timing( be->bd_info, &time1 );
53
54         ret = bdb2i_back_db_close_internal( be );
55
56         bdb2i_stop_timing( be->bd_info, time1, "CLOSE", NULL, NULL );
57
58         return( ret );
59 }
60
61