From 61d0d63ac2f2cbf5557b44845f73721f62bb8654 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, 9 Jul 2022 13:22:35 +0300 Subject: [PATCH] mdbx-test: refine/fix batch-get testcase for large page size (i.e. when more pairs per page). --- test/test.cc | 66 ++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/test/test.cc b/test/test.cc index fd8f987d..6f620223 100644 --- a/test/test.cc +++ b/test/test.cc @@ -1189,28 +1189,29 @@ bool testcase::check_batch_get() { char dump_key[128], dump_value[128]; char dump_key_batch[128], dump_value_batch[128]; - MDBX_cursor *cursor; - int err = mdbx_cursor_open(txn_guard.get(), dbi, &cursor); - if (err != MDBX_SUCCESS) - failure_perror("mdbx_cursor_open()", err); + MDBX_cursor *check_cursor; + int check_err = mdbx_cursor_open(txn_guard.get(), dbi, &check_cursor); + if (check_err != MDBX_SUCCESS) + failure_perror("mdbx_cursor_open()", check_err); MDBX_cursor *batch_cursor; - err = mdbx_cursor_open(txn_guard.get(), dbi, &batch_cursor); - if (err != MDBX_SUCCESS) - failure_perror("mdbx_cursor_open()", err); + int batch_err = mdbx_cursor_open(txn_guard.get(), dbi, &batch_cursor); + if (batch_err != MDBX_SUCCESS) + failure_perror("mdbx_cursor_open()", batch_err); + bool rc = true; MDBX_val pairs[42]; size_t count = 0xDeadBeef; - err = mdbx_cursor_get_batch(batch_cursor, &count, pairs, ARRAY_LENGTH(pairs), - MDBX_FIRST); - bool rc = true; + MDBX_cursor_op batch_op; + batch_err = mdbx_cursor_get_batch(batch_cursor, &count, pairs, + ARRAY_LENGTH(pairs), batch_op = MDBX_FIRST); size_t i, n = 0; - while (err == MDBX_SUCCESS) { + while (batch_err == MDBX_SUCCESS || batch_err == MDBX_RESULT_TRUE) { for (i = 0; i < count; i += 2) { mdbx::slice k, v; - int err2 = mdbx_cursor_get(cursor, &k, &v, MDBX_NEXT); - if (err2 != MDBX_SUCCESS) - failure_perror("mdbx_cursor_open()", err2); + check_err = mdbx_cursor_get(check_cursor, &k, &v, MDBX_NEXT); + if (check_err != MDBX_SUCCESS) + failure_perror("batch-verify: mdbx_cursor_get(MDBX_NEXT)", check_err); if (k != pairs[i] || v != pairs[i + 1]) { log_error( "batch-get pair mismatch %zu/%zu: sequential{%s, %s} != " @@ -1224,29 +1225,32 @@ bool testcase::check_batch_get() { } } n += i / 2; - err = mdbx_cursor_get_batch(batch_cursor, &count, pairs, - ARRAY_LENGTH(pairs), MDBX_NEXT); + batch_op = (batch_err == MDBX_RESULT_TRUE) ? MDBX_GET_CURRENT : MDBX_NEXT; + batch_err = mdbx_cursor_get_batch(batch_cursor, &count, pairs, + ARRAY_LENGTH(pairs), batch_op); } - if (err != MDBX_NOTFOUND) - failure_perror("mdbx_cursor_get_batch()", err); - - err = mdbx_cursor_eof(batch_cursor); - if (err != MDBX_RESULT_TRUE) { - log_error("batch-get %s cursor not-eof %d", "batch", err); - rc = false; - } - err = mdbx_cursor_on_last(batch_cursor); - if (err != MDBX_RESULT_TRUE) { - log_error("batch-get %s cursor not-on-last %d", "batch", err); + if (batch_err != MDBX_NOTFOUND) { + log_error("mdbx_cursor_get_batch(), op %u, err %d", batch_op, batch_err); rc = false; } - err = mdbx_cursor_on_last(cursor); - if (err != MDBX_RESULT_TRUE) { - log_error("batch-get %s cursor not-on-last %d", "checked", err); + batch_err = mdbx_cursor_eof(batch_cursor); + if (batch_err != MDBX_RESULT_TRUE) { + log_error("batch-get %s-cursor not-eof %d", "batch", batch_err); rc = false; } - mdbx_cursor_close(cursor); + batch_err = mdbx_cursor_on_last(batch_cursor); + if (batch_err != MDBX_RESULT_TRUE) { + log_error("batch-get %s-cursor not-on-last %d", "batch", batch_err); + rc = false; + } + + check_err = mdbx_cursor_on_last(check_cursor); + if (check_err != MDBX_RESULT_TRUE) { + log_error("batch-get %s-cursor not-on-last %d", "checked", check_err); + rc = false; + } + mdbx_cursor_close(check_cursor); mdbx_cursor_close(batch_cursor); return rc; }