mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-20 11:58:21 +08:00
mdbx-test: refine 'ttl' testcase.
Change-Id: Ic4d759cfa29496bd46fa50fef1e974847b52bb41
This commit is contained in:
parent
243b01dd63
commit
e6ad443178
42
test/ttl.cc
42
test/ttl.cc
@ -14,12 +14,12 @@
|
|||||||
|
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <queue>
|
#include <deque>
|
||||||
|
|
||||||
static unsigned edge2window(uint64_t edge, unsigned window_max) {
|
static unsigned edge2window(uint64_t edge, unsigned window_max) {
|
||||||
const double rnd = u64_to_double1(bleach64(edge));
|
const double rnd = u64_to_double1(bleach64(edge));
|
||||||
const unsigned window = window_max - std::lrint(std::pow(window_max, rnd));
|
const unsigned window = window_max - std::lrint(std::pow(window_max, rnd));
|
||||||
return window - (window > 0);
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned edge2count(uint64_t edge, unsigned count_max) {
|
static unsigned edge2count(uint64_t edge, unsigned count_max) {
|
||||||
@ -33,9 +33,7 @@ bool testcase_ttl::run() {
|
|||||||
|
|
||||||
txn_begin(false);
|
txn_begin(false);
|
||||||
MDBX_dbi dbi = db_table_open(true);
|
MDBX_dbi dbi = db_table_open(true);
|
||||||
int rc = mdbx_drop(txn_guard.get(), dbi, false);
|
db_table_clear(dbi);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
|
||||||
failure_perror("mdbx_drop(delete=false)", rc);
|
|
||||||
txn_end(false);
|
txn_end(false);
|
||||||
|
|
||||||
/* LY: тест "эмуляцией time-to-live":
|
/* LY: тест "эмуляцией time-to-live":
|
||||||
@ -63,7 +61,8 @@ bool testcase_ttl::run() {
|
|||||||
log_info("ttl: using `batch_read` value %u for window_max", window_max);
|
log_info("ttl: using `batch_read` value %u for window_max", window_max);
|
||||||
log_info("ttl: using `batch_write` value %u for count_max", count_max);
|
log_info("ttl: using `batch_write` value %u for count_max", count_max);
|
||||||
|
|
||||||
uint64_t seed = prng64_map2_white(config.params.keygen.seed) + config.actor_id;
|
uint64_t seed =
|
||||||
|
prng64_map2_white(config.params.keygen.seed) + config.actor_id;
|
||||||
keyvalue_maker.setup(config.params, config.actor_id, 0 /* thread_number */);
|
keyvalue_maker.setup(config.params, config.actor_id, 0 /* thread_number */);
|
||||||
key = keygen::alloc(config.params.keylen_max);
|
key = keygen::alloc(config.params.keylen_max);
|
||||||
data = keygen::alloc(config.params.datalen_max);
|
data = keygen::alloc(config.params.datalen_max);
|
||||||
@ -71,21 +70,26 @@ bool testcase_ttl::run() {
|
|||||||
? MDBX_NODUPDATA
|
? MDBX_NODUPDATA
|
||||||
: MDBX_NODUPDATA | MDBX_NOOVERWRITE;
|
: MDBX_NODUPDATA | MDBX_NOOVERWRITE;
|
||||||
|
|
||||||
std::queue<std::pair<uint64_t, unsigned>> fifo;
|
std::deque<std::pair<uint64_t, unsigned>> fifo;
|
||||||
uint64_t serial = 0;
|
uint64_t serial = 0;
|
||||||
while (should_continue()) {
|
while (should_continue()) {
|
||||||
if (!txn_guard)
|
if (!txn_guard)
|
||||||
txn_begin(false);
|
txn_begin(false);
|
||||||
const uint64_t salt = prng64_white(seed)/* mdbx_txn_id(txn_guard.get()) */;
|
const uint64_t salt = prng64_white(seed) /* mdbx_txn_id(txn_guard.get()) */;
|
||||||
|
|
||||||
const unsigned window = edge2window(salt, window_max);
|
const unsigned window_width = edge2window(salt, window_max);
|
||||||
log_trace("ttl: window %u at %" PRIu64, window, salt);
|
const unsigned head_count = edge2count(salt, count_max);
|
||||||
while (fifo.size() > window) {
|
log_info("ttl: step #%zu (serial %" PRIu64
|
||||||
uint64_t tail_serial = fifo.front().first;
|
", window %u, count %u) salt %" PRIu64,
|
||||||
const unsigned tail_count = fifo.front().second;
|
nops_completed, serial, window_width, head_count, salt);
|
||||||
|
|
||||||
|
if (window_width) {
|
||||||
|
while (fifo.size() > window_width) {
|
||||||
|
uint64_t tail_serial = fifo.back().first;
|
||||||
|
const unsigned tail_count = fifo.back().second;
|
||||||
log_trace("ttl: pop-tail (serial %" PRIu64 ", count %u)", tail_serial,
|
log_trace("ttl: pop-tail (serial %" PRIu64 ", count %u)", tail_serial,
|
||||||
tail_count);
|
tail_count);
|
||||||
fifo.pop();
|
fifo.pop_back();
|
||||||
for (unsigned n = 0; n < tail_count; ++n) {
|
for (unsigned n = 0; n < tail_count; ++n) {
|
||||||
log_trace("ttl: remove-tail %" PRIu64, serial);
|
log_trace("ttl: remove-tail %" PRIu64, serial);
|
||||||
generate_pair(tail_serial);
|
generate_pair(tail_serial);
|
||||||
@ -96,12 +100,14 @@ bool testcase_ttl::run() {
|
|||||||
failure("ttl: unexpected key-space overflow on the tail");
|
failure("ttl: unexpected key-space overflow on the tail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log_trace("ttl: purge state");
|
||||||
|
db_table_clear(dbi);
|
||||||
|
fifo.clear();
|
||||||
|
}
|
||||||
|
|
||||||
txn_restart(false, false);
|
txn_restart(false, false);
|
||||||
const unsigned head_count = edge2count(salt, count_max);
|
fifo.push_front(std::make_pair(serial, head_count));
|
||||||
fifo.push(std::make_pair(serial, head_count));
|
|
||||||
log_trace("ttl: push-head (serial %" PRIu64 ", count %u)", serial,
|
|
||||||
head_count);
|
|
||||||
|
|
||||||
for (unsigned n = 0; n < head_count; ++n) {
|
for (unsigned n = 0; n < head_count; ++n) {
|
||||||
log_trace("ttl: insert-head %" PRIu64, serial);
|
log_trace("ttl: insert-head %" PRIu64, serial);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user