]>
Commit | Line | Data |
---|---|---|
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 | ||
f67539c2 | 10 | #include "db/db_impl/db_impl.h" |
11fdf7f2 | 11 | |
f67539c2 | 12 | namespace ROCKSDB_NAMESPACE { |
11fdf7f2 TL |
13 | |
14 | Status GetAllKeyVersions(DB* db, Slice begin_key, Slice end_key, | |
15 | size_t max_num_ikeys, | |
16 | std::vector<KeyVersion>* key_versions) { | |
f67539c2 TL |
17 | if (nullptr == db) { |
18 | return Status::InvalidArgument("db cannot be null."); | |
19 | } | |
20 | return GetAllKeyVersions(db, db->DefaultColumnFamily(), begin_key, end_key, | |
21 | max_num_ikeys, key_versions); | |
22 | } | |
23 | ||
24 | Status GetAllKeyVersions(DB* db, ColumnFamilyHandle* cfh, Slice begin_key, | |
25 | Slice end_key, size_t max_num_ikeys, | |
26 | std::vector<KeyVersion>* key_versions) { | |
27 | if (nullptr == db) { | |
28 | return Status::InvalidArgument("db cannot be null."); | |
29 | } | |
30 | if (nullptr == cfh) { | |
31 | return Status::InvalidArgument("Column family handle cannot be null."); | |
32 | } | |
33 | if (nullptr == key_versions) { | |
34 | return Status::InvalidArgument("key_versions cannot be null."); | |
35 | } | |
11fdf7f2 TL |
36 | key_versions->clear(); |
37 | ||
38 | DBImpl* idb = static_cast<DBImpl*>(db->GetRootDB()); | |
f67539c2 | 39 | auto icmp = InternalKeyComparator(idb->GetOptions(cfh).comparator); |
20effc67 | 40 | ReadOptions read_options; |
494da23a TL |
41 | ReadRangeDelAggregator range_del_agg(&icmp, |
42 | kMaxSequenceNumber /* upper_bound */); | |
11fdf7f2 | 43 | Arena arena; |
20effc67 TL |
44 | ScopedArenaIterator iter(idb->NewInternalIterator( |
45 | read_options, &arena, &range_del_agg, kMaxSequenceNumber, cfh)); | |
11fdf7f2 TL |
46 | |
47 | if (!begin_key.empty()) { | |
48 | InternalKey ikey; | |
49 | ikey.SetMinPossibleForUserKey(begin_key); | |
50 | iter->Seek(ikey.Encode()); | |
51 | } else { | |
52 | iter->SeekToFirst(); | |
53 | } | |
54 | ||
55 | size_t num_keys = 0; | |
56 | for (; iter->Valid(); iter->Next()) { | |
57 | ParsedInternalKey ikey; | |
20effc67 TL |
58 | Status pik_status = |
59 | ParseInternalKey(iter->key(), &ikey, true /* log_err_key */); // TODO | |
60 | if (!pik_status.ok()) { | |
61 | return pik_status; | |
11fdf7f2 TL |
62 | } |
63 | ||
64 | if (!end_key.empty() && | |
65 | icmp.user_comparator()->Compare(ikey.user_key, end_key) > 0) { | |
66 | break; | |
67 | } | |
68 | ||
69 | key_versions->emplace_back(ikey.user_key.ToString() /* _user_key */, | |
70 | iter->value().ToString() /* _value */, | |
71 | ikey.sequence /* _sequence */, | |
72 | static_cast<int>(ikey.type) /* _type */); | |
73 | if (++num_keys >= max_num_ikeys) { | |
74 | break; | |
75 | } | |
76 | } | |
77 | return Status::OK(); | |
78 | } | |
79 | ||
f67539c2 | 80 | } // namespace ROCKSDB_NAMESPACE |
11fdf7f2 TL |
81 | |
82 | #endif // ROCKSDB_LITE |