From d8db63a67d151b29d20938cf2f81e1dc0492b653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Sat, 2 Mar 2024 01:11:24 +0300 Subject: [PATCH] =?UTF-8?q?mdbx-test:=20=D1=87=D1=83=D1=82=D1=8C=20=D0=B1?= =?UTF-8?q?=D0=BE=D0=BB=D0=B5=D0=B5=20=D1=80=D0=B0=D0=B7=D1=83=D0=BC=D0=BD?= =?UTF-8?q?=D0=BE=D0=B5/=D1=83=D0=B4=D0=BE=D0=B1=D0=BD=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=BA=D0=BE=D0=BB=D0=BB=D0=B8=D0=B7=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B5-=D1=83=D0=BD=D0=B8=D0=BA=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D0=BF=D0=B0=D1=80=20=D0=BA=D0=BB=D1=8E=D1=87-?= =?UTF-8?q?=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test.c++ | 55 +++++++++++++++++++++++++++++++-------------------- test/test.h++ | 5 +++-- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/test/test.c++ b/test/test.c++ index bb7bd818..05f1be60 100644 --- a/test/test.c++ +++ b/test/test.c++ @@ -599,9 +599,9 @@ void testcase::db_table_drop(MDBX_dbi handle) { void testcase::db_table_clear(MDBX_dbi handle, MDBX_txn *txn) { log_trace(">> testcase::db_table_clear, handle %u", handle); - int rc = mdbx_drop(txn ? txn : txn_guard.get(), handle, false); - if (unlikely(rc != MDBX_SUCCESS)) - failure_perror("mdbx_drop(delete=false)", rc); + int err = mdbx_drop(txn ? txn : txn_guard.get(), handle, false); + if (unlikely(err != MDBX_SUCCESS)) + failure_perror("mdbx_drop(delete=false)", err); speculum.clear(); log_trace("<< testcase::db_table_clear"); } @@ -609,21 +609,25 @@ void testcase::db_table_clear(MDBX_dbi handle, MDBX_txn *txn) { void testcase::db_table_close(MDBX_dbi handle) { log_trace(">> testcase::db_table_close, handle %u", handle); assert(!txn_guard); - int rc = mdbx_dbi_close(db_guard.get(), handle); - if (unlikely(rc != MDBX_SUCCESS)) - failure_perror("mdbx_dbi_close()", rc); + int err = mdbx_dbi_close(db_guard.get(), handle); + if (unlikely(err != MDBX_SUCCESS)) + failure_perror("mdbx_dbi_close()", err); log_trace("<< testcase::db_table_close"); } -void testcase::checkdata(const char *step, MDBX_dbi handle, MDBX_val key2check, +bool testcase::checkdata(const char *step, MDBX_dbi handle, MDBX_val key2check, MDBX_val expected_valued) { MDBX_val actual_value = expected_valued; - int rc = mdbx_get_equal_or_great(txn_guard.get(), handle, &key2check, - &actual_value); - if (unlikely(rc != MDBX_SUCCESS)) - failure_perror(step, rc); + int err = mdbx_get_equal_or_great(txn_guard.get(), handle, &key2check, + &actual_value); + if (unlikely(err != MDBX_SUCCESS)) { + if (!config.params.speculum || err != MDBX_RESULT_TRUE) + failure_perror(step, (err == MDBX_RESULT_TRUE) ? MDBX_NOTFOUND : err); + return false; + } if (!is_samedata(&actual_value, &expected_valued)) failure("%s data mismatch", step); + return true; } //----------------------------------------------------------------------------- @@ -988,7 +992,9 @@ int testcase::insert(const keygen::buffer &akey, const keygen::buffer &adata, } auto it_lowerbound = insertion_result.first; - if (++it_lowerbound != speculum.end()) { + if (insertion_result.second) + ++it_lowerbound; + if (it_lowerbound != speculum.end()) { const auto cursor_lowerbound = speculum_cursors[lowerbound].get(); speculum_check_cursor("after-insert", "lowerbound", it_lowerbound, cursor_lowerbound, MDBX_GET_CURRENT); @@ -1015,30 +1021,37 @@ int testcase::insert(const keygen::buffer &akey, const keygen::buffer &adata, int testcase::replace(const keygen::buffer &akey, const keygen::buffer &new_data, - const keygen::buffer &old_data, MDBX_put_flags_t flags) { + const keygen::buffer &old_data, MDBX_put_flags_t flags, + bool hush_keygen_mistakes) { + int expected_err = MDBX_SUCCESS; if (config.params.speculum) { const auto S_key = iov2dataview(akey); const auto S_old = iov2dataview(old_data); const auto S_new = iov2dataview(new_data); const auto removed = speculum.erase(SET::key_type(S_key, S_old)); - if (unlikely(removed != 1)) { + if (unlikely(!removed)) { char dump_key[128], dump_value[128]; log_error( - "speculum-%s: %s old value {%s, %s}", "replace", - (removed > 1) ? "multi" : "no", + "speculum-%s: no old pair {%s, %s} (keygen mistake)", "replace", mdbx_dump_val(&akey->value, dump_key, sizeof(dump_key)), mdbx_dump_val(&old_data->value, dump_value, sizeof(dump_value))); - } - if (unlikely(!speculum.emplace(S_key, S_new).second)) { + expected_err = MDBX_NOTFOUND; + } else if (unlikely(!speculum.emplace(S_key, S_new).second)) { char dump_key[128], dump_value[128]; log_error( - "speculum-replace: new pair not inserted {%s, %s}", + "speculum-%s: %s {%s, %s}", "replace", "new pair not inserted", mdbx_dump_val(&akey->value, dump_key, sizeof(dump_key)), mdbx_dump_val(&new_data->value, dump_value, sizeof(dump_value))); + expected_err = MDBX_KEYEXIST; } } - return mdbx_replace(txn_guard.get(), dbi, &akey->value, &new_data->value, - &old_data->value, flags); + int err = mdbx_replace(txn_guard.get(), dbi, &akey->value, &new_data->value, + &old_data->value, flags); + if (err && err == expected_err && hush_keygen_mistakes) { + log_notice("speculum-%s: %s %d", "replace", "hust keygen mistake", err); + err = MDBX_SUCCESS; + } + return err; } int testcase::remove(const keygen::buffer &akey, const keygen::buffer &adata) { diff --git a/test/test.h++ b/test/test.h++ index d99ba4f8..ef9ea0c1 100644 --- a/test/test.h++ +++ b/test/test.h++ @@ -232,7 +232,8 @@ protected: int insert(const keygen::buffer &akey, const keygen::buffer &adata, MDBX_put_flags_t flags); int replace(const keygen::buffer &akey, const keygen::buffer &new_value, - const keygen::buffer &old_value, MDBX_put_flags_t flags); + const keygen::buffer &old_value, MDBX_put_flags_t flags, + bool hush_keygen_mistakes = true); int remove(const keygen::buffer &akey, const keygen::buffer &adata); static int hsr_callback(const MDBX_env *env, const MDBX_txn *txn, @@ -262,7 +263,7 @@ protected: void txn_inject_writefault(MDBX_txn *txn); void fetch_canary(); void update_canary(uint64_t increment); - void checkdata(const char *step, MDBX_dbi handle, MDBX_val key2check, + bool checkdata(const char *step, MDBX_dbi handle, MDBX_val key2check, MDBX_val expected_valued); unsigned txn_underutilization_x256(MDBX_txn *txn) const;