Add kv_log_level, print warnings on level 1, trace ops on level 10

antietcd
Vitaliy Filippov 2023-11-05 19:59:02 +03:00
parent 605afc3583
commit 79ae0aadcd
3 changed files with 24 additions and 11 deletions

View File

@ -255,9 +255,13 @@ void kv_cli_t::handle_cmd(const std::string & cmd, std::function<void()> cb)
key != "kv_allocate_blocks" && key != "kv_allocate_blocks" &&
key != "kv_evict_max_misses" && key != "kv_evict_max_misses" &&
key != "kv_evict_attempts_per_level" && key != "kv_evict_attempts_per_level" &&
key != "kv_evict_unused_age") key != "kv_evict_unused_age" &&
key != "kv_log_level")
{ {
fprintf(stderr, "Allowed properties: kv_memory_limit, kv_allocate_blocks, kv_evict_max_misses, kv_evict_attempts_per_level, kv_evict_unused_age\n"); fprintf(
stderr, "Allowed properties: kv_memory_limit, kv_allocate_blocks,"
" kv_evict_max_misses, kv_evict_attempts_per_level, kv_evict_unused_age, kv_log_level\n"
);
} }
else else
{ {

View File

@ -133,6 +133,7 @@ struct kv_db_t
uint64_t evict_max_misses = 10; uint64_t evict_max_misses = 10;
uint64_t evict_attempts_per_level = 3; uint64_t evict_attempts_per_level = 3;
uint64_t allocate_blocks = 4; uint64_t allocate_blocks = 4;
uint64_t log_level = 1;
// state // state
uint64_t evict_unused_counter = 0; uint64_t evict_unused_counter = 0;
@ -533,6 +534,7 @@ void kv_db_t::set_config(json11::Json cfg)
this->evict_unused_age = cfg["kv_evict_unused_age"].is_null() ? 1000 : cfg["kv_evict_unused_age"].uint64_value(); this->evict_unused_age = cfg["kv_evict_unused_age"].is_null() ? 1000 : cfg["kv_evict_unused_age"].uint64_value();
this->cache_max_blocks = this->memory_limit / this->kv_block_size; this->cache_max_blocks = this->memory_limit / this->kv_block_size;
this->allocate_blocks = cfg["kv_allocate_blocks"].uint64_value() ? cfg["kv_allocate_blocks"].uint64_value() : 4; this->allocate_blocks = cfg["kv_allocate_blocks"].uint64_value() ? cfg["kv_allocate_blocks"].uint64_value() : 4;
this->log_level = !cfg["kv_log_level"].is_null() ? cfg["kv_log_level"].uint64_value() : 1;
} }
void kv_db_t::close(std::function<void()> cb) void kv_db_t::close(std::function<void()> cb)
@ -964,9 +966,13 @@ int kv_op_t::handle_block(int res, bool updated, bool stop_on_split)
// We may read P on step (1), get a link to A, and read A on step (4). // We may read P on step (1), get a link to A, and read A on step (4).
// It will miss data from [c, b). // It will miss data from [c, b).
// Retry once. If we don't see any updates after retrying - fail with EILSEQ. // Retry once. If we don't see any updates after retrying - fail with EILSEQ.
fprintf(stderr, "K/V: %sgot unrelated block %lu: key=%s range=[%s, %s) from=[%s, %s)\n", bool fatal = !this->updated && this->retry > 0;
!this->updated && this->retry > 0 ? "Error: " : "Warning: read/update collision: ", if (fatal || db->log_level > 0)
cur_block, key.c_str(), blk->key_ge.c_str(), blk->key_lt.c_str(), prev_key_ge.c_str(), prev_key_lt.c_str()); {
fprintf(stderr, "K/V: %sgot unrelated block %lu: key=%s range=[%s, %s) from=[%s, %s)\n",
fatal ? "Error: " : "Warning: read/update collision: ",
cur_block, key.c_str(), blk->key_ge.c_str(), blk->key_lt.c_str(), prev_key_ge.c_str(), prev_key_lt.c_str());
}
if (this->updated) if (this->updated)
{ {
this->updated = false; this->updated = false;

View File

@ -61,7 +61,7 @@ public:
uint64_t max_value_len = 300; uint64_t max_value_len = 300;
uint64_t print_stats_interval = 1; uint64_t print_stats_interval = 1;
bool json_output = false; bool json_output = false;
bool trace = true; bool trace = false;
bool stop_on_error = false; bool stop_on_error = false;
// FIXME: Multiple clients // FIXME: Multiple clients
kv_test_stat_t stat, prev_stat; kv_test_stat_t stat, prev_stat;
@ -153,8 +153,6 @@ json11::Json::object kv_test_t::parse_args(int narg, const char *args[])
" Print operation statistics every this number of seconds\n" " Print operation statistics every this number of seconds\n"
" --json\n" " --json\n"
" JSON output\n" " JSON output\n"
" --trace 1\n"
" Print all executed operations\n"
" --stop_on_error 0\n" " --stop_on_error 0\n"
" Stop on first execution error, mismatch, lost key or extra key during listing\n" " Stop on first execution error, mismatch, lost key or extra key during listing\n"
" --kv_memory_limit 128M\n" " --kv_memory_limit 128M\n"
@ -168,7 +166,9 @@ json11::Json::object kv_test_t::parse_args(int narg, const char *args[])
" Retry eviction at most this number of times per tree level, starting\n" " Retry eviction at most this number of times per tree level, starting\n"
" with bottom-most levels\n" " with bottom-most levels\n"
" --kv_evict_unused_age 1000\n" " --kv_evict_unused_age 1000\n"
" Evict only keys unused during this number of last operations\n", " Evict only keys unused during this number of last operations\n"
" --kv_log_level 1\n"
" Log level. 0 = errors, 1 = warnings, 10 = trace operations\n",
exe_name exe_name
); );
exit(0); exit(0);
@ -216,8 +216,6 @@ void kv_test_t::parse_config(json11::Json cfg)
print_stats_interval = cfg["print_stats"].uint64_value(); print_stats_interval = cfg["print_stats"].uint64_value();
if (!cfg["json"].is_null()) if (!cfg["json"].is_null())
json_output = true; json_output = true;
if (!cfg["trace"].is_null())
trace = cfg["trace"].bool_value();
if (!cfg["stop_on_error"].is_null()) if (!cfg["stop_on_error"].is_null())
stop_on_error = cfg["stop_on_error"].bool_value(); stop_on_error = cfg["stop_on_error"].bool_value();
if (!cfg["kv_memory_limit"].is_null()) if (!cfg["kv_memory_limit"].is_null())
@ -230,6 +228,11 @@ void kv_test_t::parse_config(json11::Json cfg)
kv_cfg["kv_evict_attempts_per_level"] = cfg["kv_evict_attempts_per_level"]; kv_cfg["kv_evict_attempts_per_level"] = cfg["kv_evict_attempts_per_level"];
if (!cfg["kv_evict_unused_age"].is_null()) if (!cfg["kv_evict_unused_age"].is_null())
kv_cfg["kv_evict_unused_age"] = cfg["kv_evict_unused_age"]; kv_cfg["kv_evict_unused_age"] = cfg["kv_evict_unused_age"];
if (!cfg["kv_log_level"].is_null())
{
trace = cfg["kv_log_level"].uint64_value() >= 10;
kv_cfg["kv_log_level"] = cfg["kv_log_level"];
}
total_prob = reopen_prob+get_prob+add_prob+update_prob+del_prob+list_prob; total_prob = reopen_prob+get_prob+add_prob+update_prob+del_prob+list_prob;
stat.get.name = "get"; stat.get.name = "get";
stat.add.name = "add"; stat.add.name = "add";