Skip to content

Commit

Permalink
DBImpl::GetApproximateSizes(): optimize by reusing InternalKey
Browse files Browse the repository at this point in the history
  • Loading branch information
rockeet committed Aug 30, 2022
1 parent 6bed77f commit 719af44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions db/db_impl/db_impl.cc
Expand Up @@ -4140,6 +4140,7 @@ Status DBImpl::GetApproximateSizes(const SizeApproximationOptions& options,
SuperVersion* sv = GetAndRefSuperVersion(cfd);
v = sv->current;

InternalKey k1, k2;
for (int i = 0; i < n; i++) {
Slice start = range[i].start;
Slice limit = range[i].limit;
Expand All @@ -4158,8 +4159,8 @@ Status DBImpl::GetApproximateSizes(const SizeApproximationOptions& options,
}
#endif
// Convert user_key into a corresponding internal key.
InternalKey k1(start, kMaxSequenceNumber, kValueTypeForSeek);
InternalKey k2(limit, kMaxSequenceNumber, kValueTypeForSeek);
SetInternalKey(k1.rep(), start, kMaxSequenceNumber, kValueTypeForSeek);
SetInternalKey(k2.rep(), limit, kMaxSequenceNumber, kValueTypeForSeek);
sizes[i] = 0;
if (options.include_files) {
sizes[i] += versions_->ApproximateSize(
Expand Down
10 changes: 10 additions & 0 deletions db/dbformat.h
Expand Up @@ -160,6 +160,16 @@ inline void UnPackSequenceAndType(uint64_t packed, uint64_t* seq,

EntryType GetEntryType(ValueType value_type);

inline void SetInternalKey(std::string* result, Slice ukey, uint64_t seqvt) {
result->assign(ukey.data(), ukey.size());
PutFixed64(result, seqvt);
}
inline void SetInternalKey(std::string* result, Slice ukey,
SequenceNumber seq, ValueType vt) {
result->assign(ukey.data(), ukey.size());
PutFixed64(result, PackSequenceAndType(seq, vt));
}

// Append the serialization of "key" to *result.
extern void AppendInternalKey(std::string* result,
const ParsedInternalKey& key);
Expand Down

0 comments on commit 719af44

Please sign in to comment.