Skip to content

Commit c4d05ba

Browse files
authored
fix(tiering): Fix upload strategy (#6067)
1 parent 1deb9f8 commit c4d05ba

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/server/tiered_storage.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,8 @@ void TieredStorage::RunOffloading(DbIndex dbid) {
551551
auto cb = [this, dbid, &tmp](PrimeIterator it) mutable {
552552
stats_.offloading_steps++;
553553
if (ShouldStash(it->second)) {
554-
if (it->first.WasTouched()) {
555-
it->first.SetTouched(false);
554+
if (it->second.WasTouched()) {
555+
it->second.SetTouched(false);
556556
} else {
557557
stats_.offloading_stashes++;
558558
TryStash(dbid, it->first.GetSlice(&tmp), &it->second);

src/server/tiered_storage_test.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,41 @@ TEST_F(PureDiskTSTest, BackgroundOffloading) {
322322
EXPECT_EQ(metrics.tiered_stats.allocated_bytes, kNum * 4096);
323323
}
324324

325+
// Verify correctness of our offloading startegy, offloading values only after second access.
326+
TEST_F(PureDiskTSTest, OffloadingStrategy) {
327+
// Create value and wait to be offlaoded
328+
string value = BuildString(3000);
329+
Run({"set", "key", value});
330+
ExpectConditionWithinTimeout([&] { return GetMetrics().db_stats[0].tiered_entries == 1; });
331+
332+
// Check base values
333+
auto metrics = GetMetrics();
334+
EXPECT_EQ(metrics.tiered_stats.total_fetches, 0);
335+
EXPECT_EQ(metrics.tiered_stats.total_uploads, 0);
336+
EXPECT_EQ(metrics.tiered_stats.total_stashes, 1);
337+
338+
// Repeat a few times
339+
for (size_t i = 1; i <= 3; i++) {
340+
// Value is not uploaded after first read
341+
Run({"get", "key"});
342+
metrics = GetMetrics();
343+
EXPECT_EQ(metrics.tiered_stats.total_fetches, 2 * i - 1);
344+
EXPECT_EQ(metrics.tiered_stats.total_uploads, i - 1);
345+
346+
// But on second read upload should happend at the end of chain due to two touches
347+
Run({"get", "key"});
348+
ExpectConditionWithinTimeout([&] { return GetMetrics().tiered_stats.total_uploads == i; });
349+
metrics = GetMetrics();
350+
EXPECT_EQ(metrics.tiered_stats.total_fetches, 2 * i);
351+
352+
// Wait for offloading again
353+
ExpectConditionWithinTimeout([&] { return GetMetrics().db_stats[0].tiered_entries == 1; });
354+
metrics = GetMetrics();
355+
EXPECT_EQ(metrics.tiered_stats.total_offloading_stashes, i);
356+
EXPECT_EQ(metrics.tiered_stats.total_stashes, i + 1);
357+
}
358+
}
359+
325360
// Test FLUSHALL while reading entries
326361
TEST_F(PureDiskTSTest, FlushAll) {
327362
const int kNum = 500;

src/server/tiering/decoders.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct StringDecoder : public Decoder {
6464
private:
6565
explicit StringDecoder(CompactObj::StrEncoding encoding);
6666

67-
bool modified_;
67+
bool modified_ = false;
6868
std::string_view slice_;
6969
CompactObj::StrEncoding encoding_;
7070
dfly::StringOrView value_;

0 commit comments

Comments
 (0)