Fix uninitialized fields in file metadata (#4693)

Summary:
This is a quick fix for the uninitialized bugs in `LiveFileMetaData` and `SstFileMetaData` that were uncovered in #4686.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4693

Differential Revision: D13113189

Pulled By: ajkr

fbshipit-source-id: 18e798d031d2a59d0b55fc010c135e0126f4042d
main
Andrew Kryczka 6 years ago committed by Facebook Github Bot
parent 147697420a
commit 9d6d4867ab
  1. 5
      db/version_set.cc
  2. 10
      include/rocksdb/metadata.h

@ -916,6 +916,8 @@ void Version::GetColumnFamilyMetaData(ColumnFamilyMetaData* cf_meta) {
file->largest.user_key().ToString(),
file->stats.num_reads_sampled.load(std::memory_order_relaxed),
file->being_compacted});
files.back().num_entries = file->num_entries;
files.back().num_deletions = file->num_deletions;
level_size += file->fd.GetFileSize();
}
cf_meta->levels.emplace_back(
@ -4406,6 +4408,9 @@ void VersionSet::GetLiveFilesMetaData(std::vector<LiveFileMetaData>* metadata) {
filemetadata.largestkey = file->largest.user_key().ToString();
filemetadata.smallest_seqno = file->fd.smallest_seqno;
filemetadata.largest_seqno = file->fd.largest_seqno;
filemetadata.num_reads_sampled = file->stats.num_reads_sampled.load(
std::memory_order_relaxed);
filemetadata.being_compacted = file->being_compacted;
filemetadata.num_entries = file->num_entries;
filemetadata.num_deletions = file->num_deletions;
metadata->push_back(filemetadata);

@ -63,7 +63,10 @@ struct SstFileMetaData {
smallestkey(""),
largestkey(""),
num_reads_sampled(0),
being_compacted(false) {}
being_compacted(false),
num_entries(0),
num_deletions(0) {}
SstFileMetaData(const std::string& _file_name, const std::string& _path,
size_t _size, SequenceNumber _smallest_seqno,
SequenceNumber _largest_seqno,
@ -78,7 +81,9 @@ struct SstFileMetaData {
smallestkey(_smallestkey),
largestkey(_largestkey),
num_reads_sampled(_num_reads_sampled),
being_compacted(_being_compacted) {}
being_compacted(_being_compacted),
num_entries(0),
num_deletions(0) {}
// File size in bytes.
size_t size;
@ -102,5 +107,6 @@ struct SstFileMetaData {
struct LiveFileMetaData : SstFileMetaData {
std::string column_family_name; // Name of the column family
int level; // Level at which this file resides.
LiveFileMetaData() : column_family_name(), level(0) {}
};
} // namespace rocksdb

Loading…
Cancel
Save