Skip to content

Commit 6d35ab9

Browse files
committed
fpta: update libmdbx to 0.11.2.22 (MDBX_SHRINK_ALLOWED / MDBX_ACCEDE collision).
1 parent 6bcef29 commit 6d35ab9

File tree

12 files changed

+229
-38
lines changed

12 files changed

+229
-38
lines changed

externals/libmdbx/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ endif()
434434
# #### # # # #### # # ####
435435
#
436436

437-
set(MDBX_BUILD_OPTIONS ENABLE_ASAN MDBX_USE_VALGRIND ENABLE_GPROF ENABLE_GCOV)
437+
set(MDBX_BUILD_OPTIONS ENABLE_UBSAN ENABLE_ASAN MDBX_USE_VALGRIND ENABLE_GPROF ENABLE_GCOV)
438438
macro(add_mdbx_option NAME DESCRIPTION DEFAULT)
439439
list(APPEND MDBX_BUILD_OPTIONS ${NAME})
440440
if(NOT ${DEFAULT} STREQUAL "AUTO")
@@ -863,7 +863,7 @@ else()
863863
endif()
864864

865865
# options
866-
set(options VERSION C_COMPILER CXX_COMPILER MDBX_BUILD_TARGET MDBX_BUILD_TYPE)
866+
set(options VERSION C_COMPILER CXX_COMPILER MDBX_BUILD_TARGET MDBX_BUILD_TYPE ${MDBX_BUILD_OPTIONS})
867867
foreach(item IN LISTS options)
868868
if(DEFINED ${item})
869869
set(value "${${item}}")
@@ -874,7 +874,7 @@ foreach(item IN LISTS options)
874874
set(item CMAKE_${item})
875875
set(value "${${item}}")
876876
else()
877-
set(value "undefined")
877+
set(value "AUTO (not pre-defined explicitly)")
878878
endif()
879879
message(STATUS "${item}: ${value}")
880880
endforeach(item)

externals/libmdbx/ChangeLog.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,28 @@ ChangeLog
2323
Acknowledgements:
2424

