From 9d6d4867ab4bcfca9cca750d6da4e3c6e3111816 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Fri, 16 Nov 2018 20:34:27 -0800 Subject: [PATCH] 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 --- db/version_set.cc | 5 +++++ include/rocksdb/metadata.h | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/db/version_set.cc b/db/version_set.cc index 1850a2b99..0e9fa0af1 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -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* 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); diff --git a/include/rocksdb/metadata.h b/include/rocksdb/metadata.h index 097d2fde9..e62d4f409 100644 --- a/include/rocksdb/metadata.h +++ b/include/rocksdb/metadata.h @@ -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