]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/utilities/debug.cc
build: use dgit for download target
[ceph.git] / ceph / src / rocksdb / utilities / debug.cc
CommitLineData
11fdf7f2
TL
1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
5
6#ifndef ROCKSDB_LITE
7
8#include "rocksdb/utilities/debug.h"
9
10#include "db/db_impl.h"
11
12namespace rocksdb {
13
14Status GetAllKeyVersions(DB* db, Slice begin_key, Slice end_key,
15 size_t max_num_ikeys,
16 std::vector<KeyVersion>* key_versions) {
17 assert(key_versions != nullptr);
18 key_versions->clear();
19
20 DBImpl* idb = static_cast<DBImpl*>(db->GetRootDB());
21 auto icmp = InternalKeyComparator(idb->GetOptions().comparator);
22 RangeDelAggregator range_del_agg(icmp, {} /* snapshots */);
23 Arena arena;
24 ScopedArenaIterator iter(idb->NewInternalIterator(&arena, &range_del_agg));
25
26 if (!begin_key.empty()) {
27 InternalKey ikey;
28 ikey.SetMinPossibleForUserKey(begin_key);
29 iter->Seek(ikey.Encode());
30 } else {
31 iter->SeekToFirst();
32 }
33
34 size_t num_keys = 0;
35 for (; iter->Valid(); iter->Next()) {
36 ParsedInternalKey ikey;
37 if (!ParseInternalKey(iter->key(), &ikey)) {
38 return Status::Corruption("Internal Key [" + iter->key().ToString() +
39 "] parse error!");
40 }
41
42 if (!end_key.empty() &&
43 icmp.user_comparator()->Compare(ikey.user_key, end_key) > 0) {
44 break;
45 }
46
47 key_versions->emplace_back(ikey.user_key.ToString() /* _user_key */,
48 iter->value().ToString() /* _value */,
49 ikey.sequence /* _sequence */,
50 static_cast<int>(ikey.type) /* _type */);
51 if (++num_keys >= max_num_ikeys) {
52 break;
53 }
54 }
55 return Status::OK();
56}
57
58} // namespace rocksdb
59
60#endif // ROCKSDB_LITE