diff --git a/README.md b/README.md index 7887838..f9465fb 100644 --- a/README.md +++ b/README.md @@ -294,6 +294,7 @@ The following configuration settings may be applied (a `Y` in column `$` means a | `OTR_CAPATH` | Y | | Directory of c_rehashed PEM certificates | `OTR_CERTFILE` | Y | | Path to PEM-encoded client certificate for MQTT | `OTR_KEYFILE` | Y | | Path to PEM-encoded client key for MQTT +| `OTR_LMDBSIZE` | Y | `104857600000` | size of the LMDB database. If less than 10485760 (10 MB) it will be set to 10485760. Note that options passed to `ot-recorder` override both configuration file settings and environment variables. diff --git a/gcache.c b/gcache.c index 8398fff..b5e413f 100644 --- a/gcache.c +++ b/gcache.c @@ -32,10 +32,19 @@ struct gcache *gcache_open(char *path, char *dbname, int rdonly) { + size_t lmdb_size = LMDB_DB_SIZE; MDB_txn *txn = NULL; int rc; unsigned int flags = 0, dbiflags = 0, perms = 0664; struct gcache *gc; + char *p; + + if ((p = getenv("OTR_LMDBSIZE")) != NULL) { + lmdb_size = atol(p); + if (lmdb_size < 10485760) { // 10 MB + lmdb_size = 10485760; + } + } if (!is_directory(path)) { olog(LOG_ERR, "gcache_open: %s is not a directory", path); @@ -62,7 +71,7 @@ struct gcache *gcache_open(char *path, char *dbname, int rdonly) return (NULL); } - mdb_env_set_mapsize(gc->env, LMDB_DB_SIZE); + mdb_env_set_mapsize(gc->env, lmdb_size); rc = mdb_env_set_maxdbs(gc->env, 10); if (rc != 0) {