lmdb: lock meta-pages in writemap-mode to avoid unordered write.

Without locking the meta-pages may be writen by OS before data pages,
in this case database would be inconsistent.

Change-Id: I6a262709b0741d7b57cb68231c4ae1c62a10a743
This commit is contained in:
Leo Yuriev 2014-09-20 07:16:15 +04:00
parent 2df38ad58b
commit c9489da920

10
mdb.c
View File

@ -3882,6 +3882,16 @@ mdb_env_map(MDB_env *env, void *addr)
env->me_metas[0] = METADATA(p);
env->me_metas[1] = (MDB_meta *)((char *)env->me_metas[0] + env->me_psize);
/* Lock meta pages to avoid unexpected write,
* before the data pages would be synchronized. */
#ifdef _WIN32
if ((flags & MDB_WRITEMAP) && !VirtualLock(env->me_map, env->me_psize * 2))
return ErrCode();
#else
if ((flags & MDB_WRITEMAP) && mlock(env->me_map, env->me_psize * 2))
return ErrCode();
#endif /* _WIN32 */
return MDB_SUCCESS;
}