Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(tiering): add prints to find crash flow #2673

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/server/tiered_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,12 @@ void TieredStorage::Free(PrimeIterator it, DbTableStats* stats) {
alloc_.Free(offset, len);
} else {
uint32_t offs_page = offset / kBlockLen;
auto it = page_refcnt_.find(offs_page);
CHECK(it != page_refcnt_.end()) << offs_page;
CHECK_GT(it->second, 0u);
if (--it->second == 0) {
auto page_it = page_refcnt_.find(offs_page);
CHECK(page_it != page_refcnt_.end()) << offs_page << "," << it->first.ToString();
CHECK_GT(page_it->second, 0u);
if (--page_it->second == 0) {
alloc_.Free(offs_page * kBlockLen, kBlockLen);
page_refcnt_.erase(it);
page_refcnt_.erase(page_it);
}
}

Expand Down Expand Up @@ -402,6 +402,7 @@ void TieredStorage::FinishIoRequest(int io_res, InflightWriteRequest* req) {
}

PrimeIterator TieredStorage::Load(DbIndex db_index, PrimeIterator it, string_view key) {
VLOG(2) << "Load:" << key;
PrimeValue* entry = &it->second;
CHECK(entry->IsExternal());
DCHECK_EQ(entry->ObjType(), OBJ_STRING);
Expand Down Expand Up @@ -469,7 +470,7 @@ bool TieredStorage::PrepareForOffload(DbIndex db_index, PrimeIterator it) {
return false;
}

VLOG(2) << "ScheduleOffload:" << it->first.ToString();
VLOG(2) << "PrepareForOffload:" << it->first.ToString();
bin_record.pending_entries.insert(it->first.AsRef());
it->second.SetIoPending(true);

Expand All @@ -480,6 +481,7 @@ bool TieredStorage::PrepareForOffload(DbIndex db_index, PrimeIterator it) {
}

void TieredStorage::CancelOffload(DbIndex db_index, PrimeIterator it) {
VLOG(2) << "CancelOffload:" << it->first.ToString();
size_t blob_len = it->second.Size();
if (blob_len > kMaxSmallBin) {
return;
Expand Down Expand Up @@ -521,6 +523,7 @@ error_code TieredStorage::ScheduleOffload(DbIndex db_index, PrimeIterator it) {
}

error_code TieredStorage::ScheduleOffloadInternal(DbIndex db_index, PrimeIterator it) {
VLOG(2) << "PrepareForOffload:" << it->first.ToString();
size_t blob_len = it->second.Size();

if (blob_len > kMaxSmallBin) {
Expand Down
22 changes: 21 additions & 1 deletion src/server/tiered_storage_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ using absl::SetFlag;
using absl::StrCat;

ABSL_DECLARE_FLAG(string, tiered_prefix);

ABSL_DECLARE_FLAG(uint32_t, tiered_storage_max_pending_writes);
ABSL_DECLARE_FLAG(float, tiered_offload_threshold);
namespace dfly {

class TieredStorageTest : public BaseFamilyTest {
Expand Down Expand Up @@ -318,4 +319,23 @@ TEST_F(TieredStorageTest, GetValueValidation) {
EXPECT_EQ(m.db_stats[0].tiered_entries, 0);
}

TEST_F(TieredStorageTest, BackgroundOffload) {
shard_set->TEST_EnableHeartBeat();
max_memory_limit = 300000;
absl::FlagSaver fs;
// Disable writing to disk
absl::SetFlag(&FLAGS_tiered_storage_max_pending_writes, 0);

const int kKeyNum = 100;
FillExternalKeys(kKeyNum);
usleep(20000);
Metrics m = GetMetrics();
EXPECT_EQ(m.db_stats[0].tiered_entries, 0);

absl::SetFlag(&FLAGS_tiered_storage_max_pending_writes, 1);
absl::SetFlag(&FLAGS_tiered_offload_threshold, 0);
FillExternalKeys(kKeyNum);
EXPECT_TRUE(WaitUntilTieredEntriesGT(0));
}

} // namespace dfly