mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-10 12:24:12 +08:00
mdbx: backport - don't madvise(MADV_REMOVE).
Avoid lost changes and corruption in case a collision between mdbx_env_open() in one process and write-txn with next-pgno updates in an another process. Change-Id: I890db9251edbd77ac0ace10bed10a24517d709ec
This commit is contained in:
parent
4874852b79
commit
f55c30f286
13
mdb.c
13
mdb.c
@ -4341,7 +4341,7 @@ mdb_env_create(MDB_env **env)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int __cold
|
static int __cold
|
||||||
mdb_env_map(MDB_env *env, void *addr, size_t usedsize)
|
mdb_env_map(MDB_env *env, void *addr)
|
||||||
{
|
{
|
||||||
unsigned flags = env->me_flags;
|
unsigned flags = env->me_flags;
|
||||||
|
|
||||||
@ -4381,12 +4381,6 @@ mdb_env_map(MDB_env *env, void *addr, size_t usedsize)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MADV_REMOVE
|
|
||||||
if (flags & MDB_WRITEMAP) {
|
|
||||||
(void) madvise(env->me_map + usedsize, env->me_mapsize - usedsize, MADV_REMOVE);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Turn on/off readahead. It's harmful when the DB is larger than RAM. */
|
/* Turn on/off readahead. It's harmful when the DB is larger than RAM. */
|
||||||
if (madvise(env->me_map, env->me_mapsize, (flags & MDB_NORDAHEAD) ? MADV_RANDOM : MADV_WILLNEED))
|
if (madvise(env->me_map, env->me_mapsize, (flags & MDB_NORDAHEAD) ? MADV_RANDOM : MADV_WILLNEED))
|
||||||
return errno;
|
return errno;
|
||||||
@ -4439,7 +4433,7 @@ mdb_env_set_mapsize(MDB_env *env, size_t size)
|
|||||||
#endif
|
#endif
|
||||||
env->me_mapsize = size;
|
env->me_mapsize = size;
|
||||||
old = (env->me_flags & MDB_FIXEDMAP) ? env->me_map : NULL;
|
old = (env->me_flags & MDB_FIXEDMAP) ? env->me_map : NULL;
|
||||||
rc = mdb_env_map(env, old, usedsize);
|
rc = mdb_env_map(env, old);
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -4557,8 +4551,7 @@ mdb_env_open2(MDB_env *env, MDB_meta *meta)
|
|||||||
newenv = 0;
|
newenv = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t usedsize = (meta->mm_last_pg + 1) * env->me_psize;
|
rc = mdb_env_map(env, (flags & MDB_FIXEDMAP) ? meta->mm_address : NULL);
|
||||||
rc = mdb_env_map(env, (flags & MDB_FIXEDMAP) ? meta->mm_address : NULL, usedsize);
|
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user