mdbx-tests: refine after last pull-request.

Refine after 4e40af60e74143aedaa8d295f0f33a3c892a1c9b (Merge pull request #20 from rouzier/feature/txn_try).
This commit is contained in:
Leo Yuriev 2017-10-26 21:14:29 +03:00
parent 17b8e48bf4
commit 32c5c3b761
5 changed files with 33 additions and 31 deletions

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@ -25,7 +25,7 @@ bool testcase_deadread::setup() {
bool testcase_deadread::run() {
db_open();
txn_begin(MDBX_RDONLY);
txn_begin(true);
return true;
}
@ -50,7 +50,7 @@ bool testcase_deadwrite::setup() {
bool testcase_deadwrite::run() {
db_open();
txn_begin(0);
txn_begin(false);
return true;
}

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@ -28,7 +28,7 @@ bool testcase_hill::setup() {
bool testcase_hill::run() {
db_open();
txn_begin(0);
txn_begin(false);
MDBX_dbi dbi = db_table_open(true);
txn_end(false);
@ -70,7 +70,7 @@ bool testcase_hill::run() {
uint64_t serial_count = 0;
unsigned txn_nops = 0;
if (!txn_guard)
txn_begin(0);
txn_begin(false);
while (should_continue()) {
const keygen::serial_t a_serial = serial_count;
@ -91,7 +91,7 @@ bool testcase_hill::run() {
failure_perror("mdbx_put(insert-a.1)", rc);
if (++txn_nops >= config.params.batch_write) {
txn_restart(false, 0);
txn_restart(false, false);
txn_nops = 0;
}
@ -104,7 +104,7 @@ bool testcase_hill::run() {
failure_perror("mdbx_put(insert-b)", rc);
if (++txn_nops >= config.params.batch_write) {
txn_restart(false, 0);
txn_restart(false, false);
txn_nops = 0;
}
@ -118,7 +118,7 @@ bool testcase_hill::run() {
failure_perror("mdbx_put(update-a: 1->0)", rc);
if (++txn_nops >= config.params.batch_write) {
txn_restart(false, 0);
txn_restart(false, false);
txn_nops = 0;
}
@ -129,7 +129,7 @@ bool testcase_hill::run() {
failure_perror("mdbx_del(b)", rc);
if (++txn_nops >= config.params.batch_write) {
txn_restart(false, 0);
txn_restart(false, false);
txn_nops = 0;
}
@ -164,7 +164,7 @@ bool testcase_hill::run() {
failure_perror("mdbx_put(update-a: 0->1)", rc);
if (++txn_nops >= config.params.batch_write) {
txn_restart(false, 0);
txn_restart(false, false);
txn_nops = 0;
}
@ -177,7 +177,7 @@ bool testcase_hill::run() {
failure_perror("mdbx_put(insert-b)", rc);
if (++txn_nops >= config.params.batch_write) {
txn_restart(false, 0);
txn_restart(false, false);
txn_nops = 0;
}
@ -189,7 +189,7 @@ bool testcase_hill::run() {
failure_perror("mdbx_del(a)", rc);
if (++txn_nops >= config.params.batch_write) {
txn_restart(false, 0);
txn_restart(false, false);
txn_nops = 0;
}
@ -200,7 +200,7 @@ bool testcase_hill::run() {
failure_perror("mdbx_del(b)", rc);
if (++txn_nops >= config.params.batch_write) {
txn_restart(false, 0);
txn_restart(false, false);
txn_nops = 0;
}
@ -212,7 +212,7 @@ bool testcase_hill::run() {
if (dbi) {
if (config.params.drop_table && !mode_readonly()) {
txn_begin(0);
txn_begin(false);
db_table_drop(dbi);
txn_end(false);
} else

View File

@ -30,7 +30,7 @@ bool testcase_jitter::run() {
if (flipcoin()) {
jitter_delay();
txn_begin(MDBX_RDONLY);
txn_begin(true);
fetch_canary();
jitter_delay();
txn_end(flipcoin());
@ -51,7 +51,7 @@ bool testcase_jitter::run() {
if (flipcoin()) {
jitter_delay();
txn_begin(MDBX_RDONLY);
txn_begin(true);
jitter_delay();
txn_end(flipcoin());
}

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@ -177,19 +177,21 @@ void testcase::db_close() {
log_trace("<< db_close");
}
void testcase::txn_begin(unsigned flags) {
log_trace(">> txn_begin(%s)",
flags & MDBX_RDONLY ? "read-only" : "read-write");
void testcase::txn_begin(bool readonly, unsigned flags) {
assert((flags & MDBX_RDONLY) == 0);
log_trace(">> txn_begin(%s, 0x%04X)", readonly ? "read-only" : "read-write",
flags);
assert(!txn_guard);
MDBX_txn *txn = nullptr;
int rc = mdbx_txn_begin(db_guard.get(), nullptr, flags, &txn);
int rc = mdbx_txn_begin(db_guard.get(), nullptr,
readonly ? flags | MDBX_RDONLY : flags, &txn);
if (unlikely(rc != MDBX_SUCCESS))
failure_perror("mdbx_txn_begin()", rc);
txn_guard.reset(txn);
log_trace("<< txn_begin(%s)",
flags & MDBX_RDONLY ? "read-only" : "read-write");
log_trace("<< txn_begin(%s, 0x%04X)", readonly ? "read-only" : "read-write",
flags);
}
void testcase::txn_end(bool abort) {
@ -210,10 +212,10 @@ void testcase::txn_end(bool abort) {
log_trace("<< txn_end(%s)", abort ? "abort" : "commit");
}
void testcase::txn_restart(bool abort, unsigned flags) {
void testcase::txn_restart(bool abort, bool readonly, unsigned flags) {
if (txn_guard)
txn_end(abort);
txn_begin(flags);
txn_begin(readonly, flags);
}
bool testcase::wait4start() {

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@ -104,9 +104,9 @@ protected:
void db_prepare();
void db_open();
void db_close();
void txn_begin(unsigned flags);
void txn_begin(bool readonly, unsigned flags = 0);
void txn_end(bool abort);
void txn_restart(bool abort, unsigned flags);
void txn_restart(bool abort, bool readonly, unsigned flags = 0);
void fetch_canary();
void update_canary(uint64_t increment);
void kick_progress(bool active) const;
@ -130,8 +130,8 @@ protected:
generate_pair(serial, key, data, data_age);
}
unsigned mode_readonly() const {
return (config.params.mode_flags & MDBX_RDONLY) ? MDBX_RDONLY : 0;
bool mode_readonly() const {
return (config.params.mode_flags & MDBX_RDONLY) ? true : false;
}
public: