2018-11-04 23:57:27 +08:00
|
|
|
|
/*
|
2019-02-03 17:28:01 +08:00
|
|
|
|
* Copyright 2017-2019 Leonid Yuriev <leo@yuriev.ru>
|
2017-03-30 23:54:57 +08:00
|
|
|
|
* and other libmdbx authors: please see AUTHORS file.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
|
* Public License.
|
|
|
|
|
*
|
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "base.h"
|
2017-04-12 00:00:26 +08:00
|
|
|
|
#include "chrono.h"
|
2017-03-30 23:54:57 +08:00
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "keygen.h"
|
|
|
|
|
#include "log.h"
|
|
|
|
|
#include "osal.h"
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
|
|
bool test_execute(const actor_config &config);
|
|
|
|
|
std::string thunk_param(const actor_config &config);
|
2017-04-21 23:41:11 +08:00
|
|
|
|
void testcase_setup(const char *casename, actor_params ¶ms,
|
2017-05-18 01:10:56 +08:00
|
|
|
|
unsigned &last_space_id);
|
|
|
|
|
void configure_actor(unsigned &last_space_id, const actor_testcase testcase,
|
|
|
|
|
const char *space_id_cstr, const actor_params ¶ms);
|
|
|
|
|
void keycase_setup(const char *casename, actor_params ¶ms);
|
2017-03-30 23:54:57 +08:00
|
|
|
|
|
|
|
|
|
namespace global {
|
|
|
|
|
|
|
|
|
|
extern const char thunk_param_prefix[];
|
|
|
|
|
extern std::vector<actor_config> actors;
|
|
|
|
|
extern std::unordered_map<unsigned, actor_config *> events;
|
|
|
|
|
extern std::unordered_map<mdbx_pid_t, actor_config *> pid2actor;
|
|
|
|
|
extern std::set<std::string> databases;
|
2017-04-21 23:41:11 +08:00
|
|
|
|
extern unsigned nactors;
|
|
|
|
|
extern chrono::time start_motonic;
|
|
|
|
|
extern chrono::time deadline_motonic;
|
|
|
|
|
extern bool singlemode;
|
2017-03-30 23:54:57 +08:00
|
|
|
|
|
|
|
|
|
namespace config {
|
2017-04-21 23:41:11 +08:00
|
|
|
|
extern unsigned timeout_duration_seconds;
|
2017-03-30 23:54:57 +08:00
|
|
|
|
extern bool dump_config;
|
2017-04-21 23:41:11 +08:00
|
|
|
|
extern bool cleanup_before;
|
|
|
|
|
extern bool cleanup_after;
|
2017-04-23 17:54:37 +08:00
|
|
|
|
extern bool failfast;
|
2017-05-24 07:16:25 +08:00
|
|
|
|
extern bool progress_indicator;
|
2017-03-30 23:54:57 +08:00
|
|
|
|
} /* namespace config */
|
|
|
|
|
|
|
|
|
|
} /* namespace global */
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2017-05-24 06:42:10 +08:00
|
|
|
|
struct db_deleter : public std::unary_function<void, MDBX_env *> {
|
|
|
|
|
void operator()(MDBX_env *env) const { mdbx_env_close(env); }
|
2017-03-30 23:54:57 +08:00
|
|
|
|
};
|
|
|
|
|
|
2017-05-24 02:36:09 +08:00
|
|
|
|
struct txn_deleter : public std::unary_function<void, MDBX_txn *> {
|
|
|
|
|
void operator()(MDBX_txn *txn) const {
|
2017-03-30 23:54:57 +08:00
|
|
|
|
int rc = mdbx_txn_abort(txn);
|
|
|
|
|
if (rc)
|
2017-07-06 04:08:45 +08:00
|
|
|
|
log_trouble(mdbx_func_, "mdbx_txn_abort()", rc);
|
2017-03-30 23:54:57 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-24 06:42:10 +08:00
|
|
|
|
struct cursor_deleter : public std::unary_function<void, MDBX_cursor *> {
|
|
|
|
|
void operator()(MDBX_cursor *cursor) const { mdbx_cursor_close(cursor); }
|
2017-03-30 23:54:57 +08:00
|
|
|
|
};
|
|
|
|
|
|
2017-05-24 06:42:10 +08:00
|
|
|
|
typedef std::unique_ptr<MDBX_env, db_deleter> scoped_db_guard;
|
2017-05-24 02:36:09 +08:00
|
|
|
|
typedef std::unique_ptr<MDBX_txn, txn_deleter> scoped_txn_guard;
|
2017-05-24 06:42:10 +08:00
|
|
|
|
typedef std::unique_ptr<MDBX_cursor, cursor_deleter> scoped_cursor_guard;
|
2017-03-30 23:54:57 +08:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class testcase {
|
|
|
|
|
protected:
|
|
|
|
|
const actor_config &config;
|
|
|
|
|
const mdbx_pid_t pid;
|
|
|
|
|
|
|
|
|
|
scoped_db_guard db_guard;
|
|
|
|
|
scoped_txn_guard txn_guard;
|
|
|
|
|
scoped_cursor_guard cursor_guard;
|
|
|
|
|
bool signalled;
|
|
|
|
|
|
2017-04-21 23:41:11 +08:00
|
|
|
|
size_t nops_completed;
|
|
|
|
|
chrono::time start_timestamp;
|
2017-05-18 01:10:56 +08:00
|
|
|
|
keygen::buffer key;
|
|
|
|
|
keygen::buffer data;
|
|
|
|
|
keygen::maker keyvalue_maker;
|
2017-04-21 23:41:11 +08:00
|
|
|
|
|
2017-04-24 00:00:28 +08:00
|
|
|
|
struct {
|
|
|
|
|
mdbx_canary canary;
|
2017-07-02 14:07:57 +08:00
|
|
|
|
mutable chrono::time progress_timestamp;
|
2017-04-24 00:00:28 +08:00
|
|
|
|
} last;
|
|
|
|
|
|
2017-05-24 06:42:10 +08:00
|
|
|
|
static int oom_callback(MDBX_env *env, int pid, mdbx_tid_t tid, uint64_t txn,
|
2017-05-24 03:08:18 +08:00
|
|
|
|
unsigned gap, int retry);
|
|
|
|
|
|
2017-04-21 23:41:11 +08:00
|
|
|
|
void db_prepare();
|
|
|
|
|
void db_open();
|
|
|
|
|
void db_close();
|
2017-10-27 02:14:29 +08:00
|
|
|
|
void txn_begin(bool readonly, unsigned flags = 0);
|
2017-04-21 23:41:11 +08:00
|
|
|
|
void txn_end(bool abort);
|
2017-10-27 02:14:29 +08:00
|
|
|
|
void txn_restart(bool abort, bool readonly, unsigned flags = 0);
|
2018-03-19 21:51:44 +08:00
|
|
|
|
void txn_inject_writefault(void);
|
|
|
|
|
void txn_inject_writefault(MDBX_txn *txn);
|
2017-04-24 00:00:28 +08:00
|
|
|
|
void fetch_canary();
|
|
|
|
|
void update_canary(uint64_t increment);
|
2017-05-24 07:16:25 +08:00
|
|
|
|
void kick_progress(bool active) const;
|
2018-09-17 21:21:09 +08:00
|
|
|
|
void checkdata(const char *step, MDBX_dbi handle, MDBX_val key2check,
|
|
|
|
|
MDBX_val expected_valued);
|
2017-03-30 23:54:57 +08:00
|
|
|
|
|
2017-05-24 06:42:10 +08:00
|
|
|
|
MDBX_dbi db_table_open(bool create);
|
|
|
|
|
void db_table_drop(MDBX_dbi handle);
|
|
|
|
|
void db_table_close(MDBX_dbi handle);
|
2017-05-18 01:10:56 +08:00
|
|
|
|
|
2017-03-30 23:54:57 +08:00
|
|
|
|
bool wait4start();
|
|
|
|
|
void report(size_t nops_done);
|
|
|
|
|
void signal();
|
2017-05-25 14:51:26 +08:00
|
|
|
|
bool should_continue(bool check_timeout_only = false) const;
|
2017-04-21 23:41:11 +08:00
|
|
|
|
|
2017-07-02 14:07:57 +08:00
|
|
|
|
void generate_pair(const keygen::serial_t serial, keygen::buffer &out_key,
|
|
|
|
|
keygen::buffer &out_value, keygen::serial_t data_age = 0) {
|
|
|
|
|
keyvalue_maker.pair(serial, out_key, out_value, data_age);
|
2017-05-18 01:10:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void generate_pair(const keygen::serial_t serial,
|
|
|
|
|
keygen::serial_t data_age = 0) {
|
|
|
|
|
generate_pair(serial, key, data, data_age);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 02:14:29 +08:00
|
|
|
|
bool mode_readonly() const {
|
|
|
|
|
return (config.params.mode_flags & MDBX_RDONLY) ? true : false;
|
2017-04-21 23:41:11 +08:00
|
|
|
|
}
|
2017-03-30 23:54:57 +08:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
testcase(const actor_config &config, const mdbx_pid_t pid)
|
2017-07-04 17:24:14 +08:00
|
|
|
|
: config(config), pid(pid), signalled(false), nops_completed(0) {
|
2017-04-21 23:41:11 +08:00
|
|
|
|
start_timestamp.reset();
|
2017-04-24 00:00:28 +08:00
|
|
|
|
memset(&last, 0, sizeof(last));
|
2017-03-30 23:54:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual bool setup();
|
|
|
|
|
virtual bool run() { return true; }
|
|
|
|
|
virtual bool teardown();
|
|
|
|
|
virtual ~testcase() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class testcase_hill : public testcase {
|
|
|
|
|
public:
|
|
|
|
|
testcase_hill(const actor_config &config, const mdbx_pid_t pid)
|
|
|
|
|
: testcase(config, pid) {}
|
|
|
|
|
bool run();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class testcase_deadread : public testcase {
|
|
|
|
|
public:
|
|
|
|
|
testcase_deadread(const actor_config &config, const mdbx_pid_t pid)
|
|
|
|
|
: testcase(config, pid) {}
|
|
|
|
|
bool run();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class testcase_deadwrite : public testcase {
|
|
|
|
|
public:
|
|
|
|
|
testcase_deadwrite(const actor_config &config, const mdbx_pid_t pid)
|
|
|
|
|
: testcase(config, pid) {}
|
|
|
|
|
bool run();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class testcase_jitter : public testcase {
|
|
|
|
|
public:
|
|
|
|
|
testcase_jitter(const actor_config &config, const mdbx_pid_t pid)
|
|
|
|
|
: testcase(config, pid) {}
|
|
|
|
|
bool run();
|
|
|
|
|
};
|
2017-10-26 08:56:12 +08:00
|
|
|
|
|
|
|
|
|
class testcase_try : public testcase {
|
|
|
|
|
public:
|
|
|
|
|
testcase_try(const actor_config &config, const mdbx_pid_t pid)
|
|
|
|
|
: testcase(config, pid) {}
|
|
|
|
|
bool run();
|
|
|
|
|
};
|
2018-11-04 23:57:36 +08:00
|
|
|
|
|
|
|
|
|
class testcase_copy : public testcase {
|
|
|
|
|
const std::string copy_pathname;
|
|
|
|
|
void copy_db(const bool with_compaction);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
testcase_copy(const actor_config &config, const mdbx_pid_t pid)
|
|
|
|
|
: testcase(config, pid),
|
|
|
|
|
copy_pathname(config.params.pathname_db + "-copy") {}
|
|
|
|
|
bool run();
|
|
|
|
|
};
|