From 8477255da3b3775742815d15141d18a26fe1a030 Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Fri, 24 Jan 2014 16:15:05 -0800 Subject: [PATCH 1/2] Moving Some includes from options.h to forward declaration Summary: By removing some includes form options.h and reply on forward declaration, we can more easily reason the dependencies. Test Plan: make all check Reviewers: kailiu, haobo, igor, dhruba Reviewed By: kailiu CC: leveldb Differential Revision: https://reviews.facebook.net/D15411 --- db/compaction_picker.cc | 2 ++ db/db_bench.cc | 2 ++ db/db_test.cc | 2 ++ db/prefix_filter_iterator.h | 2 ++ db/skiplist.h | 1 + db/tailing_iter.cc | 2 ++ include/rocksdb/memtablerep.h | 7 ++++--- include/rocksdb/options.h | 10 +++++----- include/rocksdb/universal_compaction.h | 6 ------ tools/db_stress.cc | 2 ++ util/coding.cc | 4 ++++ util/coding.h | 2 ++ util/options.cc | 4 ++++ utilities/backupable/backupable_db.cc | 1 + 14 files changed, 33 insertions(+), 14 deletions(-) diff --git a/db/compaction_picker.cc b/db/compaction_picker.cc index 284942117..9582b6a29 100644 --- a/db/compaction_picker.cc +++ b/db/compaction_picker.cc @@ -8,6 +8,8 @@ // found in the LICENSE file. See the AUTHORS file for names of contributors. #include "db/compaction_picker.h" + +#include #include "util/statistics.h" namespace rocksdb { diff --git a/db/db_bench.cc b/db/db_bench.cc index e41a31cf3..18258fbb6 100644 --- a/db/db_bench.cc +++ b/db/db_bench.cc @@ -21,6 +21,8 @@ #include "rocksdb/env.h" #include "rocksdb/memtablerep.h" #include "rocksdb/write_batch.h" +#include "rocksdb/slice.h" +#include "rocksdb/slice_transform.h" #include "rocksdb/statistics.h" #include "port/port.h" #include "util/bit_set.h" diff --git a/db/db_test.cc b/db/db_test.cc index 8828ed1b9..baa6e7489 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -21,6 +21,8 @@ #include "rocksdb/cache.h" #include "rocksdb/compaction_filter.h" #include "rocksdb/env.h" +#include "rocksdb/slice.h" +#include "rocksdb/slice_transform.h" #include "rocksdb/table.h" #include "util/hash.h" #include "util/logging.h" diff --git a/db/prefix_filter_iterator.h b/db/prefix_filter_iterator.h index f4488379c..e868c7a54 100644 --- a/db/prefix_filter_iterator.h +++ b/db/prefix_filter_iterator.h @@ -12,6 +12,8 @@ #pragma once #include "rocksdb/iterator.h" +#include "rocksdb/slice.h" +#include "rocksdb/slice_transform.h" namespace rocksdb { diff --git a/db/skiplist.h b/db/skiplist.h index 06a35d911..2c9c4a6de 100644 --- a/db/skiplist.h +++ b/db/skiplist.h @@ -35,6 +35,7 @@ #include #include "port/port.h" #include "util/random.h" +#include "rocksdb/arena.h" namespace rocksdb { diff --git a/db/tailing_iter.cc b/db/tailing_iter.cc index f448ac15d..5644b1211 100644 --- a/db/tailing_iter.cc +++ b/db/tailing_iter.cc @@ -8,6 +8,8 @@ #include #include #include "db/db_impl.h" +#include "rocksdb/slice.h" +#include "rocksdb/slice_transform.h" namespace rocksdb { diff --git a/include/rocksdb/memtablerep.h b/include/rocksdb/memtablerep.h index 2fca8d161..9e24942ac 100644 --- a/include/rocksdb/memtablerep.h +++ b/include/rocksdb/memtablerep.h @@ -37,12 +37,13 @@ #define STORAGE_ROCKSDB_DB_MEMTABLEREP_H_ #include -#include "rocksdb/arena.h" -#include "rocksdb/slice.h" -#include "rocksdb/slice_transform.h" namespace rocksdb { +class Arena; +class Slice; +class SliceTransform; + class MemTableRep { public: // KeyComparator provides a means to compare keys, which are internal keys diff --git a/include/rocksdb/options.h b/include/rocksdb/options.h index 96eadcd5a..da6412aa2 100644 --- a/include/rocksdb/options.h +++ b/include/rocksdb/options.h @@ -15,11 +15,6 @@ #include #include -#include "rocksdb/memtablerep.h" -#include "rocksdb/slice.h" -#include "rocksdb/slice_transform.h" -#include "rocksdb/statistics.h" -#include "rocksdb/table_properties.h" #include "rocksdb/universal_compaction.h" namespace rocksdb { @@ -34,6 +29,11 @@ class Logger; class MergeOperator; class Snapshot; class TableFactory; +class MemTableRepFactory; +class TablePropertiesCollector; +class Slice; +class SliceTransform; +class Statistics; using std::shared_ptr; diff --git a/include/rocksdb/universal_compaction.h b/include/rocksdb/universal_compaction.h index ec862b95f..eaf47e5c7 100644 --- a/include/rocksdb/universal_compaction.h +++ b/include/rocksdb/universal_compaction.h @@ -6,14 +6,8 @@ #ifndef STORAGE_ROCKSDB_UNIVERSAL_COMPACTION_OPTIONS_H #define STORAGE_ROCKSDB_UNIVERSAL_COMPACTION_OPTIONS_H -#include -#include -#include -#include #include #include -#include "rocksdb/slice.h" -#include "rocksdb/statistics.h" namespace rocksdb { diff --git a/tools/db_stress.cc b/tools/db_stress.cc index 8321c7eaf..bad2cf0d6 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -31,6 +31,8 @@ #include "utilities/utility_db.h" #include "rocksdb/env.h" #include "rocksdb/write_batch.h" +#include "rocksdb/slice.h" +#include "rocksdb/slice_transform.h" #include "rocksdb/statistics.h" #include "port/port.h" #include "util/coding.h" diff --git a/util/coding.cc b/util/coding.cc index ce67fa486..6cf67efad 100644 --- a/util/coding.cc +++ b/util/coding.cc @@ -9,6 +9,10 @@ #include "util/coding.h" +#include "rocksdb/slice.h" +#include "rocksdb/slice_transform.h" + + #include namespace rocksdb { diff --git a/util/coding.h b/util/coding.h index 4477dc799..c6a6b203d 100644 --- a/util/coding.h +++ b/util/coding.h @@ -16,6 +16,8 @@ #include #include #include + +#include "rocksdb/write_batch.h" #include "port/port.h" namespace rocksdb { diff --git a/util/options.cc b/util/options.cc index 64cabc8ca..671f3d681 100644 --- a/util/options.cc +++ b/util/options.cc @@ -17,6 +17,10 @@ #include "rocksdb/env.h" #include "rocksdb/filter_policy.h" #include "rocksdb/merge_operator.h" +#include "rocksdb/memtablerep.h" +#include "rocksdb/slice.h" +#include "rocksdb/slice_transform.h" +#include "rocksdb/table_properties.h" #include "table/block_based_table_factory.h" namespace rocksdb { diff --git a/utilities/backupable/backupable_db.cc b/utilities/backupable/backupable_db.cc index 26bdd254b..8e5ef5220 100644 --- a/utilities/backupable/backupable_db.cc +++ b/utilities/backupable/backupable_db.cc @@ -21,6 +21,7 @@ #include #include #include +#include namespace rocksdb { From 04afa32134e88fdb17e9521d3b0e015c777ea4c5 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Fri, 24 Jan 2014 18:30:00 -0800 Subject: [PATCH 2/2] Fix reduce levels ReduceNumberOfLevels had segmentation fault in WriteSnapshot() since we didn't change the number of levels in VersionSet (we consider them immutable from now on). This fixes the problem. --- db/version_set.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/version_set.cc b/db/version_set.cc index e03d115d7..db5f9151a 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -1779,8 +1779,11 @@ Status VersionSet::ReduceNumberOfLevels(const std::string& dbname, } std::vector* old_files_list = current_version->files_; + // we need to allocate an array with the old number of levels size to + // avoid SIGSEGV in WriteSnapshot() + // however, all levels bigger or equal to new_levels will be empty std::vector* new_files_list = - new std::vector[new_levels]; + new std::vector[current_levels]; for (int i = 0; i < new_levels - 1; i++) { new_files_list[i] = old_files_list[i]; }