mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-30 22:47:16 +08:00
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:
parent
2df38ad58b
commit
c9489da920
10
mdb.c
10
mdb.c
@ -3882,6 +3882,16 @@ mdb_env_map(MDB_env *env, void *addr)
|
|||||||
env->me_metas[0] = METADATA(p);
|
env->me_metas[0] = METADATA(p);
|
||||||
env->me_metas[1] = (MDB_meta *)((char *)env->me_metas[0] + env->me_psize);
|
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;
|
return MDB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user