From: Howard Chu Date: Tue, 11 Dec 2012 20:03:19 +0000 (-0800) Subject: Partially revert 65d40eb5d2c7c28df05e2c1d9b21d90e2a82e0b5 X-Git-Tag: OPENLDAP_REL_ENG_2_4_34~80^2~3 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e74d70e88e838c0f1e80b00e7c3cf6ea57762d0d;p=openldap Partially revert 65d40eb5d2c7c28df05e2c1d9b21d90e2a82e0b5 Allow both increasing and decreasing the environment size. But don't allow decreasing below the currently occupied space. --- diff --git a/libraries/liblmdb/lmdb.h b/libraries/liblmdb/lmdb.h index 9c21cdc68b..e4d55c8b22 100644 --- a/libraries/liblmdb/lmdb.h +++ b/libraries/liblmdb/lmdb.h @@ -574,6 +574,9 @@ int mdb_env_get_path(MDB_env *env, const char **path); * of the database. The value should be chosen as large as possible, * to accommodate future growth of the database. * This function may only be called after #mdb_env_create() and before #mdb_env_open(). + * The size may be changed by closing and reopening the environment. + * Any attempt to set a size smaller than the space already consumed + * by the environment will be silently changed to the current size of the used space. * @param[in] env An environment handle returned by #mdb_env_create() * @param[in] size The size in bytes * @return A non-zero error value on failure and 0 on success. Some possible diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 4fe330b1d1..b25c372fb7 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -2722,11 +2722,22 @@ mdb_env_open2(MDB_env *env) return i; DPUTS("new mdbenv"); newenv = 1; - meta.mm_mapsize = env->me_mapsize > DEFAULT_MAPSIZE ? env->me_mapsize : DEFAULT_MAPSIZE; } - if (env->me_mapsize < meta.mm_mapsize) - env->me_mapsize = meta.mm_mapsize; + /* Was a mapsize configured? */ + if (!env->me_mapsize) { + /* If this is a new environment, take the default, + * else use the size recorded in the existing env. + */ + env->me_mapsize = newenv ? DEFAULT_MAPSIZE : meta.mm_mapsize; + } else if (env->me_mapsize < meta.mm_mapsize) { + /* If the configured size is smaller, make sure it's + * still big enough. Silently round up to minimum if not. + */ + size_t minsize = (meta.mm_last_pg + 1) * meta.mm_psize; + if (env->me_mapsize < minsize) + env->me_mapsize = minsize; + } #ifdef _WIN32 {