mdbx: rename MDBX_MAP_RESIZED to MDBX_UNABLE_EXTEND_MAPSIZE.

Change-Id: I22fbdb4f08fd7a6ae37da42e6827677ae8a8337b
This commit is contained in:
Leo Yuriev 2020-02-28 16:08:58 +03:00
parent 63449a44c5
commit 5072b45026
3 changed files with 40 additions and 37 deletions

43
mdbx.h
View File

@ -1453,9 +1453,14 @@ typedef enum MDBX_cursor_op {
/* Page has not enough space - internal error */
#define MDBX_PAGE_FULL (-30786)
/* Database contents grew beyond environment mapsize and engine was
* unable to extend mapping, e.g. since address space is unavailable or busy */
#define MDBX_MAP_RESIZED (-30785)
/* Database engine was unable to extend mapping, e.g. since address space
* is unavailable or busy. This can mean:
* - Database size extended by other process beyond to environment mapsize
* and engine was unable to extend mapping while starting read transaction.
* Environment should be reopened to continue.
* - Engine was unable to extend mapping during write transaction
* or explicit call of mdbx_env_set_geometry(). */
#define MDBX_UNABLE_EXTEND_MAPSIZE (-30785)
/* Environment or database is not compatible with the requested operation
* or the specified flags. This can mean:
@ -2027,9 +2032,9 @@ LIBMDBX_API int mdbx_env_get_fd(MDBX_env *env, mdbx_filehandle_t *fd);
* size. Besides, the upper bound defines the linear address space
* reservation in each process that opens the database. Therefore changing
* the upper bound is costly and may be required reopening environment in
* case of MDBX_MAP_RESIZED errors, and so on. Therefore, this value should
* be chosen reasonable as large as possible, to accommodate future growth
* of the database.
* case of MDBX_UNABLE_EXTEND_MAPSIZE errors, and so on. Therefore, this
* value should be chosen reasonable as large as possible, to accommodate
* future growth of the database.
* - The growth step must be greater than zero to allow the database to grow,
* but also reasonable not too small, since increasing the size by little
* steps will result a large overhead.
@ -2049,6 +2054,7 @@ LIBMDBX_API int mdbx_env_get_fd(MDBX_env *env, mdbx_filehandle_t *fd);
* - Windows does not provide the usual API to augment a memory-mapped file
* (that is, a memory-mapped partition), but only by using "Native API"
* in an undocumented way.
*
* MDBX bypasses all Windows issues, but at a cost:
* - Ability to resize database on the fly requires an additional lock
* and release SlimReadWriteLock during each read-only transaction.
@ -2069,10 +2075,10 @@ LIBMDBX_API int mdbx_env_get_fd(MDBX_env *env, mdbx_filehandle_t *fd);
*
* If the mapsize is increased by another process, MDBX silently and
* transparently adopt these changes at next transaction start. However,
* mdbx_txn_begin() will return MDBX_MAP_RESIZED if new mapping size could not
* be applied for current process (for instance if address space is busy).
* Therefore, in the case of MDBX_MAP_RESIZED error you need close and reopen
* the environment to resolve error.
* mdbx_txn_begin() will return MDBX_UNABLE_EXTEND_MAPSIZE if new mapping size
* could not be applied for current process (for instance if address space
* is busy). Therefore, in the case of MDBX_UNABLE_EXTEND_MAPSIZE error you
* need close and reopen the environment to resolve error.
*
* NOTE: Actual values may be different than your have specified because of
* rounding to specified database page size, the system page size and/or the
@ -2103,13 +2109,13 @@ LIBMDBX_API int mdbx_env_get_fd(MDBX_env *env, mdbx_filehandle_t *fd);
* database is used by other processes or threaded
* (i.e. just pass -1 in this argument except absolutely
* necessity). Otherwise you must be ready for
* MDBX_MAP_RESIZED error(s), unexpected pauses during
* remapping and/or system errors like "addtress busy",
* and so on. In other words, there is no way to handle
* a growth of the upper bound robustly because there may
* be a lack of appropriate system resources (which are
* extremely volatile in a multi-process multi-threaded
* environment).
* MDBX_UNABLE_EXTEND_MAPSIZE error(s), unexpected pauses
* during remapping and/or system errors like "addtress
* busy", and so on. In other words, there is no way to
* handle a growth of the upper bound robustly because
* there may be a lack of appropriate system resources
* (which are extremely volatile in a multi-process
* multi-threaded environment).
*
* [in] growth_step The growth step in bytes, must be greater than zero
* to allow the database to grow.
@ -2301,7 +2307,8 @@ LIBMDBX_API void *mdbx_env_get_userctx(MDBX_env *env);
* possible errors are:
* - MDBX_PANIC = a fatal error occurred earlier and the environment
* must be shut down.
* - MDBX_MAP_RESIZED = another process wrote data beyond this MDBX_env's
* - MDBX_UNABLE_EXTEND_MAPSIZE
* = another process wrote data beyond this MDBX_env's
* mapsize and this environment's map must be resized
* as well. See mdbx_env_set_mapsize().
* - MDBX_READERS_FULL = a read-only transaction was requested and the reader

View File

@ -3184,12 +3184,12 @@ static const char *__mdbx_strerr(int errnum) {
"MDBX_READERS_FULL: Too many readers (maxreaders reached)",
NULL /* MDBX_TLS_FULL (-30789): unused in MDBX */,
"MDBX_TXN_FULL: Transaction has too many dirty pages,"
" i.e transaction too big",
" i.e transaction is too big",
"MDBX_CURSOR_FULL: Internal error - Cursor stack limit reached",
"MDBX_PAGE_FULL: Internal error - Page has no more space",
"MDBX_MAP_RESIZED: Database contents grew beyond environment mapsize"
" and engine was unable to extend mapping,"
" e.g. since address space is unavailable or busy",
"MDBX_UNABLE_EXTEND_MAPSIZE: Database engine was unable to extend"
" mapping, e.g. since address space is unavailable or busy,"
" or Operation system not supported such operations"
"MDBX_INCOMPATIBLE: Environment or database is not compatible"
" with the requested operation or the specified flags",
"MDBX_BAD_RSLOT: Invalid reuse of reader locktable slot,"
@ -4762,7 +4762,7 @@ bailout:
}
#endif /* MDBX_USE_VALGRIND */
} else {
if (rc != MDBX_RESULT_TRUE) {
if (rc != MDBX_UNABLE_EXTEND_MAPSIZE) {
mdbx_error("failed resize datafile/mapping: "
"present %" PRIuPTR " -> %" PRIuPTR ", "
"limit %" PRIuPTR " -> %" PRIuPTR ", errcode %d",
@ -5250,7 +5250,7 @@ skip_cache:
rc = MDBX_NOTFOUND;
if (flags & MDBX_ALLOC_NEW) {
rc = MDBX_MAP_FULL;
if (next <= txn->mt_geo.upper) {
if (next <= txn->mt_geo.upper && txn->mt_geo.grow) {
mdbx_assert(env, next > txn->mt_end_pgno);
pgno_t aligned = pgno_align2os_pgno(
env, pgno_add(next, txn->mt_geo.grow - next % txn->mt_geo.grow));
@ -5271,7 +5271,6 @@ skip_cache:
mdbx_error("unable growth datafile to %" PRIaPGNO " pages (+%" PRIaPGNO
"), errcode %d",
aligned, aligned - txn->mt_end_pgno, rc);
rc = (rc == MDBX_RESULT_TRUE) ? MDBX_MAP_FULL : rc;
} else {
mdbx_debug("gc-alloc: next %u > upper %u", next, txn->mt_geo.upper);
}
@ -6051,16 +6050,13 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
if (txn->mt_geo.upper > MAX_PAGENO ||
bytes2pgno(env, pgno2bytes(env, txn->mt_geo.upper)) !=
txn->mt_geo.upper) {
rc = MDBX_MAP_RESIZED;
rc = MDBX_UNABLE_EXTEND_MAPSIZE;
goto bailout;
}
rc = mdbx_mapresize(env, txn->mt_next_pgno, txn->mt_end_pgno,
txn->mt_geo.upper);
if (rc != MDBX_SUCCESS) {
if (rc == MDBX_RESULT_TRUE)
rc = MDBX_MAP_RESIZED;
if (rc != MDBX_SUCCESS)
goto bailout;
}
}
if (txn->mt_flags & MDBX_RDONLY) {
#if defined(_WIN32) || defined(_WIN64)

View File

@ -1404,7 +1404,7 @@ MDBX_INTERNAL_FUNC int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t size,
if (!(flags & MDBX_RDONLY) && limit == map->limit && size > map->current) {
/* growth rw-section */
if (!mdbx_NtExtendSection)
return ERROR_CALL_NOT_IMPLEMENTED /* workaround for Wine */;
return MDBX_UNABLE_EXTEND_MAPSIZE /* workaround for Wine */;
SectionSize.QuadPart = size;
status = mdbx_NtExtendSection(map->section, &SectionSize);
if (!NT_SUCCESS(status))
@ -1422,7 +1422,7 @@ MDBX_INTERNAL_FUNC int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t size,
status = NtAllocateVirtualMemory(GetCurrentProcess(), &BaseAddress, 0,
&RegionSize, MEM_RESERVE, PAGE_NOACCESS);
if (status == /* STATUS_CONFLICTING_ADDRESSES */ 0xC0000018)
return MDBX_RESULT_TRUE;
return MDBX_UNABLE_EXTEND_MAPSIZE;
if (!NT_SUCCESS(status))
return ntstatus2errcode(status);
@ -1540,8 +1540,8 @@ retry_mapview:;
if (map->address && (size != map->current || limit != map->limit)) {
/* try remap with previously size and limit,
* but will return MDBX_RESULT_TRUE on success */
rc = MDBX_RESULT_TRUE;
* but will return MDBX_UNABLE_EXTEND_MAPSIZE on success */
rc = MDBX_UNABLE_EXTEND_MAPSIZE;
size = map->current;
limit = map->limit;
goto retry_file_and_section;
@ -1564,7 +1564,7 @@ retry_mapview:;
if (flags & MDBX_RDONLY) {
map->current = (filesize > limit) ? limit : (size_t)filesize;
if (map->current != size)
rc = MDBX_RESULT_TRUE;
rc = MDBX_UNABLE_EXTEND_MAPSIZE;
} else if (filesize != size) {
rc = mdbx_ftruncate(map->fd, size);
if (rc != MDBX_SUCCESS)
@ -1581,7 +1581,7 @@ retry_mapview:;
case EAGAIN:
case ENOMEM:
case EFAULT /* MADV_DODUMP / MADV_DONTDUMP are mixed for mmap-range */:
rc = MDBX_RESULT_TRUE;
rc = MDBX_UNABLE_EXTEND_MAPSIZE;
}
return rc;
}
@ -1600,7 +1600,7 @@ retry_mapview:;
#else /* MREMAP_MAYMOVE */
/* TODO: Perhaps here it is worth to implement suspend/resume threads
* and perform unmap/map as like for Windows. */
rc = MDBX_RESULT_TRUE;
rc = MDBX_UNABLE_EXTEND_MAPSIZE;
#endif /* !MREMAP_MAYMOVE */
}
#endif