mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
chore: retire TEST_EnableHeartBeat (#3435)
Now unit tests will run the same Hearbeat fiber like in prod. The whole feature was redundant, with just few explicit settings of maxmemory_limit I succeeeded to make all unit tests pass. In addition, this change allows passing a global handler that is called by heartbeat from a single thread. This is not used yet - preparation for the next PR to break hung up replication connections on a master. Finally, this change has some non-functional clean-ups and warning fixes to improve code quality. Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
parent
82298b8122
commit
c9ed3f7b2b
22 changed files with 56 additions and 100 deletions
|
@ -406,14 +406,15 @@ void EngineShard::StopPeriodicFiber() {
|
|||
}
|
||||
}
|
||||
|
||||
void EngineShard::StartPeriodicFiber(util::ProactorBase* pb) {
|
||||
void EngineShard::StartPeriodicFiber(util::ProactorBase* pb, std::function<void()> global_handler) {
|
||||
uint32_t clock_cycle_ms = 1000 / std::max<uint32_t>(1, GetFlag(FLAGS_hz));
|
||||
if (clock_cycle_ms == 0)
|
||||
clock_cycle_ms = 1;
|
||||
|
||||
fiber_periodic_ = MakeFiber([this, index = pb->GetPoolIndex(), period_ms = clock_cycle_ms] {
|
||||
fiber_periodic_ = MakeFiber([this, index = pb->GetPoolIndex(), period_ms = clock_cycle_ms,
|
||||
handler = std::move(global_handler)] {
|
||||
ThisFiber::SetName(absl::StrCat("shard_periodic", index));
|
||||
RunPeriodic(std::chrono::milliseconds(period_ms));
|
||||
RunPeriodic(std::chrono::milliseconds(period_ms), std::move(handler));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -671,7 +672,8 @@ void EngineShard::Heartbeat() {
|
|||
}
|
||||
}
|
||||
|
||||
void EngineShard::RunPeriodic(std::chrono::milliseconds period_ms) {
|
||||
void EngineShard::RunPeriodic(std::chrono::milliseconds period_ms,
|
||||
std::function<void()> global_handler) {
|
||||
VLOG(1) << "RunPeriodic with period " << period_ms.count() << "ms";
|
||||
|
||||
bool runs_global_periodic = (shard_id() == 0); // Only shard 0 runs global periodic.
|
||||
|
@ -716,6 +718,10 @@ void EngineShard::RunPeriodic(std::chrono::milliseconds period_ms) {
|
|||
rss_mem_peak.store(total_rss, memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
if (global_handler) {
|
||||
global_handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -762,12 +768,6 @@ size_t EngineShard::UsedMemory() const {
|
|||
search_indices()->GetUsedMemory();
|
||||
}
|
||||
|
||||
void EngineShard::TEST_EnableHeartbeat() {
|
||||
fiber_periodic_ = fb2::Fiber("shard_periodic_TEST", [this, period_ms = 1] {
|
||||
RunPeriodic(std::chrono::milliseconds(period_ms));
|
||||
});
|
||||
}
|
||||
|
||||
bool EngineShard::ShouldThrottleForTiering() const { // see header for formula justification
|
||||
if (!tiered_storage_)
|
||||
return false;
|
||||
|
@ -902,7 +902,7 @@ size_t GetTieredFileLimit(size_t threads) {
|
|||
return max_shard_file_size;
|
||||
}
|
||||
|
||||
void EngineShardSet::Init(uint32_t sz, bool update_db_time) {
|
||||
void EngineShardSet::Init(uint32_t sz, std::function<void()> global_handler) {
|
||||
CHECK_EQ(0u, size());
|
||||
shard_queue_.resize(sz);
|
||||
|
||||
|
@ -920,10 +920,8 @@ void EngineShardSet::Init(uint32_t sz, bool update_db_time) {
|
|||
auto* shard = EngineShard::tlocal();
|
||||
shard->InitTieredStorage(pb, max_shard_file_size);
|
||||
|
||||
if (update_db_time) {
|
||||
// Must be last, as it accesses objects initialized above.
|
||||
shard->StartPeriodicFiber(pb);
|
||||
}
|
||||
// Must be last, as it accesses objects initialized above.
|
||||
shard->StartPeriodicFiber(pb, global_handler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -949,10 +947,6 @@ void EngineShardSet::InitThreadLocal(ProactorBase* pb) {
|
|||
shard_queue_[es->shard_id()] = es->GetFiberQueue();
|
||||
}
|
||||
|
||||
void EngineShardSet::TEST_EnableHeartBeat() {
|
||||
RunBriefInParallel([](EngineShard* shard) { shard->TEST_EnableHeartbeat(); });
|
||||
}
|
||||
|
||||
void EngineShardSet::TEST_EnableCacheMode() {
|
||||
RunBlockingInParallel([](EngineShard* shard) {
|
||||
namespaces.GetDefaultNamespace().GetCurrentDbSlice().TEST_EnableCacheMode();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue