db/batchlog_manager: wire in batchlog_replay_cleanup_after_replays

After the specified amount of replays, trigger a cleanup: flush batchlog
table memtables. This allows the cleanup to happen on a configurable
interval, instead of on every batchlog replay attempt, which might be
too much.
This commit is contained in:
Botond Dénes
2024-08-22 10:12:05 -04:00
committed by Asias He
parent 1635525526
commit 3361542e84
3 changed files with 11 additions and 1 deletions

View File

@@ -47,6 +47,7 @@ db::batchlog_manager::batchlog_manager(cql3::query_processor& qp, db::system_key
, _write_request_timeout(std::chrono::duration_cast<db_clock::duration>(config.write_request_timeout))
, _replay_rate(config.replay_rate)
, _delay(config.delay)
, _replay_cleanup_after_replays(config.replay_cleanup_after_replays)
, _loop_done(batchlog_replay_loop())
{
namespace sm = seastar::metrics;
@@ -89,6 +90,7 @@ future<> db::batchlog_manager::batchlog_replay_loop() {
co_return;
}
unsigned replay_counter = 0;
auto delay = _delay;
while (!_stop.abort_requested()) {
try {
@@ -97,7 +99,12 @@ future<> db::batchlog_manager::batchlog_replay_loop() {
co_return;
}
try {
co_await do_batch_log_replay(post_replay_cleanup::yes);
auto cleanup = post_replay_cleanup::no;
if (++replay_counter >= _replay_cleanup_after_replays) {
replay_counter = 0;
cleanup = post_replay_cleanup::yes;
}
co_await do_batch_log_replay(cleanup);
} catch (seastar::broken_semaphore&) {
if (_stop.abort_requested()) {
co_return;

View File

@@ -35,6 +35,7 @@ struct batchlog_manager_config {
std::chrono::duration<double> write_request_timeout;
uint64_t replay_rate = std::numeric_limits<uint64_t>::max();
std::chrono::milliseconds delay = std::chrono::milliseconds(0);
unsigned replay_cleanup_after_replays;
};
class batchlog_manager : public peering_sharded_service<batchlog_manager> {
@@ -59,6 +60,7 @@ private:
db_clock::duration _write_request_timeout;
uint64_t _replay_rate;
std::chrono::milliseconds _delay;
unsigned _replay_cleanup_after_replays = 100;
semaphore _sem{1};
seastar::gate _gate;
unsigned _cpu = 0;

View File

@@ -2052,6 +2052,7 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl
bm_cfg.write_request_timeout = cfg->write_request_timeout_in_ms() * 1ms;
bm_cfg.replay_rate = cfg->batchlog_replay_throttle_in_kb() * 1000;
bm_cfg.delay = std::chrono::milliseconds(cfg->ring_delay_ms());
bm_cfg.replay_cleanup_after_replays = cfg->batchlog_replay_cleanup_after_replays();
bm.start(std::ref(qp), std::ref(sys_ks), bm_cfg).get();
auto stop_batchlog_manager = defer_verbose_shutdown("batchlog manager", [&bm] {