| 32 | #include "types/redis_string.h" |
| 33 | |
| 34 | Status 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 | |
| 66 | Status 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_); |
no test coverage detected