ITS#8021 env_sync is invalid in RDONLY env

Change-Id: I2c9c8bcf4b28ea002cb5e4caa117396a82289924
This commit is contained in:
Howard Chu 2015-01-09 11:25:07 +00:00 committed by Leo Yuriev
parent 3fd4f9cce0
commit 13b144dc5d
2 changed files with 5 additions and 1 deletions

4
lmdb.h
View File

@ -714,7 +714,8 @@ int mdb_env_info(MDB_env *env, MDB_envinfo *stat);
* Data is always written to disk when #mdb_txn_commit() is called,
* but the operating system may keep it buffered. LMDB always flushes
* the OS buffers upon commit as well, unless the environment was
* opened with #MDB_NOSYNC or in part #MDB_NOMETASYNC.
* opened with #MDB_NOSYNC or in part #MDB_NOMETASYNC. This call is
* not valid if the environment was opened with #MDB_RDONLY.
* @param[in] env An environment handle returned by #mdb_env_create()
* @param[in] force If non-zero, force a synchronous flush. Otherwise
* if the environment has the #MDB_NOSYNC flag set the flushes
@ -722,6 +723,7 @@ int mdb_env_info(MDB_env *env, MDB_envinfo *stat);
* @return A non-zero error value on failure and 0 on success. Some possible
* errors are:
* <ul>
* <li>EACCES - the environment is read-only.
* <li>EINVAL - an invalid parameter was specified.
* <li>EIO - an error occurred during synchronization.
* </ul>

2
mdb.c
View File

@ -2530,6 +2530,8 @@ static int
mdb_env_sync0(MDB_env *env, int *force)
{
int rc = 0;
if (env->me_flags & MDB_RDONLY)
return EACCES;
if (env->me_sync_threshold && env->me_sync_pending >= env->me_sync_threshold)
*force = 1;
if (*force || !F_ISSET(env->me_flags, MDB_NOSYNC)) {