From fe936316781384358f01f426979cda8cb96b9456 Mon Sep 17 00:00:00 2001 From: Dhruba Borthakur Date: Wed, 29 Aug 2012 12:29:43 -0700 Subject: [PATCH] Clean up compiler warnings generated by -Wall option. Summary: Clean up compiler warnings generated by -Wall option. make clean all OPT=-Wall This is a pre-requisite before making a new release. Test Plan: compile and run unit tests Reviewers: heyongqiang Reviewed By: heyongqiang Differential Revision: https://reviews.facebook.net/D5019 --- build_detect_platform | 1 + db/db_impl.cc | 2 +- db/db_stats_logger.cc | 2 -- db/version_edit.cc | 2 +- db/version_set.cc | 24 +++++++++--------- db/version_set.h | 6 ++--- hdfs/env_hdfs.h | 37 ++++++++++++++-------------- include/leveldb/options.h | 47 ++++++++++++++++++------------------ include/leveldb/statistics.h | 1 + table/table_builder.cc | 2 +- tools/manifest_dump.cc | 2 +- tools/sst_dump.cc | 7 +++--- util/env_hdfs.cc | 6 +++-- util/options.cc | 2 +- util/stats_logger.h | 1 + 15 files changed, 73 insertions(+), 69 deletions(-) diff --git a/build_detect_platform b/build_detect_platform index b6fafab6c..c0daeb70a 100755 --- a/build_detect_platform +++ b/build_detect_platform @@ -237,4 +237,5 @@ echo "PLATFORM_CXXFLAGS=$PLATFORM_CXXFLAGS" >> $OUTPUT echo "PLATFORM_SHARED_CFLAGS=$PLATFORM_SHARED_CFLAGS" >> $OUTPUT echo "PLATFORM_SHARED_EXT=$PLATFORM_SHARED_EXT" >> $OUTPUT echo "PLATFORM_SHARED_LDFLAGS=$PLATFORM_SHARED_LDFLAGS" >> $OUTPUT +echo "PLATFORM_SHARED_VERSIONED=$PLATFORM_SHARED_VERSIONED" >> $OUTPUT echo "THRIFTSERVER=$THRIFTSERVER" >> $OUTPUT diff --git a/db/db_impl.cc b/db/db_impl.cc index b5b08ea9a..af7e51997 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -1428,7 +1428,7 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) { in.remove_prefix(strlen("num-files-at-level")); uint64_t level; bool ok = ConsumeDecimalNumber(&in, &level) && in.empty(); - if (!ok || level >= NumberLevels()) { + if (!ok || (int)level >= NumberLevels()) { return false; } else { char buf[100]; diff --git a/db/db_stats_logger.cc b/db/db_stats_logger.cc index 575d044a3..7216eef61 100644 --- a/db/db_stats_logger.cc +++ b/db/db_stats_logger.cc @@ -68,8 +68,6 @@ void DBImpl::LogDBDeployStats() { VersionSet::LevelSummaryStorage scratch; const char* file_num_summary = versions_->LevelSummary(&scratch); std::string file_num_per_level(file_num_summary); - const char* file_size_summary = versions_->LevelDataSizeSummary( - &scratch); std::string data_size_per_level(file_num_summary); mutex_.Unlock(); diff --git a/db/version_edit.cc b/db/version_edit.cc index 8143f07ce..9a52310ca 100644 --- a/db/version_edit.cc +++ b/db/version_edit.cc @@ -98,7 +98,7 @@ static bool GetInternalKey(Slice* input, InternalKey* dst) { bool VersionEdit::GetLevel(Slice* input, int* level) { uint32_t v; if (GetVarint32(input, &v) && - v < number_levels_) { + (int)v < number_levels_) { *level = v; return true; } else { diff --git a/db/version_set.cc b/db/version_set.cc index 4ec9e27b1..695dc6458 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -944,9 +944,9 @@ Status VersionSet::Recover() { prev_log_number_ = prev_log_number; Log(options_->info_log, "Recovered from manifest file:%s succeeded," - "manifest_file_number is %lld, next_file_number is %lld, " - "last_sequence is %lld, log_number is %lld," - "prev_log_number is %lld\n", + "manifest_file_number is %ld, next_file_number is %ld, " + "last_sequence is %ld, log_number is %ld," + "prev_log_number is %ld\n", current.c_str(), manifest_file_number_, next_file_number_, last_sequence_, log_number_, prev_log_number_); } @@ -1057,7 +1057,7 @@ Status VersionSet::DumpManifest(Options& options, std::string& dscname) { log_number_ = log_number; prev_log_number_ = prev_log_number; - printf("manifest_file_number %d next_file_number %d last_sequence %d log_number %d prev_log_number %d\n", + printf("manifest_file_number %ld next_file_number %ld last_sequence %ld log_number %ld prev_log_number %ld\n", manifest_file_number_, next_file_number_, last_sequence, log_number, prev_log_number); printf("%s \n", v->DebugString().c_str()); @@ -1223,7 +1223,7 @@ void VersionSet::AddLiveFiles(std::set* live) { int64_t VersionSet::NumLevelBytes(int level) const { assert(level >= 0); assert(level < NumberLevels()); - if(current_ && level < current_->files_->size()) + if(current_ && level < (int)current_->files_->size()) return TotalFileSize(current_->files_[level]); else return 0; @@ -1327,16 +1327,16 @@ double VersionSet::MaxBytesForLevel(int level) { uint64_t VersionSet::MaxFileSizeForLevel(int level) { assert(level >= 0); assert(level < NumberLevels()); - return max_file_size_[level]; + return max_file_size_[level]; } -uint64_t VersionSet::ExpandedCompactionByteSizeLimit(int level) { +int64_t VersionSet::ExpandedCompactionByteSizeLimit(int level) { uint64_t result = MaxFileSizeForLevel(level); result *= options_->expanded_compaction_factor; return result; } -uint64_t VersionSet::MaxGrandParentOverlapBytes(int level) { +int64_t VersionSet::MaxGrandParentOverlapBytes(int level) { uint64_t result = MaxFileSizeForLevel(level); result *= options_->max_grandparent_overlap_factor; return result; @@ -1417,7 +1417,7 @@ void VersionSet::SetupOtherInputs(Compaction* c) { const int64_t inputs0_size = TotalFileSize(c->inputs_[0]); const int64_t inputs1_size = TotalFileSize(c->inputs_[1]); const int64_t expanded0_size = TotalFileSize(expanded0); - uint64_t limit = ExpandedCompactionByteSizeLimit(level); + int64_t limit = ExpandedCompactionByteSizeLimit(level); if (expanded0.size() > c->inputs_[0].size() && inputs1_size + expanded0_size < limit) { InternalKey new_start, new_limit; @@ -1502,8 +1502,8 @@ Compaction::Compaction(int level, uint64_t target_file_size, : level_(level), max_output_file_size_(target_file_size), maxGrandParentOverlapBytes_(max_grandparent_overlap_bytes), - number_levels_(number_levels), input_version_(NULL), + number_levels_(number_levels), grandparent_index_(0), seen_key_(false), overlapped_bytes_(0) { @@ -1593,9 +1593,9 @@ static void InputSummary(std::vector& files, char* output, int len) { int write = 0; - for (int i = 0; i < files.size(); i++) { + for (unsigned int i = 0; i < files.size(); i++) { int sz = len - write; - int ret = snprintf(output + write, sz, "%llu(%llu) ", + int ret = snprintf(output + write, sz, "%lu(%lu) ", files.at(i)->number, files.at(i)->file_size); if (ret < 0 || ret >= sz) diff --git a/db/version_set.h b/db/version_set.h index e6bca8bf5..c5f7a314b 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -282,9 +282,9 @@ class VersionSet { uint64_t MaxFileSizeForLevel(int level); - uint64_t ExpandedCompactionByteSizeLimit(int level); + int64_t ExpandedCompactionByteSizeLimit(int level); - uint64_t MaxGrandParentOverlapBytes(int level); + int64_t MaxGrandParentOverlapBytes(int level); Env* const env_; const std::string dbname_; @@ -371,7 +371,7 @@ class Compaction { int level_; uint64_t max_output_file_size_; - uint64_t maxGrandParentOverlapBytes_; + int64_t maxGrandParentOverlapBytes_; Version* input_version_; VersionEdit* edit_; int number_levels_; diff --git a/hdfs/env_hdfs.h b/hdfs/env_hdfs.h index 4f2809871..318b131d5 100644 --- a/hdfs/env_hdfs.h +++ b/hdfs/env_hdfs.h @@ -208,6 +208,8 @@ class HdfsEnv : public Env { namespace leveldb { +static const Status notsup; + class HdfsEnv : public Env { public: @@ -224,49 +226,48 @@ class HdfsEnv : public Env { SequentialFile** result); virtual Status NewRandomAccessFile(const std::string& fname, - RandomAccessFile** result) {} + RandomAccessFile** result){ return notsup;} virtual Status NewWritableFile(const std::string& fname, - WritableFile** result){} + WritableFile** result){return notsup;} - virtual bool FileExists(const std::string& fname){} + virtual bool FileExists(const std::string& fname){return false;} virtual Status GetChildren(const std::string& path, - std::vector* result){} + std::vector* result){return notsup;} - virtual Status DeleteFile(const std::string& fname){} + virtual Status DeleteFile(const std::string& fname){return notsup;} - virtual Status CreateDir(const std::string& name){} + virtual Status CreateDir(const std::string& name){return notsup;} - virtual Status DeleteDir(const std::string& name){} + virtual Status DeleteDir(const std::string& name){return notsup;} - virtual Status GetFileSize(const std::string& fname, uint64_t* size){} + virtual Status GetFileSize(const std::string& fname, uint64_t* size){return notsup;} - virtual Status RenameFile(const std::string& src, const std::string& target){} + virtual Status RenameFile(const std::string& src, const std::string& target){return notsup;} - virtual Status LockFile(const std::string& fname, FileLock** lock){} + virtual Status LockFile(const std::string& fname, FileLock** lock){return notsup;} - virtual Status UnlockFile(FileLock* lock){} + virtual Status UnlockFile(FileLock* lock){return notsup;} - virtual Status NewLogger(const std::string& fname, Logger** result){} + virtual Status NewLogger(const std::string& fname, Logger** result){return notsup;} virtual void Schedule( void (*function)(void* arg), void* arg) {} virtual void StartThread(void (*function)(void* arg), void* arg) {} - virtual Status GetTestDirectory(std::string* path) {} + virtual Status GetTestDirectory(std::string* path) {return notsup;} - virtual uint64_t NowMicros() {} + virtual uint64_t NowMicros() {return 0;} virtual void SleepForMicroseconds(int micros) {} - virtual Status GetHostName(char* name, uint len) {} + virtual Status GetHostName(char* name, uint len) {return notsup;} - virtual Status GetCurrentTime(int64_t* unix_time) {} + virtual Status GetCurrentTime(int64_t* unix_time) {return notsup;} virtual Status GetAbsolutePath(const std::string& db_path, - std::string* outputpath) {} - + std::string* outputpath) {return notsup;} }; } diff --git a/include/leveldb/options.h b/include/leveldb/options.h index 6fa9f7068..1cf076e52 100644 --- a/include/leveldb/options.h +++ b/include/leveldb/options.h @@ -115,6 +115,30 @@ struct Options { // Default: 16 int block_restart_interval; + + // Compress blocks using the specified compression algorithm. This + // parameter can be changed dynamically. + // + // Default: kSnappyCompression, which gives lightweight but fast + // compression. + // + // Typical speeds of kSnappyCompression on an Intel(R) Core(TM)2 2.4GHz: + // ~200-500MB/s compression + // ~400-800MB/s decompression + // Note that these speeds are significantly faster than most + // persistent storage speeds, and therefore it is typically never + // worth switching to kNoCompression. Even if the input data is + // incompressible, the kSnappyCompression implementation will + // efficiently detect that and will switch to uncompressed mode. + CompressionType compression; + + // If non-NULL, use the specified filter policy to reduce disk reads. + // Many applications will benefit from passing the result of + // NewBloomFilterPolicy() here. + // + // Default: NULL + const FilterPolicy* filter_policy; + // Number of levels for this database int num_levels; @@ -164,29 +188,6 @@ struct Options { // stop building a single file in a level->level+1 compaction. int max_grandparent_overlap_factor; - // Compress blocks using the specified compression algorithm. This - // parameter can be changed dynamically. - // - // Default: kSnappyCompression, which gives lightweight but fast - // compression. - // - // Typical speeds of kSnappyCompression on an Intel(R) Core(TM)2 2.4GHz: - // ~200-500MB/s compression - // ~400-800MB/s decompression - // Note that these speeds are significantly faster than most - // persistent storage speeds, and therefore it is typically never - // worth switching to kNoCompression. Even if the input data is - // incompressible, the kSnappyCompression implementation will - // efficiently detect that and will switch to uncompressed mode. - CompressionType compression; - - // If non-NULL, use the specified filter policy to reduce disk reads. - // Many applications will benefit from passing the result of - // NewBloomFilterPolicy() here. - // - // Default: NULL - const FilterPolicy* filter_policy; - // If non-null, then we should collect metrics about database operations Statistics* statistics; diff --git a/include/leveldb/statistics.h b/include/leveldb/statistics.h index 4684f88ef..3286daa32 100644 --- a/include/leveldb/statistics.h +++ b/include/leveldb/statistics.h @@ -21,6 +21,7 @@ class Statistics { virtual long getNumFileOpens() { return numFileOpens_;} virtual long getNumFileCloses() { return numFileCloses_;} virtual long getNumFileErrors() { return numFileErrors_;} + virtual ~Statistics() {} protected: long numFileOpens_; diff --git a/table/table_builder.cc b/table/table_builder.cc index 2074c8bb0..eabdedead 100644 --- a/table/table_builder.cc +++ b/table/table_builder.cc @@ -136,7 +136,7 @@ void TableBuilder::Flush() { } } -static bool GoodCompressionRatio(int compressed_size, int raw_size) { +static bool GoodCompressionRatio(size_t compressed_size, size_t raw_size) { // Check to see if compressed less than 12.5% return compressed_size < raw_size - (raw_size / 8u); } diff --git a/tools/manifest_dump.cc b/tools/manifest_dump.cc index 58f206fe9..3268f1053 100644 --- a/tools/manifest_dump.cc +++ b/tools/manifest_dump.cc @@ -28,7 +28,7 @@ using namespace leveldb; int main(int argc, char** argv) { // parse command line options - int n; + size_t n; char junk; int foundfile = 0; std::string manifestfile; diff --git a/tools/sst_dump.cc b/tools/sst_dump.cc index 3a8060008..374377eff 100644 --- a/tools/sst_dump.cc +++ b/tools/sst_dump.cc @@ -54,8 +54,7 @@ Status SstFileReader::ReadSequential(bool print_kv, uint64_t read_num) } Iterator* iter = table->NewIterator(ReadOptions(verify_checksum_, false)); - long i = 0; - int64_t bytes = 0; + uint64_t i = 0; for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { Slice key = iter->key(); Slice value = iter->value(); @@ -125,8 +124,8 @@ int main(int argc, char** argv) { dir = false; } - int total_read = 0; - for (int i = 0; i < filenames.size(); i++) { + uint64_t total_read = 0; + for (size_t i = 0; i < filenames.size(); i++) { std::string filename = filenames.at(i); if (filename.length() <= 4 || filename.rfind(".sst") != filename.length() - 4) { diff --git a/util/env_hdfs.cc b/util/env_hdfs.cc index 500e343d1..901f1fc96 100644 --- a/util/env_hdfs.cc +++ b/util/env_hdfs.cc @@ -492,8 +492,10 @@ Status HdfsEnv::NewLogger(const std::string& fname, Logger** result) { #include "leveldb/env.h" #include "hdfs/env_hdfs.h" namespace leveldb { -Status HdfsEnv::NewSequentialFile(const std::string& fname, - SequentialFile** result) {} + Status HdfsEnv::NewSequentialFile(const std::string& fname, + SequentialFile** result) { + return Status::NotSupported("Not compiled with hdfs support"); + } } #endif diff --git a/util/options.cc b/util/options.cc index d05c5e0e3..51eb6c85f 100644 --- a/util/options.cc +++ b/util/options.cc @@ -23,6 +23,7 @@ Options::Options() block_size(4096), block_restart_interval(16), compression(kSnappyCompression), + filter_policy(NULL), num_levels(7), level0_file_num_compaction_trigger(4), level0_slowdown_writes_trigger(8), @@ -34,7 +35,6 @@ Options::Options() max_bytes_for_level_multiplier(10), expanded_compaction_factor(25), max_grandparent_overlap_factor(10), - filter_policy(NULL), statistics(NULL), disableDataSync(false), use_fsync(false), diff --git a/util/stats_logger.h b/util/stats_logger.h index a14362c78..a0799730f 100644 --- a/util/stats_logger.h +++ b/util/stats_logger.h @@ -15,6 +15,7 @@ class StatsLogger { const std::string& data_size_per_level, const std::string& file_number_per_level, const int64_t& ts_unix) = 0; + virtual ~StatsLogger() {} };