diff --git a/mdbx.h b/mdbx.h index 1e71f1ad..b5d85921 100644 --- a/mdbx.h +++ b/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: * \retval MDBX_EINVAL An invalid parameter was specified, * or the environment has an active write transaction. - * \retval MDBX_EPERM Specific for Windows: Shrinking was disabled before - * and now it wanna be enabled, but there are reading - * threads that don't use the additional `SRWL` (that - * is required to avoid Windows issues). + * \retval MDBX_EPERM Two specific cases for Windows: + * 1) Shrinking was disabled before via geometry settings + * and now it enabled, but there are reading threads that + * 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_MAP_FULL Specified size smaller than the space already * consumed by the environment. diff --git a/src/core.c b/src/core.c index 9cb5f513..5eb3190c 100644 --- a/src/core.c +++ b/src/core.c @@ -6234,7 +6234,7 @@ bailout: } #endif /* MDBX_USE_VALGRIND */ } 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: " "present %" PRIuPTR " -> %" PRIuPTR ", " "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 */ rc = mdbx_mapresize_implicit(env, parent->mt_next_pgno, 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), * therefore promote size changes from child to the parent txn */ 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); rc = mdbx_mapresize_implicit(env, pending->mm_geo.next, pending->mm_geo.now, pending->mm_geo.upper); - if (MDBX_IS_ERROR(rc)) + if (rc != MDBX_SUCCESS && rc != MDBX_EPERM) goto fail; mdbx_assert(env, meta_checktxnid(env, target, true)); } diff --git a/src/osal.c b/src/osal.c index 51a170af..f0cb13b5 100644 --- a/src/osal.c +++ b/src/osal.c @@ -1619,7 +1619,7 @@ MDBX_INTERNAL_FUNC int mdbx_mresize(const int flags, mdbx_mmap_t *map, * - extend read-only mapping; * Therefore we should unmap/map entire section. */ if ((flags & MDBX_MRESIZE_MAY_UNMAP) == 0) - return MDBX_RESULT_TRUE; + return MDBX_EPERM; /* Unpoisoning is required for ASAN to avoid false-positive diagnostic * 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)) { /* try remap with previously size and limit, * 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; ReservedSize = limit = map->limit; goto retry_file_and_section; @@ -1753,8 +1753,7 @@ retry_mapview:; if (flags & MDBX_RDONLY) { map->current = (map->filesize > limit) ? limit : (size_t)map->filesize; if (map->current != size) - rc = - (size > map->current) ? MDBX_UNABLE_EXTEND_MAPSIZE : MDBX_RESULT_TRUE; + rc = (size > map->current) ? MDBX_UNABLE_EXTEND_MAPSIZE : MDBX_EPERM; } else { if (map->filesize != size) { rc = mdbx_ftruncate(map->fd, size); diff --git a/test/jitter.cc b/test/jitter.cc index b51c8124..2c781d7f 100644 --- a/test/jitter.cc +++ b/test/jitter.cc @@ -115,8 +115,7 @@ bool testcase_jitter::run() { db_guard.get(), -1, -1, coin4size ? upper_limit * 2 / 3 : upper_limit * 3 / 2, -1, -1, -1); if (err != MDBX_SUCCESS && err != MDBX_UNABLE_EXTEND_MAPSIZE && - err != MDBX_MAP_FULL && err != MDBX_TOO_LARGE && - err != MDBX_RESULT_TRUE) + err != MDBX_MAP_FULL && err != MDBX_TOO_LARGE && err != MDBX_EPERM) failure_perror("mdbx_env_set_geometry-1", err); } } @@ -127,8 +126,7 @@ bool testcase_jitter::run() { db_guard.get(), -1, -1, !coin4size ? upper_limit * 2 / 3 : upper_limit * 3 / 2, -1, -1, -1); if (err != MDBX_SUCCESS && err != MDBX_UNABLE_EXTEND_MAPSIZE && - err != MDBX_MAP_FULL && err != MDBX_TOO_LARGE && - err != MDBX_RESULT_TRUE) + err != MDBX_MAP_FULL && err != MDBX_TOO_LARGE && err != MDBX_EPERM) 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, -1); if (err != MDBX_SUCCESS && err != MDBX_UNABLE_EXTEND_MAPSIZE && - err != MDBX_MAP_FULL && err != MDBX_TOO_LARGE && - err != MDBX_RESULT_TRUE) + err != MDBX_MAP_FULL && err != MDBX_TOO_LARGE && err != MDBX_EPERM) failure_perror("mdbx_env_set_geometry-3", err); }