2525
- [gcxfd <i@rmw.link>](https://github.com/gcxfd) for reporting, contributing and testing.
26+
- [장세연 (Чан Се Ен)](https://github.com/sasgas) for reporting and testing.
27+
28+
New features, extensions and improvements:
29+
30+
- [Added](https://github.com/erthink/libmdbx/issues/236) `mdbx_cursor_get_batch()`.
31+
- [Added](https://github.com/erthink/libmdbx/issues/250) `MDBX_SET_UPPERBOUND`.
2632

2733
Fixes:
2834

2935
- Disabled C++20 concepts for stupid AppleClang 13.x
36+
- Fixed internal collision of `MDBX_SHRINK_ALLOWED` with `MDBX_ACCEDE`.
3037

3138
Minors:
3239

33-
- Fixed returning `MDBX_RESULT_TRUE` (-1) from `mdbx_env_set_option()`.
40+
- Fixed returning `MDBX_RESULT_TRUE` (unexpected -1) from `mdbx_env_set_option()`.
3441
- Added `mdbx_env_get_syncbytes()` and `mdbx_env_get_syncperiod()`.
3542
- [Clarified](https://github.com/erthink/libmdbx/pull/249) description of `MDBX_INTEGERKEY`.
3643
- Reworked/simplified `mdbx_env_sync_internal()`.
3744
- [Fixed](https://github.com/erthink/libmdbx/issues/248) extra assertion inside `mdbx_cursor_put()` for `MDBX_DUPFIXED` cases.
3845
- Avoiding extra looping inside `mdbx_env_info_ex()`.
46+
- Explicitly enabled core dumps from stochastic tests scripts on Linux.
47+
- [Fixed](https://github.com/erthink/libmdbx/issues/253) `mdbx_override_meta()` to avoid false-positive assertions.
3948

4049

4150
## v0.11.2 at 2021-12-02
@@ -106,7 +115,7 @@ Fixes:
106115
Minors:
107116

108117
- Refined handling of weak or invalid meta-pages while a DB opening.
109-
- Refined providing information for the @MAIN and @GC sub-databases of a last committed modification transaction's ID.
118+
- Refined providing information for the `@MAIN` and `@GC` sub-databases of a last committed modification transaction's ID.
110119

111120

112121
## v0.10.4 at 2021-10-10

externals/libmdbx/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.11.2.15
1+
0.11.2.22

externals/libmdbx/mdbx.c

Lines changed: 150 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* <http://www.OpenLDAP.org/license.html>. */
1313

1414
#define xMDBX_ALLOY 1
15-
#define MDBX_BUILD_SOURCERY c5b9a3e9ba7c98987e7554f0c84c1e12e9f82d0d470ad881d54923ecf3599c17_v0_11_2_15_gca197965
15+
#define MDBX_BUILD_SOURCERY eceee647cf2c0dcedb1c09cb1f7c82a14d9efc74380e3954b5a3f158d5b8c29b_v0_11_2_22_gc70d2d62
1616
#ifdef MDBX_CONFIG_H
1717
#include MDBX_CONFIG_H
1818
#endif
@@ -7091,7 +7091,8 @@ static void mdbx_node_del(MDBX_cursor *mc, size_t ksize);
70917091
static void mdbx_node_shrink(MDBX_page *mp, unsigned indx);
70927092
static int __must_check_result mdbx_node_move(MDBX_cursor *csrc,
70937093
MDBX_cursor *cdst, bool fromleft);
7094-
static int __must_check_result mdbx_node_read(MDBX_cursor *mc, MDBX_node *leaf,
7094+
static int __must_check_result mdbx_node_read(MDBX_cursor *mc,
7095+
const MDBX_node *leaf,
70957096
MDBX_val *data,
70967097
const txnid_t front);
70977098
static int __must_check_result mdbx_rebalance(MDBX_cursor *mc);
@@ -10350,7 +10351,7 @@ __cold static int mdbx_env_sync_internal(MDBX_env *env, bool force,
1035010351
int rc = MDBX_RESULT_TRUE /* means "nothing to sync" */;
1035110352

1035210353
retry:;
10353-
unsigned flags = env->me_flags & ~MDBX_NOMETASYNC;
10354+
unsigned flags = env->me_flags & ~(MDBX_NOMETASYNC | MDBX_SHRINK_ALLOWED);
1035410355
if (unlikely((flags & (MDBX_RDONLY | MDBX_FATAL_ERROR | MDBX_ENV_ACTIVE)) !=
1035510356
MDBX_ENV_ACTIVE)) {
1035610357
rc = MDBX_EACCESS;
@@ -10434,17 +10435,19 @@ retry:;
1043410435
mdbx_assert(env, head_txnid == meta_txnid(env, head, false));
1043510436
mdbx_assert(env, head_txnid == mdbx_recent_committed_txnid(env));
1043610437
mdbx_find_oldest(env->me_txn0);
10438+
flags |= MDBX_SHRINK_ALLOWED;
1043710439
}
1043810440

1043910441
mdbx_assert(env, inside_txn || locked);
10442+
mdbx_assert(env, !inside_txn || (flags & MDBX_SHRINK_ALLOWED) == 0);
1044010443

1044110444
if (!META_IS_STEADY(head) ||
1044210445
((flags & MDBX_SAFE_NOSYNC) == 0 && unsynced_pages)) {
1044310446
mdbx_debug("meta-head %" PRIaPGNO ", %s, sync_pending %" PRIaPGNO,
1044410447
data_page(head)->mp_pgno, mdbx_durable_str(head),
1044510448
unsynced_pages);
1044610449
MDBX_meta meta = *head;
10447-
rc = mdbx_sync_locked(env, flags | MDBX_SHRINK_ALLOWED, &meta);
10450+
rc = mdbx_sync_locked(env, flags, &meta);
1044810451
if (unlikely(rc != MDBX_SUCCESS))
1044910452
goto bailout;
1045010453
}
@@ -14092,6 +14095,10 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
1409214095
unaligned_peek_u64(4, pending->mm_txnid_a))) {
1409314096
const txnid_t txnid =
1409414097
safe64_txnid_next(unaligned_peek_u64(4, pending->mm_txnid_a));
14098+
mdbx_notice("force-forward pending-txn %" PRIaTXN " -> %" PRIaTXN,
14099+
unaligned_peek_u64(4, pending->mm_txnid_a), txnid);
14100+
mdbx_ensure(env, env->me_txn0->mt_owner != mdbx_thread_self() &&
14101+
!env->me_txn);
1409514102
if (unlikely(txnid > MAX_TXNID)) {
1409614103
rc = MDBX_TXN_FULL;
1409714104
mdbx_error("txnid overflow, raise %d", rc);
@@ -15681,16 +15688,12 @@ __cold static int __must_check_result mdbx_override_meta(
1568115688
MDBX_SYNC_DATA | MDBX_SYNC_IODQ);
1568215689
if (unlikely(rc != MDBX_SUCCESS))
1568315690
return rc;
15684-
MDBX_meta *live = METAPAGE(env, target);
15685-
mdbx_meta_update_begin(env, live, unaligned_peek_u64(4, model->mm_txnid_a));
15691+
/* mdbx_override_meta() called only while current process have exclusive
15692+
* lock of a DB file. So meta-page could be updated directly without
15693+
* clearing consistency flag by mdbx_meta_update_begin() */
15694+
memcpy(pgno2page(env, target), page, env->me_psize);
1568615695
mdbx_flush_incoherent_cpu_writeback();
15687-
mdbx_meta_update_begin(env, model,
15688-
unaligned_peek_u64(4, model->mm_txnid_a));
15689-
unaligned_poke_u64(4, model->mm_datasync_sign, MDBX_DATASIGN_WEAK);
15690-
memcpy((void *)data_page(live), page, env->me_psize);
15691-
mdbx_meta_update_end(env, live, unaligned_peek_u64(4, model->mm_txnid_b));
15692-
mdbx_flush_incoherent_cpu_writeback();
15693-
rc = mdbx_msync(&env->me_dxb_mmap, 0, pgno_align2os_bytes(env, target),
15696+
rc = mdbx_msync(&env->me_dxb_mmap, 0, pgno_align2os_bytes(env, target + 1),
1569415697
MDBX_SYNC_DATA | MDBX_SYNC_IODQ);
1569515698
} else {
1569615699
const mdbx_filehandle_t fd = (env->me_dsync_fd != INVALID_HANDLE_VALUE)
@@ -16941,8 +16944,9 @@ __hot static int mdbx_page_search(MDBX_cursor *mc, const MDBX_val *key,
1694116944
* [out] data Updated to point to the node's data.
1694216945
*
1694316946
* Returns 0 on success, non-zero on failure. */
16944-
static __always_inline int mdbx_node_read(MDBX_cursor *mc, MDBX_node *node,
16945-
MDBX_val *data, const txnid_t front) {
16947+
static __always_inline int mdbx_node_read(MDBX_cursor *mc,
16948+
const MDBX_node *node, MDBX_val *data,
16949+
const txnid_t front) {
1694616950
data->iov_len = node_ds(node);
1694716951
data->iov_base = node_data(node);
1694816952
if (unlikely(F_ISSET(node_flags(node), F_BIGDATA))) {
@@ -17848,7 +17852,7 @@ int mdbx_cursor_get(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
1784817852
break;
1784917853
case MDBX_FIRST_DUP:
1785017854
mfunc = mdbx_cursor_first;
17851-
mmove:
17855+
move:
1785217856
if (unlikely(data == NULL || !(mc->mc_flags & C_INITIALIZED)))
1785317857
return MDBX_EINVAL;
1785417858
if (unlikely(mc->mc_xcursor == NULL))
@@ -17876,7 +17880,8 @@ int mdbx_cursor_get(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
1787617880
break;
1787717881
case MDBX_LAST_DUP:
1787817882
mfunc = mdbx_cursor_last;
17879-
goto mmove;
17883+
goto move;
17884+
case MDBX_SET_UPPERBOUND: /* mostly same as MDBX_SET_LOWERBOUND */
1788017885
case MDBX_SET_LOWERBOUND: {
1788117886
if (unlikely(key == NULL || data == NULL))
1788217887
return MDBX_EINVAL;
@@ -17909,6 +17914,15 @@ int mdbx_cursor_get(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
1790917914
}
1791017915
if (rc == MDBX_SUCCESS && !csr.exact)
1791117916
rc = MDBX_RESULT_TRUE;
17917+
if (unlikely(op == MDBX_SET_UPPERBOUND)) {
17918+
/* minor fixups for MDBX_SET_UPPERBOUND */
17919+
if (rc == MDBX_RESULT_TRUE)
17920+
/* already at great-than by MDBX_SET_LOWERBOUND */
17921+
rc = MDBX_SUCCESS;
17922+
else if (rc == MDBX_SUCCESS)
17923+
/* exactly match, going next */
17924+
rc = mdbx_cursor_next(mc, key, data, MDBX_NEXT);
17925+
}
1791217926
break;
1791317927
}
1791417928
default:
@@ -17920,6 +17934,122 @@ int mdbx_cursor_get(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
1792017934
return rc;
1792117935
}
1792217936

17937+
static int cursor_first_batch(MDBX_cursor *mc) {
17938+
if (!(mc->mc_flags & C_INITIALIZED) || mc->mc_top) {
17939+
int err = mdbx_page_search(mc, NULL, MDBX_PS_FIRST);
17940+
if (unlikely(err != MDBX_SUCCESS))
17941+
return err;
17942+
}
17943+
mdbx_cassert(mc, IS_LEAF(mc->mc_pg[mc->mc_top]));
17944+
17945+
mc->mc_flags |= C_INITIALIZED;
17946+
mc->mc_flags &= ~C_EOF;
17947+
mc->mc_ki[mc->mc_top] = 0;
17948+
return MDBX_SUCCESS;
17949+
}
17950+
17951+
static int cursor_next_batch(MDBX_cursor *mc) {
17952+
if (unlikely(!(mc->mc_flags & C_INITIALIZED)))
17953+
return cursor_first_batch(mc);
17954+
17955+
MDBX_page *mp = mc->mc_pg[mc->mc_top];
17956+
if (unlikely(mc->mc_flags & C_EOF)) {
17957+
if ((unsigned)mc->mc_ki[mc->mc_top] + 1 >= page_numkeys(mp))
17958+
return MDBX_NOTFOUND;
17959+
mc->mc_flags ^= C_EOF;
17960+
}
17961+
17962+
int ki = mc->mc_ki[mc->mc_top];
17963+
mc->mc_ki[mc->mc_top] = (indx_t)++ki;
17964+
const int numkeys = page_numkeys(mp);
17965+
if (likely(ki >= numkeys)) {
17966+
mdbx_debug("%s", "=====> move to next sibling page");
17967+
mc->mc_ki[mc->mc_top] = (indx_t)(numkeys - 1);
17968+
int err = mdbx_cursor_sibling(mc, SIBLING_RIGHT);
17969+
if (unlikely(err != MDBX_SUCCESS)) {
17970+
mc->mc_flags |= C_EOF;
17971+
return err;
17972+
}
17973+
mp = mc->mc_pg[mc->mc_top];
17974+
mdbx_debug("next page is %" PRIaPGNO ", key index %u", mp->mp_pgno,
17975+
mc->mc_ki[mc->mc_top]);
17976+
}
17977+
return MDBX_SUCCESS;
17978+
}
17979+
17980+
int mdbx_cursor_get_batch(MDBX_cursor *mc, size_t *count, MDBX_val *pairs,
17981+
size_t limit, MDBX_cursor_op op) {
17982+
if (unlikely(mc == NULL || count == NULL || limit < 4))
17983+
return MDBX_EINVAL;
17984+
17985+
if (unlikely(mc->mc_signature != MDBX_MC_LIVE))
17986+
return (mc->mc_signature == MDBX_MC_READY4CLOSE) ? MDBX_EINVAL
17987+
: MDBX_EBADSIGN;
17988+
17989+
int rc = check_txn(mc->mc_txn, MDBX_TXN_BLOCKED);
17990+
if (unlikely(rc != MDBX_SUCCESS))
17991+
return rc;
17992+
17993+
if (unlikely(mc->mc_db->md_flags & MDBX_DUPSORT))
17994+
return MDBX_INCOMPATIBLE /* must be a non-dupsort subDB */;
17995+
17996+
switch (op) {
17997+
case MDBX_FIRST:
17998+
rc = cursor_first_batch(mc);
17999+
break;
18000+
case MDBX_NEXT:
18001+
rc = cursor_next_batch(mc);
18002+
break;
18003+
case MDBX_GET_CURRENT:
18004+
rc = likely(mc->mc_flags & C_INITIALIZED) ? MDBX_SUCCESS : MDBX_ENODATA;
18005+
break;
18006+
default:
18007+
mdbx_debug("unhandled/unimplemented cursor operation %u", op);
18008+
rc = EINVAL;
18009+
break;
18010+
}
18011+
18012+
if (unlikely(rc != MDBX_SUCCESS)) {
18013+
*count = 0;
18014+
return rc;
18015+
}
18016+
18017+
const MDBX_page *const page = mc->mc_pg[mc->mc_top];
18018+
const unsigned nkeys = page_numkeys(page);
18019+
unsigned i = mc->mc_ki[mc->mc_top], n = 0;
18020+
if (unlikely(i >= nkeys)) {
18021+
mdbx_cassert(mc, op == MDBX_GET_CURRENT);
18022+
mdbx_cassert(mc, mdbx_cursor_on_last(mc) == MDBX_RESULT_TRUE);
18023+
*count = 0;
18024+
if (mc->mc_flags & C_EOF) {
18025+
mdbx_cassert(mc, mdbx_cursor_on_last(mc) == MDBX_RESULT_TRUE);
18026+
return MDBX_ENODATA;
18027+
}
18028+
if (mdbx_cursor_on_last(mc) != MDBX_RESULT_TRUE)
18029+
return MDBX_EINVAL /* again MDBX_GET_CURRENT after MDBX_GET_CURRENT */;
18030+
mc->mc_flags |= C_EOF;
18031+
return MDBX_NOTFOUND;
18032+
}
18033+
18034+
const txnid_t pp_txnid = pp_txnid4chk(page, mc->mc_txn);
18035+
do {
18036+
if (unlikely(n + 2 > limit)) {
18037+
rc = MDBX_RESULT_TRUE;
18038+
break;
18039+
}
18040+
const MDBX_node *leaf = page_node(page, i);
18041+
get_key(leaf, &pairs[n]);
18042+
rc = mdbx_node_read(mc, leaf, &pairs[n + 1], pp_txnid);
18043+
if (unlikely(rc != MDBX_SUCCESS))
18044+
break;
18045+
n += 2;
18046+
} while (++i < nkeys);
18047+
18048+
mc->mc_ki[mc->mc_top] = (indx_t)i;
18049+
*count = n;
18050+
return rc;
18051+
}
18052+
1792318053
static int mdbx_touch_dbi(MDBX_cursor *mc) {
1792418054
mdbx_cassert(mc, (*mc->mc_dbistate & DBI_DIRTY) == 0);
1792518055
*mc->mc_dbistate |= DBI_DIRTY;
@@ -28535,9 +28665,9 @@ __dll_export
2853528665
0,
2853628666
11,
2853728667
2,
28538-
15,
28539-
{"2021-12-09T15:54:16+03:00", "b9a59a0f8051a9596747d2cdc7b4dd9f07ffea68", "ca19796514122e7980cb42c9cf9aeccb0e544705",
28540-
"v0.11.2-15-gca197965"},
28668+
22,
28669+
{"2021-12-13T13:03:49+03:00", "85a340e46868508e5b9d6b93c83fec220f8a7930", "c70d2d62d1d5fe5659790703390d3fd2d4c5ff60",
28670+
"v0.11.2-22-gc70d2d62"},
2854128671
sourcery};
2854228672

2854328673
__dll_export

externals/libmdbx/mdbx.c++

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* <http://www.OpenLDAP.org/license.html>. */
1313

1414
#define xMDBX_ALLOY 1
15-
#define MDBX_BUILD_SOURCERY c5b9a3e9ba7c98987e7554f0c84c1e12e9f82d0d470ad881d54923ecf3599c17_v0_11_2_15_gca197965
15+
#define MDBX_BUILD_SOURCERY eceee647cf2c0dcedb1c09cb1f7c82a14d9efc74380e3954b5a3f158d5b8c29b_v0_11_2_22_gc70d2d62
1616
#ifdef MDBX_CONFIG_H
1717
#include MDBX_CONFIG_H
1818
#endif

0 commit comments

Comments
 (0)