Skip to content

Commit 13e5612

Browse files
committed
fix: support dump for external objects
Before: the code crashed on check-fail if a dump of the external string was requested. This PR fixes it. We call SerializerBase::DumpObject also in CmdSerializer::SerializeRestore, and there we also do not handle the external strings, which will be fixed in the future. Signed-off-by: Roman Gershman <[email protected]>
1 parent db9eae1 commit 13e5612

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

src/server/generic_family.cc

+16-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ extern "C" {
3131
#include "server/rdb_save.h"
3232
#include "server/search/doc_index.h"
3333
#include "server/set_family.h"
34+
#include "server/tiered_storage.h"
3435
#include "server/transaction.h"
36+
#include "util/fibers/future.h"
3537
#include "util/varz.h"
3638

3739
ABSL_FLAG(uint32_t, dbnum, 16, "Number of databases");
@@ -524,9 +526,21 @@ OpResult<std::string> OpDump(const OpArgs& op_args, string_view key) {
524526
if (IsValid(it)) {
525527
DVLOG(1) << "Dump: key '" << key << "' successfully found, going to dump it";
526528
io::StringSink sink;
527-
SerializerBase::DumpObject(it->second, &sink);
528-
return sink.str(); // TODO: Add rvalue overload to str()
529+
const PrimeValue& pv = it->second;
530+
531+
if (pv.IsExternal() && !pv.IsCool()) {
532+
util::fb2::Future<string> future =
533+
op_args.shard->tiered_storage()->Read(op_args.db_cntx.db_index, key, pv);
534+
535+
CompactObj co(future.Get());
536+
SerializerBase::DumpObject(co, &sink);
537+
} else {
538+
SerializerBase::DumpObject(it->second, &sink);
539+
}
540+
541+
return std::move(sink).str();
529542
}
543+
530544
// fallback
531545
DVLOG(1) << "Dump: '" << key << "' Not found";
532546
return OpStatus::KEY_NOTFOUND;

src/server/rdb_save.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,14 @@ std::error_code RdbSerializer::SaveValue(const PrimeValue& pv) {
243243
if (opt_int) {
244244
ec = SaveLongLongAsString(*opt_int);
245245
} else {
246-
ec = SaveString(pv.GetSlice(&tmp_str_));
246+
if (pv.IsExternal()) {
247+
if (pv.IsCool()) {
248+
return SaveValue(pv.GetCool().record->value);
249+
}
250+
LOG(FATAL) << "External string not supported yet";
251+
} else {
252+
ec = SaveString(pv.GetSlice(&tmp_str_));
253+
}
247254
}
248255
} else {
249256
ec = SaveObject(pv);

src/server/snapshot.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,8 @@ void SliceSnapshot::SerializeExternal(DbIndex db_index, PrimeKey key, const Prim
389389
time_t expire_time, uint32_t mc_flags) {
390390
// We prefer avoid blocking, so we just schedule a tiered read and append
391391
// it to the delayed entries.
392-
util::fb2::Future<string> future;
393-
auto cb = [future](const std::string& v) mutable { future.Resolve(v); };
394-
EngineShard::tlocal()->tiered_storage()->Read(db_index, key.ToString(), pv, std::move(cb));
392+
util::fb2::Future<string> future =
393+
EngineShard::tlocal()->tiered_storage()->Read(db_index, key.ToString(), pv);
395394

396395
delayed_entries_.push_back({db_index, std::move(key), std::move(future), expire_time, mc_flags});
397396
++type_freq_map_[RDB_TYPE_STRING];

src/server/tiered_storage_test.cc

+17
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,21 @@ TEST_F(TieredStorageTest, SetExistingExpire) {
355355
}
356356
}
357357

358+
TEST_F(TieredStorageTest, Dump) {
359+
absl::FlagSaver saver;
360+
SetFlag(&FLAGS_tiered_offload_threshold, 0.0f); // offload all values
361+
362+
// we want to test without cooling to trigger disk I/O on reads.
363+
SetFlag(&FLAGS_tiered_experimental_cooling, false);
364+
365+
const int kNum = 10;
366+
for (size_t i = 0; i < kNum; i++) {
367+
Run({"SET", absl::StrCat("k", i), BuildString(3000)}); // big enough to trigger offloading.
368+
}
369+
370+
ExpectConditionWithinTimeout([&] { return GetMetrics().tiered_stats.total_stashes == kNum; });
371+
372+
Run({"DUMP", "k0"});
373+
}
374+
358375
} // namespace dfly

0 commit comments

Comments
 (0)