MCPcopy Create free account
hub / github.com/apache/kvrocks / ParseFullDB

Method ParseFullDB

utils/kvrocks2redis/parser.cc:34–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32#include "types/redis_string.h"
33
34Status Parser::ParseFullDB() {
35 rocksdb::DB *db = storage_->GetDB();
36 rocksdb::ColumnFamilyHandle *metadata_cf_handle = storage_->GetCFHandle(ColumnFamilyID::Metadata);
37 // Due to RSI(Rocksdb Secondary Instance) not supporting "Snapshots based read", we don't need to set the snapshot
38 // parameter. However, until we proactively invoke TryCatchUpWithPrimary, this replica is read-only, which can be
39 // considered as a snapshot.
40 rocksdb::ReadOptions read_options;
41 read_options.fill_cache = false;
42 std::unique_ptr<rocksdb::Iterator> iter(db->NewIterator(read_options, metadata_cf_handle));
43 for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
44 Metadata metadata(kRedisNone);
45 auto ds = metadata.Decode(iter->value());
46 if (!ds.ok()) {
47 continue;
48 }
49
50 if (metadata.Expired()) { // ignore the expired key
51 continue;
52 }
53
54 Status s;
55 if (metadata.Type() == kRedisString) {
56 s = parseSimpleKV(iter->key(), iter->value(), metadata.expire);
57 } else {
58 s = parseComplexKV(iter->key(), metadata);
59 }
60 if (!s.IsOK()) return s;
61 }
62
63 return Status::OK();
64}
65
66Status Parser::parseSimpleKV(const Slice &ns_key, const Slice &value, uint64_t expire) {
67 auto [ns, user_key] = ExtractNamespaceKey<std::string>(ns_key, slot_id_encoded_);

Callers 1

Calls 9

GetDBMethod · 0.80
GetCFHandleMethod · 0.80
NewIteratorMethod · 0.80
ExpiredMethod · 0.80
ValidMethod · 0.45
NextMethod · 0.45
DecodeMethod · 0.45
TypeMethod · 0.45
IsOKMethod · 0.45

Tested by

no test coverage detected