mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-06 22:24:13 +08:00
mdbx-tests: refine after last pull-request.
Refine after 4e40af60e74143aedaa8d295f0f33a3c892a1c9b (Merge pull request #20 from rouzier/feature/txn_try).
This commit is contained in:
parent
17b8e48bf4
commit
32c5c3b761
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
|
* Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
|
||||||
* and other libmdbx authors: please see AUTHORS file.
|
* and other libmdbx authors: please see AUTHORS file.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@ -25,7 +25,7 @@ bool testcase_deadread::setup() {
|
|||||||
|
|
||||||
bool testcase_deadread::run() {
|
bool testcase_deadread::run() {
|
||||||
db_open();
|
db_open();
|
||||||
txn_begin(MDBX_RDONLY);
|
txn_begin(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ bool testcase_deadwrite::setup() {
|
|||||||
|
|
||||||
bool testcase_deadwrite::run() {
|
bool testcase_deadwrite::run() {
|
||||||
db_open();
|
db_open();
|
||||||
txn_begin(0);
|
txn_begin(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
test/hill.cc
24
test/hill.cc
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
|
* Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
|
||||||
* and other libmdbx authors: please see AUTHORS file.
|
* and other libmdbx authors: please see AUTHORS file.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@ -28,7 +28,7 @@ bool testcase_hill::setup() {
|
|||||||
bool testcase_hill::run() {
|
bool testcase_hill::run() {
|
||||||
db_open();
|
db_open();
|
||||||
|
|
||||||
txn_begin(0);
|
txn_begin(false);
|
||||||
MDBX_dbi dbi = db_table_open(true);
|
MDBX_dbi dbi = db_table_open(true);
|
||||||
txn_end(false);
|
txn_end(false);
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ bool testcase_hill::run() {
|
|||||||
uint64_t serial_count = 0;
|
uint64_t serial_count = 0;
|
||||||
unsigned txn_nops = 0;
|
unsigned txn_nops = 0;
|
||||||
if (!txn_guard)
|
if (!txn_guard)
|
||||||
txn_begin(0);
|
txn_begin(false);
|
||||||
|
|
||||||
while (should_continue()) {
|
while (should_continue()) {
|
||||||
const keygen::serial_t a_serial = serial_count;
|
const keygen::serial_t a_serial = serial_count;
|
||||||
@ -91,7 +91,7 @@ bool testcase_hill::run() {
|
|||||||
failure_perror("mdbx_put(insert-a.1)", rc);
|
failure_perror("mdbx_put(insert-a.1)", rc);
|
||||||
|
|
||||||
if (++txn_nops >= config.params.batch_write) {
|
if (++txn_nops >= config.params.batch_write) {
|
||||||
txn_restart(false, 0);
|
txn_restart(false, false);
|
||||||
txn_nops = 0;
|
txn_nops = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ bool testcase_hill::run() {
|
|||||||
failure_perror("mdbx_put(insert-b)", rc);
|
failure_perror("mdbx_put(insert-b)", rc);
|
||||||
|
|
||||||
if (++txn_nops >= config.params.batch_write) {
|
if (++txn_nops >= config.params.batch_write) {
|
||||||
txn_restart(false, 0);
|
txn_restart(false, false);
|
||||||
txn_nops = 0;
|
txn_nops = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ bool testcase_hill::run() {
|
|||||||
failure_perror("mdbx_put(update-a: 1->0)", rc);
|
failure_perror("mdbx_put(update-a: 1->0)", rc);
|
||||||
|
|
||||||
if (++txn_nops >= config.params.batch_write) {
|
if (++txn_nops >= config.params.batch_write) {
|
||||||
txn_restart(false, 0);
|
txn_restart(false, false);
|
||||||
txn_nops = 0;
|
txn_nops = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ bool testcase_hill::run() {
|
|||||||
failure_perror("mdbx_del(b)", rc);
|
failure_perror("mdbx_del(b)", rc);
|
||||||
|
|
||||||
if (++txn_nops >= config.params.batch_write) {
|
if (++txn_nops >= config.params.batch_write) {
|
||||||
txn_restart(false, 0);
|
txn_restart(false, false);
|
||||||
txn_nops = 0;
|
txn_nops = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ bool testcase_hill::run() {
|
|||||||
failure_perror("mdbx_put(update-a: 0->1)", rc);
|
failure_perror("mdbx_put(update-a: 0->1)", rc);
|
||||||
|
|
||||||
if (++txn_nops >= config.params.batch_write) {
|
if (++txn_nops >= config.params.batch_write) {
|
||||||
txn_restart(false, 0);
|
txn_restart(false, false);
|
||||||
txn_nops = 0;
|
txn_nops = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ bool testcase_hill::run() {
|
|||||||
failure_perror("mdbx_put(insert-b)", rc);
|
failure_perror("mdbx_put(insert-b)", rc);
|
||||||
|
|
||||||
if (++txn_nops >= config.params.batch_write) {
|
if (++txn_nops >= config.params.batch_write) {
|
||||||
txn_restart(false, 0);
|
txn_restart(false, false);
|
||||||
txn_nops = 0;
|
txn_nops = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ bool testcase_hill::run() {
|
|||||||
failure_perror("mdbx_del(a)", rc);
|
failure_perror("mdbx_del(a)", rc);
|
||||||
|
|
||||||
if (++txn_nops >= config.params.batch_write) {
|
if (++txn_nops >= config.params.batch_write) {
|
||||||
txn_restart(false, 0);
|
txn_restart(false, false);
|
||||||
txn_nops = 0;
|
txn_nops = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ bool testcase_hill::run() {
|
|||||||
failure_perror("mdbx_del(b)", rc);
|
failure_perror("mdbx_del(b)", rc);
|
||||||
|
|
||||||
if (++txn_nops >= config.params.batch_write) {
|
if (++txn_nops >= config.params.batch_write) {
|
||||||
txn_restart(false, 0);
|
txn_restart(false, false);
|
||||||
txn_nops = 0;
|
txn_nops = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ bool testcase_hill::run() {
|
|||||||
|
|
||||||
if (dbi) {
|
if (dbi) {
|
||||||
if (config.params.drop_table && !mode_readonly()) {
|
if (config.params.drop_table && !mode_readonly()) {
|
||||||
txn_begin(0);
|
txn_begin(false);
|
||||||
db_table_drop(dbi);
|
db_table_drop(dbi);
|
||||||
txn_end(false);
|
txn_end(false);
|
||||||
} else
|
} else
|
||||||
|
@ -30,7 +30,7 @@ bool testcase_jitter::run() {
|
|||||||
|
|
||||||
if (flipcoin()) {
|
if (flipcoin()) {
|
||||||
jitter_delay();
|
jitter_delay();
|
||||||
txn_begin(MDBX_RDONLY);
|
txn_begin(true);
|
||||||
fetch_canary();
|
fetch_canary();
|
||||||
jitter_delay();
|
jitter_delay();
|
||||||
txn_end(flipcoin());
|
txn_end(flipcoin());
|
||||||
@ -51,7 +51,7 @@ bool testcase_jitter::run() {
|
|||||||
|
|
||||||
if (flipcoin()) {
|
if (flipcoin()) {
|
||||||
jitter_delay();
|
jitter_delay();
|
||||||
txn_begin(MDBX_RDONLY);
|
txn_begin(true);
|
||||||
jitter_delay();
|
jitter_delay();
|
||||||
txn_end(flipcoin());
|
txn_end(flipcoin());
|
||||||
}
|
}
|
||||||
|
20
test/test.cc
20
test/test.cc
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
|
* Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
|
||||||
* and other libmdbx authors: please see AUTHORS file.
|
* and other libmdbx authors: please see AUTHORS file.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@ -177,19 +177,21 @@ void testcase::db_close() {
|
|||||||
log_trace("<< db_close");
|
log_trace("<< db_close");
|
||||||
}
|
}
|
||||||
|
|
||||||
void testcase::txn_begin(unsigned flags) {
|
void testcase::txn_begin(bool readonly, unsigned flags) {
|
||||||
log_trace(">> txn_begin(%s)",
|
assert((flags & MDBX_RDONLY) == 0);
|
||||||
flags & MDBX_RDONLY ? "read-only" : "read-write");
|
log_trace(">> txn_begin(%s, 0x%04X)", readonly ? "read-only" : "read-write",
|
||||||
|
flags);
|
||||||
assert(!txn_guard);
|
assert(!txn_guard);
|
||||||
|
|
||||||
MDBX_txn *txn = nullptr;
|
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))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
failure_perror("mdbx_txn_begin()", rc);
|
failure_perror("mdbx_txn_begin()", rc);
|
||||||
txn_guard.reset(txn);
|
txn_guard.reset(txn);
|
||||||
|
|
||||||
log_trace("<< txn_begin(%s)",
|
log_trace("<< txn_begin(%s, 0x%04X)", readonly ? "read-only" : "read-write",
|
||||||
flags & MDBX_RDONLY ? "read-only" : "read-write");
|
flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void testcase::txn_end(bool abort) {
|
void testcase::txn_end(bool abort) {
|
||||||
@ -210,10 +212,10 @@ void testcase::txn_end(bool abort) {
|
|||||||
log_trace("<< txn_end(%s)", abort ? "abort" : "commit");
|
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)
|
if (txn_guard)
|
||||||
txn_end(abort);
|
txn_end(abort);
|
||||||
txn_begin(flags);
|
txn_begin(readonly, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testcase::wait4start() {
|
bool testcase::wait4start() {
|
||||||
|
10
test/test.h
10
test/test.h
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
|
* Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
|
||||||
* and other libmdbx authors: please see AUTHORS file.
|
* and other libmdbx authors: please see AUTHORS file.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@ -104,9 +104,9 @@ protected:
|
|||||||
void db_prepare();
|
void db_prepare();
|
||||||
void db_open();
|
void db_open();
|
||||||
void db_close();
|
void db_close();
|
||||||
void txn_begin(unsigned flags);
|
void txn_begin(bool readonly, unsigned flags = 0);
|
||||||
void txn_end(bool abort);
|
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 fetch_canary();
|
||||||
void update_canary(uint64_t increment);
|
void update_canary(uint64_t increment);
|
||||||
void kick_progress(bool active) const;
|
void kick_progress(bool active) const;
|
||||||
@ -130,8 +130,8 @@ protected:
|
|||||||
generate_pair(serial, key, data, data_age);
|
generate_pair(serial, key, data, data_age);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned mode_readonly() const {
|
bool mode_readonly() const {
|
||||||
return (config.params.mode_flags & MDBX_RDONLY) ? MDBX_RDONLY : 0;
|
return (config.params.mode_flags & MDBX_RDONLY) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user