mdbx-test: refine/fix batch-get testcase for large page size (i.e. when more pairs per page).

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2022-07-09 13:22:35 +03:00
parent e9a1042cc2
commit 61d0d63ac2

View File

@ -1189,28 +1189,29 @@ bool testcase::check_batch_get() {
char dump_key[128], dump_value[128]; char dump_key[128], dump_value[128];
char dump_key_batch[128], dump_value_batch[128]; char dump_key_batch[128], dump_value_batch[128];
MDBX_cursor *cursor; MDBX_cursor *check_cursor;
int err = mdbx_cursor_open(txn_guard.get(), dbi, &cursor); int check_err = mdbx_cursor_open(txn_guard.get(), dbi, &check_cursor);
if (err != MDBX_SUCCESS) if (check_err != MDBX_SUCCESS)
failure_perror("mdbx_cursor_open()", err); failure_perror("mdbx_cursor_open()", check_err);
MDBX_cursor *batch_cursor; MDBX_cursor *batch_cursor;
err = mdbx_cursor_open(txn_guard.get(), dbi, &batch_cursor); int batch_err = mdbx_cursor_open(txn_guard.get(), dbi, &batch_cursor);
if (err != MDBX_SUCCESS) if (batch_err != MDBX_SUCCESS)
failure_perror("mdbx_cursor_open()", err); failure_perror("mdbx_cursor_open()", batch_err);
bool rc = true;
MDBX_val pairs[42]; MDBX_val pairs[42];
size_t count = 0xDeadBeef; size_t count = 0xDeadBeef;
err = mdbx_cursor_get_batch(batch_cursor, &count, pairs, ARRAY_LENGTH(pairs), MDBX_cursor_op batch_op;
MDBX_FIRST); batch_err = mdbx_cursor_get_batch(batch_cursor, &count, pairs,
bool rc = true; ARRAY_LENGTH(pairs), batch_op = MDBX_FIRST);
size_t i, n = 0; 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) { for (i = 0; i < count; i += 2) {
mdbx::slice k, v; mdbx::slice k, v;
int err2 = mdbx_cursor_get(cursor, &k, &v, MDBX_NEXT); check_err = mdbx_cursor_get(check_cursor, &k, &v, MDBX_NEXT);
if (err2 != MDBX_SUCCESS) if (check_err != MDBX_SUCCESS)
failure_perror("mdbx_cursor_open()", err2); failure_perror("batch-verify: mdbx_cursor_get(MDBX_NEXT)", check_err);
if (k != pairs[i] || v != pairs[i + 1]) { if (k != pairs[i] || v != pairs[i + 1]) {
log_error( log_error(
"batch-get pair mismatch %zu/%zu: sequential{%s, %s} != " "batch-get pair mismatch %zu/%zu: sequential{%s, %s} != "
@ -1224,29 +1225,32 @@ bool testcase::check_batch_get() {
} }
} }
n += i / 2; n += i / 2;
err = mdbx_cursor_get_batch(batch_cursor, &count, pairs, batch_op = (batch_err == MDBX_RESULT_TRUE) ? MDBX_GET_CURRENT : MDBX_NEXT;
ARRAY_LENGTH(pairs), MDBX_NEXT); batch_err = mdbx_cursor_get_batch(batch_cursor, &count, pairs,
ARRAY_LENGTH(pairs), batch_op);
} }
if (err != MDBX_NOTFOUND) if (batch_err != MDBX_NOTFOUND) {
failure_perror("mdbx_cursor_get_batch()", err); log_error("mdbx_cursor_get_batch(), op %u, err %d", batch_op, 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);
rc = false; rc = false;
} }
err = mdbx_cursor_on_last(cursor); batch_err = mdbx_cursor_eof(batch_cursor);
if (err != MDBX_RESULT_TRUE) { if (batch_err != MDBX_RESULT_TRUE) {
log_error("batch-get %s cursor not-on-last %d", "checked", err); log_error("batch-get %s-cursor not-eof %d", "batch", batch_err);
rc = false; 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); mdbx_cursor_close(batch_cursor);
return rc; return rc;
} }