25 #define AFW_IMPLEMENTATION_ID "lmdb"
31 void afw_lmdb_adaptor_load_configuration(
40 rc = mdb_txn_begin(self->dbEnv, NULL, 0, &txn);
43 "Unable to begin initial transaction.", xctx);
46 config = afw_lmdb_internal_get_config(
self, txn, p, xctx);
51 afw_lmdb_internal_save_config(
self, self->internalConfig, txn, xctx);
53 rc = mdb_txn_commit(txn);
56 "Unable to commit initial transaction.", xctx);
76 "Property env.path required by LMDB adaptor.", xctx);
83 "Property env.mode required by LMDB adaptor.", xctx);
128 limits->size_soft = 500;
134 limits->size_hard = 1000;
145 limits->time_soft = 3600;
151 limits->time_hard = 14400;
176 rc = mdb_txn_begin(self->dbEnv, NULL, 0, &txn);
179 "Unable to begin initial transaction.", xctx);
188 afw_lmdb_internal_open_database(
self, txn,
189 &afw_lmdb_s_Primary, MDB_CREATE, pool, xctx);
192 afw_lmdb_internal_open_database(
self, txn,
193 &afw_lmdb_s_Journal, MDB_CREATE, pool, xctx);
195 indexer = afw_lmdb_adaptor_impl_index_create(NULL,
self, txn, xctx);
199 self->internalConfig, &afw_lmdb_s_indexDefinitions, xctx);
200 if (indexDefinitions) {
201 afw_adaptor_impl_index_open_definitions(indexer,
202 indexDefinitions, pool, xctx);
207 rc = mdb_txn_commit(txn);
210 "Unable to commit initial transaction.", xctx);
228 &impl_afw_adaptor_inf,
230 properties, p, xctx);
235 &afw_s_ubjson, xctx);
239 "Unable to load UBJSON content-type", xctx);
246 "Property env required by LMDB adaptor.", xctx);
250 self->env = afw_lmdb_adaptor_parse_env(env, p, xctx);
253 rc = mdb_env_create(&self->dbEnv);
256 "Unable to initialize LMDB environment.", xctx);
260 if (self->env->maxdbs)
261 mdb_env_set_maxdbs(self->dbEnv, self->env->maxdbs);
263 mdb_env_set_maxdbs(self->dbEnv, 128);
266 if (self->env->maxreaders)
267 mdb_env_set_maxreaders(self->dbEnv, self->env->maxreaders);
270 if (self->env->mapsize)
271 mdb_env_set_mapsize(self->dbEnv, self->env->mapsize);
282 mdb_env_set_mapsize(self->dbEnv,
283 (self->env->mapsize && (self->env->mapsize < 7438953472) ?
284 self->env->mapsize : 7438953472));
288 rc = mdb_env_open(self->dbEnv, self->env->path_z, 0, self->env->mode);
291 "Unable to open LMDB environment. Check path and permissions.",
300 rc = mdb_reader_check(self->dbEnv, &deadReaders);
305 self->limits = afw_lmdb_adaptor_parse_limits(limits, xctx);
322 afw_lmdb_adaptor_load_configuration(
self, p, xctx);
342 apr_hash_index_t *hi;
345 for (hi = apr_hash_first(NULL, self->dbi_handles);
346 hi; hi = apr_hash_next(hi)) {
350 apr_hash_this(hi, (
const void **)&k, NULL, (
void**)&v);
351 mdb_dbi_close(self->dbEnv, v->dbi);
355 apr_thread_rwlock_destroy(self->dbLock);
358 mdb_env_close(self->dbEnv);
392 int major, minor, patch;
409 &afw_lmdb_s__AdaptiveAdaptorMetrics_adaptor_lmdb,
440 &afw_lmdb_s_version, xctx);
443 &afw_lmdb_s__AdaptiveAdaptorMetrics_adaptor_lmdb_version,
446 version_str = mdb_version(&major, &minor, &patch);
449 &afw_lmdb_s_version_string, version_str, xctx);
460 &afw_lmdb_s_statistics, xctx);
463 &afw_lmdb_s__AdaptiveAdaptorMetrics_adaptor_lmdb_statistics,
468 &afw_lmdb_s_environment, xctx);
471 &afw_lmdb_s__AdaptiveAdaptorMetrics_adaptor_lmdb_statistic,
474 rc = mdb_env_stat(self->dbEnv, &stat);
492 &afw_lmdb_s_information, xctx);
495 &afw_lmdb_s__AdaptiveAdaptorMetrics_adaptor_lmdb_information,
498 rc = mdb_env_info(self->dbEnv, &info);
514 apr_thread_rwlock_rdlock(self->dbLock);
516 rc = mdb_txn_begin(self->dbEnv, NULL, 0, &txn);
518 apr_thread_rwlock_unlock(self->dbLock);
521 "Unable to begin initial transaction.", xctx);
524 rc = mdb_dbi_open(txn, NULL, 0, &dbi);
530 rc = mdb_cursor_open(txn, dbi, &cursor);
532 while ((rc = mdb_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0)
536 if (memchr(key.mv_data,
'\0', key.mv_size))
539 memcpy(str, key.mv_data, key.mv_size);
540 str[key.mv_size] =
'\0';
544 db2 = afw_lmdb_internal_open_database(
self,
545 txn, database_str, 0, p, xctx);
546 if (db2 == 0)
continue;
548 rc = mdb_stat(txn, db2, &stat);
554 &afw_lmdb_s__AdaptiveAdaptorMetrics_adaptor_lmdb_statistic,
572 mdb_cursor_close(cursor);
575 mdb_close(self->dbEnv, dbi);
578 rc = mdb_txn_commit(txn);
580 apr_thread_rwlock_unlock(self->dbLock);
Adaptive Framework Core API.
Helpers for adaptor implementation development.
Interface afw_interface implementation declares.
Helpers for afw_adaptor implementation index development.
Adaptive Framework LMDB Adaptor.
void afw_lmdb_adaptor_open_databases(afw_lmdb_adaptor_t *self, const afw_pool_t *pool, afw_xctx_t *xctx)
const afw_adaptor_t * afw_lmdb_adaptor_create_cede_p(const afw_object_t *properties, const afw_pool_t *p, afw_xctx_t *xctx)
Internal create an LMDB adaptor.
afw_lmdb_adaptor_session_t * afw_lmdb_adaptor_session_create(afw_lmdb_adaptor_t *adaptor, afw_xctx_t *xctx)
Internal create a LMDB adaptor session.
Adaptive Framework register generated (afw_lmdb) header.
Helpers for afw_adaptor implementation index development.
Adaptive Framework LMDB Adaptor Internal Header.
const afw_object_t * impl_afw_adaptor_get_additional_metrics(const afw_adaptor_t *instance, const afw_pool_t *p, afw_xctx_t *xctx)
void impl_afw_adaptor_destroy(const afw_adaptor_t *instance, afw_xctx_t *xctx)
const afw_adaptor_session_t * impl_afw_adaptor_create_adaptor_session(const afw_adaptor_t *instance, afw_xctx_t *xctx)
afw_adaptor_impl_create_cede_p(const afw_adaptor_inf_t *inf, afw_size_t instance_size, const afw_object_t *properties, const afw_pool_t *p, afw_xctx_t *xctx)
Developers should call this in all create functions for afw_adaptor.
afw_value_create_integer(afw_integer_t internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type integer value.
afw_value_as_integer(const afw_value_t *value, afw_xctx_t *xctx)
Typesafe cast of data type integer.
#define afw_object_old_get_property_as_object(object, property_name, xctx)
Get property function for data type object value.
afw_value_as_object(const afw_value_t *value, afw_xctx_t *xctx)
Typesafe cast of data type object.
const afw_content_type_t * afw_environment_get_content_type(const afw_utf8_t *type, afw_xctx_t *xctx)
Get the afw_content_type struct associated with a content type.
#define AFW_THROW_ERROR_RV_Z(code, rv_source_id, rv, message_z, xctx)
Macro used to set error and rv in xctx and throw it.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
#define afw_object_get_property(instance, property_name, xctx)
Call method get_property of interface afw_object.
afw_object_create_clone(const afw_object_t *object, const afw_pool_t *p, afw_xctx_t *xctx)
Clone an object to a specified pool.
#define afw_object_create_managed(p, xctx)
Create an empty entity object in its own pool.
afw_object_set_property_as_string_from_utf8_z(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_utf8_z_t *string_z, afw_xctx_t *xctx)
Set an string property from utf8_z.
afw_object_set_property(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_value_t *value, afw_xctx_t *xctx)
Set the value of an object's property.
const afw_object_t * afw_object_create_embedded(const afw_object_t *embedding_object, const afw_utf8_t *property_name, afw_xctx_t *xctx)
Create an empty embedded object in a memory object.
#define afw_pool_malloc(instance, size, xctx)
Call method malloc of interface afw_pool.
#define afw_pool_get_apr_pool(instance)
Call method get_apr_pool of interface afw_pool.
#define afw_pool_release(instance, xctx)
Call method release of interface afw_pool.
int afw_safe_cast_integer_to_int(afw_integer_t integer, afw_xctx_t *xctx)
Safely cast afw_integer_t to int.
#define afw_utf8_create(s, len, p, xctx)
Create utf-8 string without copy unless necessary in pool specified.
afw_value_as_utf8_z(const afw_value_t *value, const afw_pool_t *p, afw_xctx_t *xctx)
#define afw_xctx_calloc_type(type, xctx)
Macro to allocate cleared memory to hold type in xctx's pool.
Interface afw_adaptor_impl_index public struct.
Interface afw_adaptor public struct.
Interface afw_adaptor_session public struct.
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Interface afw_value public struct.
Interface afw_xctx public struct.