1 /* OpenLDAP WiredTiger backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2002-2017 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
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.
25 #include <ac/string.h>
30 wt_db_init( BackendDB *be, ConfigReply *cr )
34 Debug( LDAP_DEBUG_TRACE,
35 LDAP_XSTRING(wt_db_init) ": Initializing wt backend\n",
38 /* allocate backend-database-specific stuff */
39 wi = ch_calloc( 1, sizeof(struct wt_info) );
41 wi->wi_dbenv_home = ch_strdup( SLAPD_DEFAULT_DB_DIR );
42 wi->wi_dbenv_config = ch_strdup("create");
44 wi->wi_search_stack_depth = DEFAULT_SEARCH_STACK_DEPTH;
45 wi->wi_search_stack = NULL;
48 be->be_cf_ocs = be->bd_info->bi_cf_ocs;
54 wt_db_open( BackendDB *be, ConfigReply *cr )
56 struct wt_info *wi = (struct wt_info *) be->be_private;
62 if ( be->be_suffix == NULL ) {
63 Debug( LDAP_DEBUG_ANY,
64 LDAP_XSTRING(wt_db_open) ": need suffix.\n",
69 Debug( LDAP_DEBUG_ARGS,
70 LDAP_XSTRING(wt_db_open) ": \"%s\"\n",
71 be->be_suffix[0].bv_val, 0, 0 );
73 /* Check existence of home. Any error means trouble */
74 rc = stat( wi->wi_dbenv_home, &st );
76 Debug( LDAP_DEBUG_ANY,
77 LDAP_XSTRING(wt_db_open) ": database \"%s\": "
78 "cannot access database directory \"%s\" (%d).\n",
79 be->be_suffix[0].bv_val, wi->wi_dbenv_home, errno );
83 /* Open and create database */
84 rc = wiredtiger_open(wi->wi_dbenv_home, NULL,
85 wi->wi_dbenv_config, &conn);
87 Debug( LDAP_DEBUG_ANY,
88 LDAP_XSTRING(wt_db_open) ": database \"%s\": "
89 "cannot open database \"%s\" (%d).\n",
90 be->be_suffix[0].bv_val, wi->wi_dbenv_home, errno );
94 rc = conn->open_session(conn, NULL, NULL, &session);
96 Debug( LDAP_DEBUG_ANY,
97 LDAP_XSTRING(wt_db_open) ": database \"%s\": "
98 "cannot open session: \"%s\"\n",
99 be->be_suffix[0].bv_val, wiredtiger_strerror(rc), 0);
103 rc = session->create(session,
107 "columns=(id,dn,entry)");
109 Debug( LDAP_DEBUG_ANY,
110 LDAP_XSTRING(wt_db_open) ": database \"%s\": "
111 "cannot create entry table: \"%s\"\n",
112 be->be_suffix[0].bv_val, wiredtiger_strerror(rc), 0);
116 rc = session->create(session,
120 "columns=(ndn,id,pid,revdn)");
122 Debug( LDAP_DEBUG_ANY,
123 LDAP_XSTRING(wt_db_open) ": database \"%s\": "
124 "cannot create entry table: \"%s\"\n",
125 be->be_suffix[0].bv_val, wiredtiger_strerror(rc), 0);
129 /* not using dn2id index for id2entry table */
130 rc = session->create(session, WT_INDEX_DN, "columns=(dn)");
132 Debug( LDAP_DEBUG_ANY,
133 LDAP_XSTRING(wt_db_open) ": database \"%s\": "
134 "cannot create dn index: \"%s\"\n",
135 be->be_suffix[0].bv_val, wiredtiger_strerror(rc), 0);
139 rc = session->create(session, WT_INDEX_PID, "columns=(pid)");
141 Debug( LDAP_DEBUG_ANY,
142 LDAP_XSTRING(wt_db_open) ": database \"%s\": "
143 "cannot create pid index: \"%s\"\n",
144 be->be_suffix[0].bv_val, wiredtiger_strerror(rc), 0);
148 rc = session->create(session, WT_INDEX_REVDN, "columns=(revdn)");
150 Debug( LDAP_DEBUG_ANY,
151 LDAP_XSTRING(wt_db_open) ": database \"%s\": "
152 "cannot create revdn index: \"%s\"\n",
153 be->be_suffix[0].bv_val, wiredtiger_strerror(rc), 0);
157 rc = wt_last_id( be, session, &wi->wi_lastid);
159 snprintf( cr->msg, sizeof(cr->msg), "database \"%s\": "
160 "last_id() failed: %s(%d).",
161 be->be_suffix[0].bv_val, wiredtiger_strerror(rc), rc );
162 Debug( LDAP_DEBUG_ANY,
163 LDAP_XSTRING(wt_db_open) ": %s\n",
168 session->close(session, NULL);
170 wi->wi_flags |= WT_IS_OPEN;
176 wt_db_close( BackendDB *be, ConfigReply *cr )
178 struct wt_info *wi = (struct wt_info *) be->be_private;
181 rc = wi->wi_conn->close(wi->wi_conn, NULL);
183 Debug( LDAP_DEBUG_ANY,
184 LDAP_XSTRING(wt_db_close)
185 ": cannot close database (%d).\n",
190 wi->wi_flags &= ~WT_IS_OPEN;
196 wt_db_destroy( Backend *be, ConfigReply *cr )
198 struct wt_info *wi = (struct wt_info *) be->be_private;
200 if( wi->wi_dbenv_home ) {
201 ch_free( wi->wi_dbenv_home );
202 wi->wi_dbenv_home = NULL;
204 if( wi->wi_dbenv_config ) {
205 ch_free( wi->wi_dbenv_config );
206 wi->wi_dbenv_config = NULL;
209 wt_attr_index_destroy( wi );
211 be->be_private = NULL;
217 wt_back_initialize( BackendInfo *bi )
219 static char *controls[] = {
221 LDAP_CONTROL_MANAGEDSAIT,
223 LDAP_CONTROL_PAGEDRESULTS,
224 LDAP_CONTROL_PRE_READ,
225 LDAP_CONTROL_POST_READ,
226 LDAP_CONTROL_SUBENTRIES,
227 LDAP_CONTROL_X_PERMISSIVE_MODIFY,
231 /* initialize the database system */
232 Debug( LDAP_DEBUG_TRACE,
233 LDAP_XSTRING(wt_back_initialize)
234 ": initialize WiredTiger backend\n",
238 SLAP_BFLAG_INCREMENT |
239 SLAP_BFLAG_SUBENTRIES |
241 SLAP_BFLAG_REFERRALS;
243 bi->bi_controls = controls;
245 { /* version check */
246 Debug( LDAP_DEBUG_TRACE,
247 LDAP_XSTRING(wt_back_initialize) ": %s\n",
248 wiredtiger_version(NULL, NULL, NULL), 0, 0 );
256 bi->bi_db_init = wt_db_init;
257 bi->bi_db_config = config_generic_wrapper;
258 bi->bi_db_open = wt_db_open;
259 bi->bi_db_close = wt_db_close;
260 bi->bi_db_destroy = wt_db_destroy;
262 bi->bi_op_add = wt_add;
263 bi->bi_op_bind = wt_bind;
264 bi->bi_op_unbind = 0;
265 bi->bi_op_search = wt_search;
266 bi->bi_op_compare = wt_compare;
267 bi->bi_op_modify = wt_modify;
268 bi->bi_op_modrdn = 0;
269 bi->bi_op_delete = wt_delete;
270 bi->bi_op_abandon = 0;
274 bi->bi_chk_referrals = 0;
275 bi->bi_operational = wt_operational;
277 bi->bi_entry_release_rw = wt_entry_release;
278 bi->bi_entry_get_rw = wt_entry_get;
280 bi->bi_tool_entry_open = wt_tool_entry_open;
281 bi->bi_tool_entry_close = wt_tool_entry_close;
282 bi->bi_tool_entry_first = backend_tool_entry_first;
283 bi->bi_tool_entry_first_x = wt_tool_entry_first_x;
284 bi->bi_tool_entry_next = wt_tool_entry_next;
285 bi->bi_tool_entry_get = wt_tool_entry_get;
286 bi->bi_tool_entry_put = wt_tool_entry_put;
287 bi->bi_tool_entry_reindex = wt_tool_entry_reindex;
289 bi->bi_connection_init = 0;
290 bi->bi_connection_destroy = 0;
292 return wt_back_init_cf( bi );
295 #if SLAPD_WT == SLAPD_MOD_DYNAMIC
297 /* conditionally define the init_module() function */
298 SLAP_BACKEND_INIT_MODULE( wt )
300 #endif /* SLAPD_WT == SLAPD_MOD_DYNAMIC */
304 * indent-tabs-mode: t