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