Skip to content

Commit 129d691

Browse files
committed
core: Record change in size after defrag
For JSON type, after defrag size may change. The page usage object carries this change out to a higher call level where the db stats can be updated. Signed-off-by: Abhijat Malviya <[email protected]>
1 parent db178da commit 129d691

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/core/page_usage_stats.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,14 @@ bool PageUsage::ConsumePageStats(mi_page_usage_stats_t stat) {
179179
return force_reallocate_ || should_reallocate;
180180
}
181181

182+
void PageUsage::RecordChangeInSize(const unsigned object_type, const ssize_t delta) {
183+
last_delta_ = {object_type, delta};
184+
}
185+
186+
PageUsage::TypeAndDelta PageUsage::FetchAndResetDelta() {
187+
const auto delta = last_delta_;
188+
last_delta_ = {0, 0};
189+
return delta;
190+
}
191+
182192
} // namespace dfly

src/core/page_usage_stats.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ struct CollectedPageStats {
4141
};
4242

4343
class PageUsage {
44+
using TypeAndDelta = std::pair<unsigned, ssize_t>;
45+
4446
public:
4547
PageUsage(CollectPageStats collect_stats, float threshold);
4648

@@ -66,6 +68,12 @@ class PageUsage {
6668
force_reallocate_ = force_reallocate;
6769
}
6870

71+
// Record change in size for the last object defragmented. Primarily for use in defragmenting JSON
72+
// objects.
73+
void RecordChangeInSize(unsigned object_type, ssize_t delta);
74+
75+
TypeAndDelta FetchAndResetDelta();
76+
6977
private:
7078
CollectPageStats collect_stats_{CollectPageStats::NO};
7179
float threshold_;
@@ -93,6 +101,8 @@ class PageUsage {
93101

94102
// For use in testing, forces reallocate check to always return true
95103
bool force_reallocate_{false};
104+
105+
TypeAndDelta last_delta_;
96106
};
97107

98108
} // namespace dfly

0 commit comments

Comments
 (0)