]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/config.c
Entry caching. Based on ITS#1545 from Jong Hyuk Choi, jongchoi@us.ibm.com
[openldap] / servers / slapd / back-bdb / config.c
1 /* config.c - bdb backend configuration file routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11 #include <ac/string.h>
12
13 #include "back-bdb.h"
14
15 #define SLAP_BDB_ALLOW_DBNOTXN
16 #ifdef DB_DIRTY_READ
17 #       define  SLAP_BDB_ALLOW_DIRTY_READ
18 #endif
19
20 int
21 bdb_db_config(
22         BackendDB       *be,
23         const char      *fname,
24         int             lineno,
25         int             argc,
26         char    **argv )
27 {
28         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
29
30         if ( bdb == NULL ) {
31                 fprintf( stderr, "%s: line %d: "
32                         "bdb database info is null!\n",
33                         fname, lineno );
34                 return 1;
35         }
36
37         /* directory is the DB_HOME */
38         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
39                 if ( argc < 2 ) {
40                         fprintf( stderr, "%s: line %d: "
41                                 "missing dir in \"directory <dir>\" line\n",
42                                 fname, lineno );
43                         return 1;
44                 }
45                 if ( bdb->bi_dbenv_home ) {
46                         free( bdb->bi_dbenv_home );
47                 }
48                 bdb->bi_dbenv_home = ch_strdup( argv[1] );
49
50 #ifdef SLAP_BDB_ALLOW_DBNOTXN
51         /* turn off transactions, use CDB mode instead */
52         } else if ( strcasecmp( argv[0], "dbnotxn" ) == 0 ) {
53                 bdb->bi_txn = 0;
54 #endif
55 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
56         } else if ( strcasecmp( argv[0], "dirtyread" ) == 0 ) {
57                 bdb->bi_db_opflags |= DB_DIRTY_READ;
58 #endif
59         /* transaction checkpoint configuration */
60         } else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) {
61                 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
62
63         /* transaction checkpoint configuration */
64         } else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
65                 if ( argc < 3 ) {
66                         fprintf( stderr, "%s: line %d: "
67                                 "missing parameters in \"checkpoint <kbyte> <min>\" line\n",
68                                 fname, lineno );
69                         return 1;
70                 }
71                 bdb->bi_txn_cp = 1;
72                 bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
73                 bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
74
75         /* lock detect configuration */
76         } else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
77 #ifndef NO_THREADS
78                 if ( argc < 3 ) {
79                         fprintf( stderr, "%s: line %d: "
80                                 "missing parameters in \"lockDetect <policy> <seconds>\" line\n",
81                                 fname, lineno );
82                         return 1;
83                 }
84
85                 if( strcasecmp( argv[1], "default" ) == 0 ) {
86                         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
87
88                 } else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
89                         bdb->bi_lock_detect = DB_LOCK_OLDEST;
90
91                 } else if( strcasecmp( argv[1], "random" ) == 0 ) {
92                         bdb->bi_lock_detect = DB_LOCK_RANDOM;
93
94                 } else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
95                         bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
96
97                 } else if( strcasecmp( argv[1], "fewest" ) == 0 ) {
98                         bdb->bi_lock_detect = DB_LOCK_MINLOCKS;
99
100                 } else {
101                         fprintf( stderr, "%s: line %d: "
102                                 "bad policy (%s) in \"lockDetect <policy> <seconds>\" line\n",
103                                 fname, lineno, argv[1] );
104                         return 1;
105                 }
106
107                 bdb->bi_lock_detect_seconds = strtol( argv[2], NULL, 0 );
108                 if( bdb->bi_lock_detect_seconds < 1 ) {
109                         fprintf( stderr, "%s: line %d: "
110                                 "bad seconds (%s) in \"lockDetect <policy> <seconds>\" line\n",
111                                 fname, lineno, argv[2] );
112                         return 1;
113                 }
114 #else
115                 fprintf( stderr, "%s: line %d: "
116                         "NO THREADS: lockDetect line ignored\n",
117                         fname, lineno );
118 #endif
119
120         /* mode with which to create new database files */
121         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
122                 if ( argc < 2 ) {
123                         fprintf( stderr, "%s: line %d: "
124                                 "missing mode in \"mode <mode>\" line\n",
125                                 fname, lineno );
126                         return 1;
127                 }
128                 bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
129
130 #if BDB_FILTER_INDICES
131         /* attribute to index */
132         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
133                 int rc;
134                 if ( argc < 2 ) {
135                         fprintf( stderr, "%s: line %d: "
136                                 "missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
137                                 fname, lineno );
138                         return 1;
139                 } else if ( argc > 3 ) {
140                         fprintf( stderr, "%s: line %d: "
141                                 "extra junk after \"index <attr> [pres,eq,approx,sub]\" "
142                                 "line (ignored)\n",
143                                 fname, lineno );
144                 }
145                 rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
146
147                 if( rc != LDAP_SUCCESS ) return 1;
148 #endif
149
150         /* size of the cache in entries */
151          } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
152                  if ( argc < 2 ) {
153                          fprintf( stderr,
154                  "%s: line %d: missing size in \"cachesize <size>\" line\n",
155                              fname, lineno );
156                          return( 1 );
157                  }
158                  bdb->bi_cache.c_maxsize = atoi( argv[1] );
159
160         /* anything else */
161         } else {
162                 fprintf( stderr, "%s: line %d: "
163                         "unknown directive \"%s\" in bdb database definition (ignored)\n",
164                         fname, lineno, argv[0] );
165         }
166
167         return 0;
168 }