]> git.sur5r.net Git - openldap/blob - servers/slapd/back-wt/config.c
ff5c60c335d6ccb4ffb3e7e644df11072e45c787
[openldap] / servers / slapd / back-wt / config.c
1 /* OpenLDAP WiredTiger backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2002-2017 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was developed by HAMANO Tsukasa <hamano@osstech.co.jp>
18  * based on back-bdb for inclusion in OpenLDAP Software.
19  * WiredTiger is a product of MongoDB Inc.
20  */
21
22 #include "portable.h"
23
24 #include <stdio.h>
25 #include <ac/string.h>
26 #include "back-wt.h"
27 #include "config.h"
28
29 #include "lutil.h"
30 #include "ldap_rq.h"
31
32 static ConfigDriver wt_cf_gen;
33
34 enum {
35         WT_DIRECTORY = 1,
36         WT_CONFIG,
37         WT_INDEX,
38 };
39
40 static ConfigTable wtcfg[] = {
41     { "directory", "dir", 2, 2, 0, ARG_STRING|ARG_MAGIC|WT_DIRECTORY,
42           wt_cf_gen, "( OLcfgDbAt:0.1 NAME 'olcDbDirectory' "
43           "DESC 'Directory for database content' "
44           "EQUALITY caseIgnoreMatch "
45           "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
46     { "wtconfig", "config", 2, 2, 0, ARG_STRING|ARG_MAGIC|WT_CONFIG,
47           wt_cf_gen, "( OLcfgDbAt:13.1 NAME 'olcWtConfig' "
48           "DESC 'Configuration for WiredTiger' "
49           "EQUALITY caseIgnoreMatch "
50           "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
51         { "index", "attr> <[pres,eq,approx,sub]", 2, 3, 0, ARG_MAGIC|WT_INDEX,
52           wt_cf_gen, "( OLcfgDbAt:0.2 NAME 'olcDbIndex' "
53           "DESC 'Attribute index parameters' "
54           "EQUALITY caseIgnoreMatch "
55           "SYNTAX OMsDirectoryString )", NULL, NULL },
56         { NULL, NULL, 0, 0, 0, ARG_IGNORED,
57                 NULL, NULL, NULL, NULL }
58 };
59
60 static ConfigOCs wtocs[] = {
61         { "( OLcfgDbOc:9.1 "
62           "NAME 'olcWtConfig' "
63           "DESC 'Wt backend configuration' "
64           "SUP olcDatabaseConfig "
65           "MUST olcDbDirectory "
66           "MAY ( olcWtConfig $ olcDbIndex ) )",
67           Cft_Database, wtcfg },
68         { NULL, 0, NULL }
69 };
70
71 /* reindex entries on the fly */
72 static void *
73 wt_online_index( void *ctx, void *arg )
74 {
75         // Not implement yet
76 }
77
78 /* Cleanup loose ends after Modify completes */
79 static int
80 wt_cf_cleanup( ConfigArgs *c )
81 {
82         // Not implement yet
83         return 0;
84 }
85
86 static int
87 wt_cf_gen( ConfigArgs *c )
88 {
89         struct wt_info *wi = (struct wt_info *) c->be->be_private;
90         int rc;
91
92         if(c->op == SLAP_CONFIG_EMIT) {
93                 rc = 0;
94                 // not implement yet
95                 return rc;
96         }
97
98         switch( c->type ) {
99         case WT_DIRECTORY:
100                 ch_free( wi->wi_dbenv_home );
101                 wi->wi_dbenv_home = c->value_string;
102                 break;
103         case WT_CONFIG:
104                 ch_free( wi->wi_dbenv_config );
105                 wi->wi_dbenv_config = c->value_string;
106                 break;
107
108         case WT_INDEX:
109                 rc = wt_attr_index_config( wi, c->fname, c->lineno,
110                                                                    c->argc - 1, &c->argv[1], &c->reply);
111
112                 if( rc != LDAP_SUCCESS ) return 1;
113                 wi->wi_flags |= WT_OPEN_INDEX;
114
115                 if ( wi->wi_flags & WT_IS_OPEN ) {
116                         c->cleanup = wt_cf_cleanup;
117
118                         if ( !wi->wi_index_task ) {
119                                 /* Start the task as soon as we finish here. Set a long
120                  * interval (10 hours) so that it only gets scheduled once.
121                  */
122                                 if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) {
123                                         fprintf( stderr, "%s: "
124                                                          "\"index\" must occur after \"suffix\".\n",
125                                                          c->log );
126                                         return 1;
127                                 }
128                                 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
129                                 wi->wi_index_task = ldap_pvt_runqueue_insert(&slapd_rq, 36000,
130                                                                                                                          wt_online_index, c->be,
131                                                                                                                          LDAP_XSTRING(wt_online_index),
132                                                                                                                          c->be->be_suffix[0].bv_val );
133                                 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
134                         }
135                 }
136                 break;
137
138         }
139         return LDAP_SUCCESS;
140 }
141
142 int wt_back_init_cf( BackendInfo *bi )
143 {
144         int rc;
145         bi->bi_cf_ocs = wtocs;
146
147         rc = config_register_schema( wtcfg, wtocs );
148         if ( rc ) return rc;
149         return 0;
150 }
151
152 /*
153  * Local variables:
154  * indent-tabs-mode: t
155  * tab-width: 4
156  * c-basic-offset: 4
157  * End:
158  */