Skip to content

Commit 17dcdf5

Browse files
committed
server: Collect page defrag results
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
1 parent 2c7e5e3 commit 17dcdf5

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/server/engine_shard.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ bool EngineShard::DefragTaskState::CheckRequired() {
386386
return false;
387387
}
388388

389-
bool EngineShard::DoDefrag(CollectPageStats collect_page_stats, const float threshold) {
389+
std::optional<CollectedPageStats> EngineShard::DoDefrag(CollectPageStats collect_page_stats,
390+
const float threshold) {
390391
// --------------------------------------------------------------------------
391392
// NOTE: This task is running with exclusive access to the shard.
392393
// i.e. - Since we are using shared nothing access here, and all access
@@ -406,7 +407,7 @@ bool EngineShard::DoDefrag(CollectPageStats collect_page_stats, const float thre
406407
// If we found no valid db, we finished traversing and start from scratch next time
407408
if (!slice.IsDbValid(defrag_state_.dbid)) {
408409
defrag_state_.ResetScanState();
409-
return false;
410+
return std::nullopt;
410411
}
411412

412413
DCHECK(slice.IsDbValid(defrag_state_.dbid));
@@ -447,7 +448,7 @@ bool EngineShard::DoDefrag(CollectPageStats collect_page_stats, const float thre
447448
stats_.defrag_task_invocation_total++;
448449
stats_.defrag_attempt_total += attempts;
449450

450-
return true;
451+
return page_usage.CollectedStats();
451452
}
452453

453454
// the memory defragmentation task is as follow:

src/server/engine_shard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class EngineShard {
206206
// threshold can be passed, which will be used to determine if defragmentation should be
207207
// performed.
208208
// Returns true if defragmentation was performed.
209-
bool DoDefrag(CollectPageStats collect_page_stats, float threshold);
209+
std::optional<CollectedPageStats> DoDefrag(CollectPageStats collect_page_stats, float threshold);
210210

211211
private:
212212
struct DefragTaskState {

src/server/memory_cmd.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,15 @@ void MemoryCmd::Run(CmdArgList args) {
177177
static const float default_threshold =
178178
absl::GetFlag(FLAGS_mem_defrag_page_utilization_threshold);
179179
const float threshold = parser.NextOrDefault(default_threshold);
180-
shard_set->pool()->AwaitFiberOnAll([threshold](util::ProactorBase*) {
181-
if (auto* shard = EngineShard::tlocal(); shard)
182-
shard->DoDefrag(CollectPageStats::YES, threshold);
180+
181+
CollectedPageStats results[shard_set->size()];
182+
shard_set->pool()->AwaitFiberOnAll([threshold, &results](util::ProactorBase*) {
183+
if (auto* shard = EngineShard::tlocal(); shard) {
184+
if (auto shard_res = shard->DoDefrag(CollectPageStats::YES, threshold);
185+
shard_res.has_value()) {
186+
results[shard->shard_id()] = std::move(shard_res.value());
187+
}
188+
}
183189
});
184190
return builder_->SendSimpleString("OK");
185191
}

0 commit comments

Comments
 (0)