mdbx: fix put(MDBX_UPSERT+MDBX_ALLDUPS) for case of replacement all values of a single key inside dupsorted subDb (backport).

Fixed cursor_put_nochecklen() internals for case when dupsort'ed named subDb
contains a single key with multiple values (aka duplicates), which are replaced
with a single value by put-operation with the `MDBX_UPSERT+MDBX_ALLDUPS` flags.

In this case, the database becomes completely empty, without any pages.
However exactly this condition was not considered and
thus wasn't handled correctly.

Fixes https://gitflic.ru/project/erthink/libmdbx/issue/8

Thanks Masatoshi Fukunaga <https://gitflic.ru/user/mah0x211> for reporting.
This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2023-02-01 16:18:42 +03:00
parent 6899142872
commit 51789f3605
2 changed files with 9 additions and 2 deletions

View File

@ -7,10 +7,17 @@ Fixes:
- Fixed insignificant typo of `||` inside `#if` byte-order condition (backport).
- Fixed`SIGSEGV` or an erroneous call to `free()` in situations where
- Fixed `SIGSEGV` or an erroneous call to `free()` in situations where
errors occur when reopening by `mdbx_env_open()` of a previously used
environment (backport).
- Fixed `cursor_put_nochecklen()` internals for case when dupsort'ed named subDb
contains a single key with multiple values (aka duplicates), which are replaced
with a single value by put-operation with the `MDBX_UPSERT+MDBX_ALLDUPS` flags (backport).
In this case, the database becomes completely empty, without any pages.
However exactly this condition was not considered and thus wasn't handled correctly.
See [issue#8](https://gitflic.ru/project/erthink/libmdbx/issue/8) for more information.
Minors:
- Using the https://libmdbx.dqdkfa.ru/dead-github

View File

@ -15559,7 +15559,7 @@ int mdbx_cursor_put(MDBX_cursor *mc, const MDBX_val *key, MDBX_val *data,
if (unlikely(rc != MDBX_SUCCESS))
return rc;
flags -= MDBX_ALLDUPS;
rc = MDBX_NOTFOUND;
rc = mc->mc_snum ? MDBX_NOTFOUND : MDBX_NO_ROOT;
exact = false;
} else /* checking for early exit without dirtying pages */
if (!(flags & (MDBX_RESERVE | MDBX_MULTIPLE)) &&