diff --git a/src/kv_cli.cpp b/src/kv_cli.cpp index e71f38f9..ab2e3718 100644 --- a/src/kv_cli.cpp +++ b/src/kv_cli.cpp @@ -255,9 +255,13 @@ void kv_cli_t::handle_cmd(const std::string & cmd, std::function cb) key != "kv_allocate_blocks" && key != "kv_evict_max_misses" && 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 { diff --git a/src/kv_db.cpp b/src/kv_db.cpp index ba89c910..22d4bd25 100644 --- a/src/kv_db.cpp +++ b/src/kv_db.cpp @@ -133,6 +133,7 @@ struct kv_db_t uint64_t evict_max_misses = 10; uint64_t evict_attempts_per_level = 3; uint64_t allocate_blocks = 4; + uint64_t log_level = 1; // state 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->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->log_level = !cfg["kv_log_level"].is_null() ? cfg["kv_log_level"].uint64_value() : 1; } void kv_db_t::close(std::function 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). // It will miss data from [c, b). // 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", - !this->updated && this->retry > 0 ? "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()); + bool fatal = !this->updated && this->retry > 0; + if (fatal || db->log_level > 0) + { + 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) { this->updated = false; diff --git a/src/kv_stress.cpp b/src/kv_stress.cpp index 29033076..b0eb9cf5 100644 --- a/src/kv_stress.cpp +++ b/src/kv_stress.cpp @@ -61,7 +61,7 @@ public: uint64_t max_value_len = 300; uint64_t print_stats_interval = 1; bool json_output = false; - bool trace = true; + bool trace = false; bool stop_on_error = false; // FIXME: Multiple clients 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" " --json\n" " JSON output\n" - " --trace 1\n" - " Print all executed operations\n" " --stop_on_error 0\n" " Stop on first execution error, mismatch, lost key or extra key during listing\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" " with bottom-most levels\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 ); exit(0); @@ -216,8 +216,6 @@ void kv_test_t::parse_config(json11::Json cfg) print_stats_interval = cfg["print_stats"].uint64_value(); if (!cfg["json"].is_null()) json_output = true; - if (!cfg["trace"].is_null()) - trace = cfg["trace"].bool_value(); if (!cfg["stop_on_error"].is_null()) stop_on_error = cfg["stop_on_error"].bool_value(); 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"]; if (!cfg["kv_evict_unused_age"].is_null()) 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; stat.get.name = "get"; stat.add.name = "add";