Skip to content

Commit 5b8aea4

Browse files
authored
feat(tiering): Serialize hashes (#6015)
1 parent 61affa1 commit 5b8aea4

15 files changed

+216
-48
lines changed

src/core/compact_object.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,11 +1227,13 @@ CompactObj::ExternalRep CompactObj::GetExternalRep() const {
12271227
return static_cast<CompactObj::ExternalRep>(u_.ext_ptr.representation);
12281228
}
12291229

1230-
void CompactObj::SetCool(size_t offset, uint32_t sz, detail::TieredColdRecord* record) {
1230+
void CompactObj::SetCool(size_t offset, uint32_t sz, ExternalRep rep,
1231+
detail::TieredColdRecord* record) {
12311232
// We copy the mask of the "cooled" referenced object because it contains the encoding info.
12321233
SetMeta(EXTERNAL_TAG, record->value.mask_);
12331234

12341235
u_.ext_ptr.is_cool = 1;
1236+
u_.ext_ptr.representation = static_cast<uint8_t>(rep);
12351237
u_.ext_ptr.page_offset = offset % 4096;
12361238
u_.ext_ptr.serialized_size = sz;
12371239
u_.ext_ptr.cool_record = record;
@@ -1247,6 +1249,10 @@ auto CompactObj::GetCool() const -> CoolItem {
12471249
return res;
12481250
}
12491251

1252+
void CompactObj::Freeze(size_t offset, size_t sz) {
1253+
SetExternal(offset, sz, GetExternalRep());
1254+
}
1255+
12501256
std::pair<size_t, size_t> CompactObj::GetExternalSlice() const {
12511257
DCHECK_EQ(EXTERNAL_TAG, taglen_);
12521258
auto& ext = u_.ext_ptr;
@@ -1618,7 +1624,7 @@ StringOrView CompactObj::GetRawString() const {
16181624
return StringOrView::FromString(std::move(tmp));
16191625
}
16201626

1621-
LOG(FATAL) << "Unsupported tag for GetRawString(): " << taglen_;
1627+
LOG(FATAL) << "Unsupported tag for GetRawString(): " << int(taglen_);
16221628
return {};
16231629
}
16241630

src/core/compact_object.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ class CompactObj {
364364
}
365365

366366
// Assigns a cooling record to the object together with its external slice.
367-
void SetCool(size_t offset, uint32_t serialized_size, detail::TieredColdRecord* record);
367+
void SetCool(size_t offset, uint32_t serialized_size, ExternalRep rep,
368+
detail::TieredColdRecord* record);
368369

369370
struct CoolItem {
370371
uint16_t page_offset;
@@ -376,6 +377,10 @@ class CompactObj {
376377
// Returns the external data of the object incuding its ColdRecord.
377378
CoolItem GetCool() const;
378379

380+
// Prequisite: IsCool() is true.
381+
// Keeps cool record only as external value and discard in-memory part.
382+
void Freeze(size_t offset, size_t sz);
383+
379384
std::pair<size_t, size_t> GetExternalSlice() const;
380385

381386
// Injects either the the raw string (extracted with GetRawString()) or the usual string

src/core/detail/listpack_wrap.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ ListpackWrap::~ListpackWrap() {
3737
DCHECK(!dirty_);
3838
}
3939

40+
ListpackWrap ListpackWrap::WithCapacity(size_t capacity) {
41+
return ListpackWrap{lpNew(capacity)};
42+
}
43+
4044
uint8_t* ListpackWrap::GetPointer() {
4145
dirty_ = false;
4246
return lp_;

src/core/detail/listpack_wrap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ struct ListpackWrap {
4848
explicit ListpackWrap(uint8_t* lp) : lp_{lp} {
4949
}
5050

51+
// Create listpack with capacity
52+
static ListpackWrap WithCapacity(size_t capacity);
53+
5154
uint8_t* GetPointer(); // Get new updated pointer
5255
Iterator Find(std::string_view key) const; // Linear search
5356
bool Delete(std::string_view key);

src/server/common.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ bool ParseDouble(string_view src, double* value) {
162162
#define ADD(x) (x) += o.x
163163

164164
TieredStats& TieredStats::operator+=(const TieredStats& o) {
165-
static_assert(sizeof(TieredStats) == 160);
165+
static_assert(sizeof(TieredStats) == 168);
166166

167167
ADD(total_stashes);
168168
ADD(total_fetches);
@@ -182,6 +182,8 @@ TieredStats& TieredStats::operator+=(const TieredStats& o) {
182182
ADD(small_bins_cnt);
183183
ADD(small_bins_entries_cnt);
184184
ADD(small_bins_filling_bytes);
185+
ADD(small_bins_filling_entries_cnt);
186+
185187
ADD(total_stash_overflows);
186188
ADD(cold_storage_bytes);
187189
ADD(total_offloading_steps);

src/server/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct TieredStats {
9191
uint64_t small_bins_cnt = 0;
9292
uint64_t small_bins_entries_cnt = 0;
9393
size_t small_bins_filling_bytes = 0;
94+
size_t small_bins_filling_entries_cnt = 0;
9495
size_t cold_storage_bytes = 0;
9596

9697
uint64_t clients_throttled = 0; // current number of throttled clients

src/server/hset_family.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ OpResult<uint32_t> OpSet(const OpArgs& op_args, string_view key, CmdArgList valu
492492

493493
op_args.shard->search_indices()->AddDoc(key, op_args.db_cntx, pv);
494494

495+
if (auto* ts = op_args.shard->tiered_storage(); ts)
496+
ts->TryStash(op_args.db_cntx.db_index, key, &pv);
497+
495498
return created;
496499
}
497500

0 commit comments

Comments
 (0)