mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-31 10:58:20 +08:00
mdbx: use MDBX_EPERM
to indicate that the geometry cannot be updated instead of `MDBX_RESULT_TRUE'.
This commit is contained in:
parent
7654c9d9a1
commit
33a9395afe
13
mdbx.h
13
mdbx.h
@ -2880,10 +2880,15 @@ LIBMDBX_API int mdbx_env_get_fd(const MDBX_env *env, mdbx_filehandle_t *fd);
|
|||||||
* some possible errors are:
|
* some possible errors are:
|
||||||
* \retval MDBX_EINVAL An invalid parameter was specified,
|
* \retval MDBX_EINVAL An invalid parameter was specified,
|
||||||
* or the environment has an active write transaction.
|
* or the environment has an active write transaction.
|
||||||
* \retval MDBX_EPERM Specific for Windows: Shrinking was disabled before
|
* \retval MDBX_EPERM Two specific cases for Windows:
|
||||||
* and now it wanna be enabled, but there are reading
|
* 1) Shrinking was disabled before via geometry settings
|
||||||
* threads that don't use the additional `SRWL` (that
|
* and now it enabled, but there are reading threads that
|
||||||
* is required to avoid Windows issues).
|
* don't use the additional `SRWL` (which is required to
|
||||||
|
* avoid Windows issues).
|
||||||
|
* 2) Temporary close memory mapped is required to change
|
||||||
|
* geometry, but there read transaction(s) is running
|
||||||
|
* and no corresponding thread(s) could be suspended
|
||||||
|
* since the \ref MDBX_NOTLS mode is used.
|
||||||
* \retval MDBX_EACCESS The environment opened in read-only.
|
* \retval MDBX_EACCESS The environment opened in read-only.
|
||||||
* \retval MDBX_MAP_FULL Specified size smaller than the space already
|
* \retval MDBX_MAP_FULL Specified size smaller than the space already
|
||||||
* consumed by the environment.
|
* consumed by the environment.
|
||||||
|
@ -6234,7 +6234,7 @@ bailout:
|
|||||||
}
|
}
|
||||||
#endif /* MDBX_USE_VALGRIND */
|
#endif /* MDBX_USE_VALGRIND */
|
||||||
} else {
|
} else {
|
||||||
if (rc != MDBX_UNABLE_EXTEND_MAPSIZE && rc != MDBX_RESULT_TRUE) {
|
if (rc != MDBX_UNABLE_EXTEND_MAPSIZE && rc != MDBX_EPERM) {
|
||||||
mdbx_error("failed resize datafile/mapping: "
|
mdbx_error("failed resize datafile/mapping: "
|
||||||
"present %" PRIuPTR " -> %" PRIuPTR ", "
|
"present %" PRIuPTR " -> %" PRIuPTR ", "
|
||||||
"limit %" PRIuPTR " -> %" PRIuPTR ", errcode %d",
|
"limit %" PRIuPTR " -> %" PRIuPTR ", errcode %d",
|
||||||
@ -8716,7 +8716,7 @@ static int mdbx_txn_end(MDBX_txn *txn, const unsigned mode) {
|
|||||||
/* undo resize performed by child txn */
|
/* undo resize performed by child txn */
|
||||||
rc = mdbx_mapresize_implicit(env, parent->mt_next_pgno,
|
rc = mdbx_mapresize_implicit(env, parent->mt_next_pgno,
|
||||||
parent->mt_geo.now, parent->mt_geo.upper);
|
parent->mt_geo.now, parent->mt_geo.upper);
|
||||||
if (rc == MDBX_RESULT_TRUE) {
|
if (rc == MDBX_EPERM) {
|
||||||
/* unable undo resize (it is regular for Windows),
|
/* unable undo resize (it is regular for Windows),
|
||||||
* therefore promote size changes from child to the parent txn */
|
* therefore promote size changes from child to the parent txn */
|
||||||
mdbx_warning("unable undo resize performed by child txn, promote to "
|
mdbx_warning("unable undo resize performed by child txn, promote to "
|
||||||
@ -11256,7 +11256,7 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
|
|||||||
pending->mm_geo.now, shrink);
|
pending->mm_geo.now, shrink);
|
||||||
rc = mdbx_mapresize_implicit(env, pending->mm_geo.next, pending->mm_geo.now,
|
rc = mdbx_mapresize_implicit(env, pending->mm_geo.next, pending->mm_geo.now,
|
||||||
pending->mm_geo.upper);
|
pending->mm_geo.upper);
|
||||||
if (MDBX_IS_ERROR(rc))
|
if (rc != MDBX_SUCCESS && rc != MDBX_EPERM)
|
||||||
goto fail;
|
goto fail;
|
||||||
mdbx_assert(env, meta_checktxnid(env, target, true));
|
mdbx_assert(env, meta_checktxnid(env, target, true));
|
||||||
}
|
}
|
||||||
|
@ -1619,7 +1619,7 @@ MDBX_INTERNAL_FUNC int mdbx_mresize(const int flags, mdbx_mmap_t *map,
|
|||||||
* - extend read-only mapping;
|
* - extend read-only mapping;
|
||||||
* Therefore we should unmap/map entire section. */
|
* Therefore we should unmap/map entire section. */
|
||||||
if ((flags & MDBX_MRESIZE_MAY_UNMAP) == 0)
|
if ((flags & MDBX_MRESIZE_MAY_UNMAP) == 0)
|
||||||
return MDBX_RESULT_TRUE;
|
return MDBX_EPERM;
|
||||||
|
|
||||||
/* Unpoisoning is required for ASAN to avoid false-positive diagnostic
|
/* Unpoisoning is required for ASAN to avoid false-positive diagnostic
|
||||||
* when this memory will re-used by malloc or another mmapping.
|
* when this memory will re-used by malloc or another mmapping.
|
||||||
@ -1729,7 +1729,7 @@ retry_mapview:;
|
|||||||
if (map->address && (size != map->current || limit != map->limit)) {
|
if (map->address && (size != map->current || limit != map->limit)) {
|
||||||
/* try remap with previously size and limit,
|
/* try remap with previously size and limit,
|
||||||
* but will return MDBX_UNABLE_EXTEND_MAPSIZE on success */
|
* but will return MDBX_UNABLE_EXTEND_MAPSIZE on success */
|
||||||
rc = (limit > map->limit) ? MDBX_UNABLE_EXTEND_MAPSIZE : MDBX_RESULT_TRUE;
|
rc = (limit > map->limit) ? MDBX_UNABLE_EXTEND_MAPSIZE : MDBX_EPERM;
|
||||||
size = map->current;
|
size = map->current;
|
||||||
ReservedSize = limit = map->limit;
|
ReservedSize = limit = map->limit;
|
||||||
goto retry_file_and_section;
|
goto retry_file_and_section;
|
||||||
@ -1753,8 +1753,7 @@ retry_mapview:;
|
|||||||
if (flags & MDBX_RDONLY) {
|
if (flags & MDBX_RDONLY) {
|
||||||
map->current = (map->filesize > limit) ? limit : (size_t)map->filesize;
|
map->current = (map->filesize > limit) ? limit : (size_t)map->filesize;
|
||||||
if (map->current != size)
|
if (map->current != size)
|
||||||
rc =
|
rc = (size > map->current) ? MDBX_UNABLE_EXTEND_MAPSIZE : MDBX_EPERM;
|
||||||
(size > map->current) ? MDBX_UNABLE_EXTEND_MAPSIZE : MDBX_RESULT_TRUE;
|
|
||||||
} else {
|
} else {
|
||||||
if (map->filesize != size) {
|
if (map->filesize != size) {
|
||||||
rc = mdbx_ftruncate(map->fd, size);
|
rc = mdbx_ftruncate(map->fd, size);
|
||||||
|
@ -115,8 +115,7 @@ bool testcase_jitter::run() {
|
|||||||
db_guard.get(), -1, -1,
|
db_guard.get(), -1, -1,
|
||||||
coin4size ? upper_limit * 2 / 3 : upper_limit * 3 / 2, -1, -1, -1);
|
coin4size ? upper_limit * 2 / 3 : upper_limit * 3 / 2, -1, -1, -1);
|
||||||
if (err != MDBX_SUCCESS && err != MDBX_UNABLE_EXTEND_MAPSIZE &&
|
if (err != MDBX_SUCCESS && err != MDBX_UNABLE_EXTEND_MAPSIZE &&
|
||||||
err != MDBX_MAP_FULL && err != MDBX_TOO_LARGE &&
|
err != MDBX_MAP_FULL && err != MDBX_TOO_LARGE && err != MDBX_EPERM)
|
||||||
err != MDBX_RESULT_TRUE)
|
|
||||||
failure_perror("mdbx_env_set_geometry-1", err);
|
failure_perror("mdbx_env_set_geometry-1", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,8 +126,7 @@ bool testcase_jitter::run() {
|
|||||||
db_guard.get(), -1, -1,
|
db_guard.get(), -1, -1,
|
||||||
!coin4size ? upper_limit * 2 / 3 : upper_limit * 3 / 2, -1, -1, -1);
|
!coin4size ? upper_limit * 2 / 3 : upper_limit * 3 / 2, -1, -1, -1);
|
||||||
if (err != MDBX_SUCCESS && err != MDBX_UNABLE_EXTEND_MAPSIZE &&
|
if (err != MDBX_SUCCESS && err != MDBX_UNABLE_EXTEND_MAPSIZE &&
|
||||||
err != MDBX_MAP_FULL && err != MDBX_TOO_LARGE &&
|
err != MDBX_MAP_FULL && err != MDBX_TOO_LARGE && err != MDBX_EPERM)
|
||||||
err != MDBX_RESULT_TRUE)
|
|
||||||
failure_perror("mdbx_env_set_geometry-2", err);
|
failure_perror("mdbx_env_set_geometry-2", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,8 +142,7 @@ bool testcase_jitter::run() {
|
|||||||
err = mdbx_env_set_geometry(db_guard.get(), -1, -1, upper_limit, -1, -1,
|
err = mdbx_env_set_geometry(db_guard.get(), -1, -1, upper_limit, -1, -1,
|
||||||
-1);
|
-1);
|
||||||
if (err != MDBX_SUCCESS && err != MDBX_UNABLE_EXTEND_MAPSIZE &&
|
if (err != MDBX_SUCCESS && err != MDBX_UNABLE_EXTEND_MAPSIZE &&
|
||||||
err != MDBX_MAP_FULL && err != MDBX_TOO_LARGE &&
|
err != MDBX_MAP_FULL && err != MDBX_TOO_LARGE && err != MDBX_EPERM)
|
||||||
err != MDBX_RESULT_TRUE)
|
|
||||||
failure_perror("mdbx_env_set_geometry-3", err);
|
failure_perror("mdbx_env_set_geometry-3", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user