diff --git a/db/c.cc b/db/c.cc index 318b92f2e..c2b0550a7 100644 --- a/db/c.cc +++ b/db/c.cc @@ -2256,7 +2256,7 @@ void rocksdb_env_set_high_priority_background_threads(rocksdb_env_t* env, int n) } void rocksdb_env_join_all_threads(rocksdb_env_t* env) { - env->rep->WaitForJoin(); + env->rep->WaitForJoin(); } void rocksdb_env_destroy(rocksdb_env_t* env) { @@ -2449,19 +2449,16 @@ extern void rocksdb_livefiles_destroy( delete lf; } -void rocksdb_get_options_from_string( - const rocksdb_options_t* base_options, - const char* opts_str, rocksdb_options_t* new_options, - char** errptr){ - SaveError(errptr, - GetOptionsFromString(base_options->rep, - std::string(opts_str), &new_options->rep)); +void rocksdb_get_options_from_string(const rocksdb_options_t* base_options, + const char* opts_str, + rocksdb_options_t* new_options, + char** errptr) { + SaveError(errptr, + GetOptionsFromString(base_options->rep, std::string(opts_str), + &new_options->rep)); } -void rocksdb_free( - void* ptr){ - free(ptr); -} +void rocksdb_free(void* ptr) { free(ptr); } } // end extern "C" diff --git a/db/compaction.cc b/db/compaction.cc index 93a4658cc..7824a86bc 100644 --- a/db/compaction.cc +++ b/db/compaction.cc @@ -270,7 +270,8 @@ const char* Compaction::InputLevelSummary( is_first = false; } len += snprintf(scratch->buffer + len, sizeof(scratch->buffer) - len, - "%" ROCKSDB_PRIszt "@%d", input_level.size(), input_level.level); + "%" ROCKSDB_PRIszt "@%d", input_level.size(), + input_level.level); } snprintf(scratch->buffer + len, sizeof(scratch->buffer) - len, " files to L%d", output_level()); diff --git a/db/compaction.h b/db/compaction.h index 64cd3565a..765c99ee0 100644 --- a/db/compaction.h +++ b/db/compaction.h @@ -122,9 +122,7 @@ class Compaction { bool IsTrivialMove() const; // If true, then the compaction can be done by simply deleting input files. - bool deletion_compaction() const { - return deletion_compaction_; - } + bool deletion_compaction() const { return deletion_compaction_; } // Add all inputs to this compaction as delete operations to *edit. void AddInputDeletions(VersionEdit* edit); diff --git a/db/compaction_job.cc b/db/compaction_job.cc index ac07851f2..944b38592 100644 --- a/db/compaction_job.cc +++ b/db/compaction_job.cc @@ -242,7 +242,7 @@ void CompactionJob::ReportStartedCompaction( ThreadStatusUtil::SetThreadOperationProperty( ThreadStatus::COMPACTION_PROP_FLAGS, - compaction->is_manual_compaction() + + compaction->is_manual_compaction() + (compaction->deletion_compaction() << 1)); ThreadStatusUtil::SetThreadOperationProperty( @@ -263,7 +263,7 @@ void CompactionJob::ReportStartedCompaction( if (compaction_job_stats_) { compaction_job_stats_->is_manual_compaction = - compaction->is_manual_compaction(); + compaction->is_manual_compaction(); } } diff --git a/db/compaction_job_stats_test.cc b/db/compaction_job_stats_test.cc index a78155e32..29e415787 100644 --- a/db/compaction_job_stats_test.cc +++ b/db/compaction_job_stats_test.cc @@ -777,7 +777,5 @@ int main(int argc, char** argv) { #else -int main(int argc, char** argv) { - return 0; -} +int main(int argc, char** argv) { return 0; } #endif // !defined(IOS_CROSS_COMPILE) diff --git a/db/compaction_job_test.cc b/db/compaction_job_test.cc index 63507d94a..1cabee24b 100644 --- a/db/compaction_job_test.cc +++ b/db/compaction_job_test.cc @@ -165,10 +165,9 @@ void VerifyInitializationOfCompactionJobStats( #endif // !defined(IOS_CROSS_COMPILE) } -void VerifyCompactionJobStats( - const CompactionJobStats& compaction_job_stats, - const std::vector& files, - size_t num_output_files) { +void VerifyCompactionJobStats(const CompactionJobStats& compaction_job_stats, + const std::vector& files, + size_t num_output_files) { ASSERT_GE(compaction_job_stats.elapsed_micros, 0U); ASSERT_EQ(compaction_job_stats.num_input_files, files.size()); ASSERT_EQ(compaction_job_stats.num_output_files, num_output_files); @@ -219,9 +218,7 @@ TEST_F(CompactionJobTest, Simple) { ASSERT_OK(s); mutex_.Unlock(); - VerifyCompactionJobStats( - compaction_job_stats, - files, 1); + VerifyCompactionJobStats(compaction_job_stats, files, 1); mock_table_factory_->AssertLatestFile(expected_results); ASSERT_EQ(yield_callback_called, 20000); diff --git a/db/compaction_picker.cc b/db/compaction_picker.cc index 8d271d1d0..26dbb82d4 100644 --- a/db/compaction_picker.cc +++ b/db/compaction_picker.cc @@ -401,8 +401,9 @@ bool CompactionPicker::SetupOtherInputs( if (expanded1.size() == output_level_inputs->size() && !FilesInCompaction(expanded1)) { Log(InfoLogLevel::INFO_LEVEL, ioptions_.info_log, - "[%s] Expanding@%d %" ROCKSDB_PRIszt "+%" ROCKSDB_PRIszt "(%" PRIu64 "+%" PRIu64 - " bytes) to %" ROCKSDB_PRIszt "+%" ROCKSDB_PRIszt " (%" PRIu64 "+%" PRIu64 "bytes)\n", + "[%s] Expanding@%d %" ROCKSDB_PRIszt "+%" ROCKSDB_PRIszt "(%" PRIu64 + "+%" PRIu64 " bytes) to %" ROCKSDB_PRIszt "+%" ROCKSDB_PRIszt + " (%" PRIu64 "+%" PRIu64 "bytes)\n", cf_name.c_str(), input_level, inputs->size(), output_level_inputs->size(), inputs0_size, inputs1_size, expanded0.size(), expanded1.size(), expanded0_size, inputs1_size); @@ -1225,7 +1226,8 @@ Compaction* UniversalCompactionPicker::PickCompaction( return nullptr; } VersionStorageInfo::LevelSummaryStorage tmp; - LogToBuffer(log_buffer, 3072, "[%s] Universal: sorted runs files(%" ROCKSDB_PRIszt "): %s\n", + LogToBuffer(log_buffer, 3072, + "[%s] Universal: sorted runs files(%" ROCKSDB_PRIszt "): %s\n", cf_name.c_str(), sorted_runs.size(), vstorage->LevelSummary(&tmp)); diff --git a/db/db_bench.cc b/db/db_bench.cc index 3da652510..0b1e65fc4 100644 --- a/db/db_bench.cc +++ b/db/db_bench.cc @@ -71,7 +71,7 @@ int main() { #include "utilities/merge_operators.h" #ifdef OS_WIN -#include // open/close +#include // open/close #endif using GFLAGS::ParseCommandLineFlags; @@ -3544,8 +3544,8 @@ class Benchmark { char msg[100]; snprintf(msg, sizeof(msg), - "(reads:%" PRIu64 " merges:%" PRIu64 " total:%" PRIu64 " hits:%" \ - PRIu64 " maxlength:%" ROCKSDB_PRIszt ")", + "(reads:%" PRIu64 " merges:%" PRIu64 " total:%" PRIu64 + " hits:%" PRIu64 " maxlength:%" ROCKSDB_PRIszt ")", num_gets, num_merges, readwrites_, num_hits, max_length); thread->stats.AddMessage(msg); } diff --git a/db/db_impl.cc b/db/db_impl.cc index 32487dcf9..ff679c69a 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -1631,9 +1631,9 @@ Status DBImpl::CompactFilesImpl( CompactionJob compaction_job( job_context->job_id, c.get(), db_options_, env_options_, versions_.get(), &shutting_down_, log_buffer, directories_.GetDbDir(), - directories_.GetDataDir(c->output_path_id()), stats_, - snapshots_.GetAll(), table_cache_, std::move(yield_callback), - &event_logger_, c->mutable_cf_options()->paranoid_file_checks, dbname_, + directories_.GetDataDir(c->output_path_id()), stats_, snapshots_.GetAll(), + table_cache_, std::move(yield_callback), &event_logger_, + c->mutable_cf_options()->paranoid_file_checks, dbname_, nullptr); // Here we pass a nullptr for CompactionJobStats because // CompactFiles does not trigger OnCompactionCompleted(), // which is the only place where CompactionJobStats is @@ -2602,8 +2602,8 @@ Status DBImpl::BackgroundCompaction(bool* madeProgress, JobContext* job_context, versions_.get(), &shutting_down_, log_buffer, directories_.GetDbDir(), directories_.GetDataDir(c->output_path_id()), stats_, snapshots_.GetAll(), table_cache_, std::move(yield_callback), - &event_logger_, c->mutable_cf_options()->paranoid_file_checks, - dbname_, &compaction_job_stats); + &event_logger_, c->mutable_cf_options()->paranoid_file_checks, dbname_, + &compaction_job_stats); compaction_job.Prepare(); mutex_.Unlock(); diff --git a/db/db_test.cc b/db/db_test.cc index 0616a81e2..37a619220 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -7,20 +7,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. See the AUTHORS file for names of contributors. -// Introduction of SyncPoint effectively disabled building and running this test in Release build. +// Introduction of SyncPoint effectively disabled building and running this test +// in Release build. // which is a pity, it is a good test -#if !(defined NDEBUG) || !defined (OS_WIN) +#if !(defined NDEBUG) || !defined(OS_WIN) #include #include #include -#ifndef OS_WIN -# include -#endif #include #include #include #include +#ifndef OS_WIN +#include +#endif #include "db/filename.h" #include "db/dbformat.h" @@ -8590,7 +8591,7 @@ TEST_F(DBTest, TransactionLogIterator) { } while (ChangeCompactOptions()); } -#ifndef NDEBUG // sync point is not included with DNDEBUG build +#ifndef NDEBUG // sync point is not included with DNDEBUG build TEST_F(DBTest, TransactionLogIteratorRace) { static const int LOG_ITERATOR_RACE_TEST_COUNT = 2; static const char* sync_points[LOG_ITERATOR_RACE_TEST_COUNT][4] = { @@ -8716,7 +8717,6 @@ TEST_F(DBTest, TransactionLogIteratorCorruptedLog) { // class RecoveryTestHelper { public: - // Number of WAL files to generate static const int kWALFilesCount = 10; // Starting number for the WAL file name like 00010.log @@ -8727,9 +8727,9 @@ class RecoveryTestHelper { static const int kValueSize = 10; // Create WAL files with values filled in - static void FillData(DBTest* test, Options& options, - const size_t wal_count, size_t & count) { - DBOptions & db_options = options; + static void FillData(DBTest* test, Options& options, const size_t wal_count, + size_t& count) { + DBOptions& db_options = options; count = 0; @@ -8750,7 +8750,7 @@ class RecoveryTestHelper { std::unique_ptr current_log_writer; for (size_t j = kWALFileOffset; j < wal_count + kWALFileOffset; j++) { - uint64_t current_log_number = j; + uint64_t current_log_number = j; std::string fname = LogFileName(test->dbname_, current_log_number); unique_ptr file; ASSERT_OK(db_options.env->NewWritableFile(fname, &file, env_options)); @@ -8760,7 +8760,7 @@ class RecoveryTestHelper { std::string key = "key" + ToString(count++); std::string value = test->DummyString(kValueSize); assert(current_log_writer.get() != nullptr); - uint64_t seq = versions->LastSequence() + 1; + uint64_t seq = versions->LastSequence() + 1; WriteBatch batch; batch.Put(key, value); WriteBatchInternal::SetSequence(&batch, seq); @@ -8793,9 +8793,9 @@ class RecoveryTestHelper { } // Manuall corrupt the specified WAL - static void CorruptWAL(DBTest * test, Options& options, - const double off, const double len, - const int wal_file_id, const bool trunc = false) { + static void CorruptWAL(DBTest* test, Options& options, const double off, + const double len, const int wal_file_id, + const bool trunc = false) { Env* env = options.env; std::string fname = LogFileName(test->dbname_, wal_file_id); uint64_t size; @@ -8839,18 +8839,18 @@ class RecoveryTestHelper { // at the end of any of the logs // - We do not expect to open the data store for corruption TEST_F(DBTest, kTolerateCorruptedTailRecords) { - const int jstart = RecoveryTestHelper::kWALFileOffset; - const int jend = jstart + RecoveryTestHelper::kWALFilesCount; + const int jstart = RecoveryTestHelper::kWALFileOffset; + const int jend = jstart + RecoveryTestHelper::kWALFilesCount; - for (auto trunc : {true, false}) { /* Corruption style */ - for (int i = 0; i < 4; i++) { /* Corruption offset position */ + for (auto trunc : {true, false}) { /* Corruption style */ + for (int i = 0; i < 4; i++) { /* Corruption offset position */ for (int j = jstart; j < jend; j++) { /* WAL file */ // Fill data for testing Options options = CurrentOptions(); const size_t row_count = RecoveryTestHelper::FillData(this, options); // test checksum failure or parsing - RecoveryTestHelper::CorruptWAL(this, options, /*off=*/ i * .3, - /*len%=*/ .1, /*wal=*/ j, trunc); + RecoveryTestHelper::CorruptWAL(this, options, /*off=*/i * .3, + /*len%=*/.1, /*wal=*/j, trunc); if (trunc) { options.wal_recovery_mode = @@ -8874,8 +8874,8 @@ TEST_F(DBTest, kTolerateCorruptedTailRecords) { // We don't expect the data store to be opened if there is any corruption // (leading, middle or trailing -- incomplete writes or corruption) TEST_F(DBTest, kAbsoluteConsistency) { - const int jstart = RecoveryTestHelper::kWALFileOffset; - const int jend = jstart + RecoveryTestHelper::kWALFilesCount; + const int jstart = RecoveryTestHelper::kWALFileOffset; + const int jend = jstart + RecoveryTestHelper::kWALFilesCount; // Verify clean slate behavior Options options = CurrentOptions(); @@ -8886,7 +8886,7 @@ TEST_F(DBTest, kAbsoluteConsistency) { ASSERT_EQ(RecoveryTestHelper::GetData(this), row_count); for (auto trunc : {true, false}) { /* Corruption style */ - for (int i = 0; i < 4; i++) { /* Corruption offset position */ + for (int i = 0; i < 4; i++) { /* Corruption offset position */ if (trunc && i == 0) { continue; } @@ -8895,7 +8895,7 @@ TEST_F(DBTest, kAbsoluteConsistency) { // fill with new date RecoveryTestHelper::FillData(this, options); // corrupt the wal - RecoveryTestHelper::CorruptWAL(this, options, /*off=*/ i * .3, + RecoveryTestHelper::CorruptWAL(this, options, /*off=*/i * .3, /*len%=*/.1, j, trunc); // verify options.wal_recovery_mode = WALRecoveryMode::kAbsoluteConsistency; @@ -8910,20 +8910,20 @@ TEST_F(DBTest, kAbsoluteConsistency) { // - We expect to open data store under all circumstances // - We expect only data upto the point where the first error was encountered TEST_F(DBTest, kPointInTimeRecovery) { - const int jstart = RecoveryTestHelper::kWALFileOffset; + const int jstart = RecoveryTestHelper::kWALFileOffset; const int jend = jstart + RecoveryTestHelper::kWALFilesCount; - const int maxkeys = RecoveryTestHelper::kWALFilesCount * - RecoveryTestHelper::kKeysPerWALFile; + const int maxkeys = + RecoveryTestHelper::kWALFilesCount * RecoveryTestHelper::kKeysPerWALFile; - for (auto trunc : {true, false}) { /* Corruption style */ - for (int i = 0; i < 4; i++) { /* Offset of corruption */ + for (auto trunc : {true, false}) { /* Corruption style */ + for (int i = 0; i < 4; i++) { /* Offset of corruption */ for (int j = jstart; j < jend; j++) { /* WAL file */ // Fill data for testing Options options = CurrentOptions(); const size_t row_count = RecoveryTestHelper::FillData(this, options); // Corrupt the wal - RecoveryTestHelper::CorruptWAL(this, options, /*off=*/ i * .3, + RecoveryTestHelper::CorruptWAL(this, options, /*off=*/i * .3, /*len%=*/.1, j, trunc); // Verify @@ -8945,11 +8945,11 @@ TEST_F(DBTest, kPointInTimeRecovery) { } const size_t min = RecoveryTestHelper::kKeysPerWALFile * - (j - RecoveryTestHelper::kWALFileOffset); + (j - RecoveryTestHelper::kWALFileOffset); ASSERT_GE(recovered_row_count, min); if (!trunc && i != 0) { const size_t max = RecoveryTestHelper::kKeysPerWALFile * - (j - RecoveryTestHelper::kWALFileOffset + 1); + (j - RecoveryTestHelper::kWALFileOffset + 1); ASSERT_LE(recovered_row_count, max); } } @@ -8961,18 +8961,18 @@ TEST_F(DBTest, kPointInTimeRecovery) { // - We expect to open the data store under all scenarios // - We expect to have recovered records past the corruption zone TEST_F(DBTest, kSkipAnyCorruptedRecords) { - const int jstart = RecoveryTestHelper::kWALFileOffset; - const int jend = jstart + RecoveryTestHelper::kWALFilesCount; + const int jstart = RecoveryTestHelper::kWALFileOffset; + const int jend = jstart + RecoveryTestHelper::kWALFilesCount; - for (auto trunc : {true, false}) { /* Corruption style */ - for (int i = 0; i < 4; i++) { /* Corruption offset */ + for (auto trunc : {true, false}) { /* Corruption style */ + for (int i = 0; i < 4; i++) { /* Corruption offset */ for (int j = jstart; j < jend; j++) { /* wal files */ // Fill data for testing Options options = CurrentOptions(); const size_t row_count = RecoveryTestHelper::FillData(this, options); // Corrupt the WAL - RecoveryTestHelper::CorruptWAL(this, options, /*off=*/ i * .3, + RecoveryTestHelper::CorruptWAL(this, options, /*off=*/i * .3, /*len%=*/.1, j, trunc); // Verify behavior @@ -11228,8 +11228,8 @@ TEST_F(DBTest, DynamicMemtableOptions) { count++; } ASSERT_GT(sleep_count.load(), 0); - // Windows fails this test. Will tune in the future and figure out - // approp number +// Windows fails this test. Will tune in the future and figure out +// approp number #ifndef OS_WIN ASSERT_GT(static_cast(count), 512 * 0.8); ASSERT_LT(static_cast(count), 512 * 1.2); @@ -11254,8 +11254,8 @@ TEST_F(DBTest, DynamicMemtableOptions) { count++; } ASSERT_GT(sleep_count.load(), 0); - // Windows fails this test. Will tune in the future and figure out - // approp number +// Windows fails this test. Will tune in the future and figure out +// approp number #ifndef OS_WIN ASSERT_GT(static_cast(count), 256 * 0.8); ASSERT_LT(static_cast(count), 266 * 1.2); diff --git a/db/listener_test.cc b/db/listener_test.cc index 069349a7a..cc7c4547c 100644 --- a/db/listener_test.cc +++ b/db/listener_test.cc @@ -216,11 +216,8 @@ TEST_F(EventListenerTest, OnSingleDBCompactionTest) { // This simple Listener can only handle one flush at a time. class TestFlushListener : public EventListener { public: - explicit TestFlushListener(Env* env) : - slowdown_count(0), - stop_count(0), - db_closed(), - env_(env) { + explicit TestFlushListener(Env* env) + : slowdown_count(0), stop_count(0), db_closed(), env_(env) { db_closed = false; } void OnTableFileCreated( diff --git a/db/transaction_log_impl.h b/db/transaction_log_impl.h index b5cd9554a..c730d0f61 100644 --- a/db/transaction_log_impl.h +++ b/db/transaction_log_impl.h @@ -90,7 +90,8 @@ class TransactionLogIteratorImpl : public TransactionLogIterator { Env* env; Logger* info_log; virtual void Corruption(size_t bytes, const Status& s) override { - Log(InfoLogLevel::ERROR_LEVEL, info_log, "dropping %" ROCKSDB_PRIszt " bytes; %s", bytes, + Log(InfoLogLevel::ERROR_LEVEL, info_log, + "dropping %" ROCKSDB_PRIszt " bytes; %s", bytes, s.ToString().c_str()); } virtual void Info(const char* s) { diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index 42641c3ea..cf6f9d87b 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -47,17 +47,17 @@ #pragma once #ifdef OS_WIN -# ifdef ROCKSDB_DLL -# ifdef ROCKSDB_LIBRARY_EXPORTS -# define ROCKSDB_LIBRARY_API __declspec(dllexport) -# else -# define ROCKSDB_LIBRARY_API __declspec(dllimport) -# endif -# else -# define ROCKSDB_LIBRARY_API -# endif +#ifdef ROCKSDB_DLL +#ifdef ROCKSDB_LIBRARY_EXPORTS +#define ROCKSDB_LIBRARY_API __declspec(dllexport) #else -# define ROCKSDB_LIBRARY_API +#define ROCKSDB_LIBRARY_API __declspec(dllimport) +#endif +#else +#define ROCKSDB_LIBRARY_API +#endif +#else +#define ROCKSDB_LIBRARY_API #endif #ifdef __cplusplus @@ -113,173 +113,132 @@ typedef struct rocksdb_column_family_handle_t rocksdb_column_family_handle_t; /* DB operations */ extern ROCKSDB_LIBRARY_API rocksdb_t* rocksdb_open( - const rocksdb_options_t* options, - const char* name, - char** errptr); + const rocksdb_options_t* options, const char* name, char** errptr); extern ROCKSDB_LIBRARY_API rocksdb_t* rocksdb_open_for_read_only( - const rocksdb_options_t* options, - const char* name, - unsigned char error_if_log_file_exist, - char** errptr); + const rocksdb_options_t* options, const char* name, + unsigned char error_if_log_file_exist, char** errptr); extern ROCKSDB_LIBRARY_API rocksdb_backup_engine_t* rocksdb_backup_engine_open( - const rocksdb_options_t* options, - const char* path, - char** errptr); + const rocksdb_options_t* options, const char* path, char** errptr); extern ROCKSDB_LIBRARY_API void rocksdb_backup_engine_create_new_backup( - rocksdb_backup_engine_t* be, - rocksdb_t* db, - char** errptr); + rocksdb_backup_engine_t* be, rocksdb_t* db, char** errptr); -extern ROCKSDB_LIBRARY_API rocksdb_restore_options_t* rocksdb_restore_options_create(); -extern ROCKSDB_LIBRARY_API void rocksdb_restore_options_destroy(rocksdb_restore_options_t* opt); +extern ROCKSDB_LIBRARY_API rocksdb_restore_options_t* +rocksdb_restore_options_create(); +extern ROCKSDB_LIBRARY_API void rocksdb_restore_options_destroy( + rocksdb_restore_options_t* opt); extern ROCKSDB_LIBRARY_API void rocksdb_restore_options_set_keep_log_files( rocksdb_restore_options_t* opt, int v); -extern ROCKSDB_LIBRARY_API void rocksdb_backup_engine_restore_db_from_latest_backup( - rocksdb_backup_engine_t *be, - const char* db_dir, - const char* wal_dir, - const rocksdb_restore_options_t *restore_options, - char** errptr); +extern ROCKSDB_LIBRARY_API void +rocksdb_backup_engine_restore_db_from_latest_backup( + rocksdb_backup_engine_t* be, const char* db_dir, const char* wal_dir, + const rocksdb_restore_options_t* restore_options, char** errptr); -extern ROCKSDB_LIBRARY_API const rocksdb_backup_engine_info_t* rocksdb_backup_engine_get_backup_info( - rocksdb_backup_engine_t* be); +extern ROCKSDB_LIBRARY_API const rocksdb_backup_engine_info_t* +rocksdb_backup_engine_get_backup_info(rocksdb_backup_engine_t* be); extern ROCKSDB_LIBRARY_API int rocksdb_backup_engine_info_count( const rocksdb_backup_engine_info_t* info); -extern ROCKSDB_LIBRARY_API int64_t rocksdb_backup_engine_info_timestamp( - const rocksdb_backup_engine_info_t* info, - int index); +extern ROCKSDB_LIBRARY_API int64_t +rocksdb_backup_engine_info_timestamp(const rocksdb_backup_engine_info_t* info, + int index); -extern ROCKSDB_LIBRARY_API uint32_t rocksdb_backup_engine_info_backup_id( - const rocksdb_backup_engine_info_t* info, - int index); +extern ROCKSDB_LIBRARY_API uint32_t +rocksdb_backup_engine_info_backup_id(const rocksdb_backup_engine_info_t* info, + int index); -extern ROCKSDB_LIBRARY_API uint64_t rocksdb_backup_engine_info_size( - const rocksdb_backup_engine_info_t* info, - int index); +extern ROCKSDB_LIBRARY_API uint64_t +rocksdb_backup_engine_info_size(const rocksdb_backup_engine_info_t* info, + int index); extern ROCKSDB_LIBRARY_API uint32_t rocksdb_backup_engine_info_number_files( - const rocksdb_backup_engine_info_t* info, - int index); + const rocksdb_backup_engine_info_t* info, int index); extern ROCKSDB_LIBRARY_API void rocksdb_backup_engine_info_destroy( - const rocksdb_backup_engine_info_t *info); + const rocksdb_backup_engine_info_t* info); extern ROCKSDB_LIBRARY_API void rocksdb_backup_engine_close( rocksdb_backup_engine_t* be); extern ROCKSDB_LIBRARY_API rocksdb_t* rocksdb_open_column_families( - const rocksdb_options_t* options, - const char* name, - int num_column_families, + const rocksdb_options_t* options, const char* name, int num_column_families, const char** column_family_names, const rocksdb_options_t** column_family_options, - rocksdb_column_family_handle_t** column_family_handles, - char** errptr); + rocksdb_column_family_handle_t** column_family_handles, char** errptr); -extern ROCKSDB_LIBRARY_API rocksdb_t* rocksdb_open_for_read_only_column_families( - const rocksdb_options_t* options, - const char* name, - int num_column_families, +extern ROCKSDB_LIBRARY_API rocksdb_t* +rocksdb_open_for_read_only_column_families( + const rocksdb_options_t* options, const char* name, int num_column_families, const char** column_family_names, const rocksdb_options_t** column_family_options, rocksdb_column_family_handle_t** column_family_handles, - unsigned char error_if_log_file_exist, - char** errptr); + unsigned char error_if_log_file_exist, char** errptr); extern ROCKSDB_LIBRARY_API char** rocksdb_list_column_families( - const rocksdb_options_t* options, - const char* name, - size_t* lencf, + const rocksdb_options_t* options, const char* name, size_t* lencf, char** errptr); -extern ROCKSDB_LIBRARY_API void rocksdb_list_column_families_destroy(char** list, size_t len); +extern ROCKSDB_LIBRARY_API void rocksdb_list_column_families_destroy( + char** list, size_t len); -extern ROCKSDB_LIBRARY_API rocksdb_column_family_handle_t* rocksdb_create_column_family( - rocksdb_t* db, - const rocksdb_options_t* column_family_options, - const char* column_family_name, - char** errptr); +extern ROCKSDB_LIBRARY_API rocksdb_column_family_handle_t* +rocksdb_create_column_family(rocksdb_t* db, + const rocksdb_options_t* column_family_options, + const char* column_family_name, char** errptr); extern ROCKSDB_LIBRARY_API void rocksdb_drop_column_family( - rocksdb_t* db, - rocksdb_column_family_handle_t* handle, - char** errptr); + rocksdb_t* db, rocksdb_column_family_handle_t* handle, char** errptr); -extern ROCKSDB_LIBRARY_API void rocksdb_column_family_handle_destroy(rocksdb_column_family_handle_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_column_family_handle_destroy( + rocksdb_column_family_handle_t*); extern ROCKSDB_LIBRARY_API void rocksdb_close(rocksdb_t* db); extern ROCKSDB_LIBRARY_API void rocksdb_put( - rocksdb_t* db, - const rocksdb_writeoptions_t* options, - const char* key, size_t keylen, - const char* val, size_t vallen, - char** errptr); + rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key, + size_t keylen, const char* val, size_t vallen, char** errptr); extern ROCKSDB_LIBRARY_API void rocksdb_put_cf( - rocksdb_t* db, - const rocksdb_writeoptions_t* options, - rocksdb_column_family_handle_t* column_family, - const char* key, size_t keylen, - const char* val, size_t vallen, - char** errptr); + rocksdb_t* db, const rocksdb_writeoptions_t* options, + rocksdb_column_family_handle_t* column_family, const char* key, + size_t keylen, const char* val, size_t vallen, char** errptr); extern ROCKSDB_LIBRARY_API void rocksdb_delete( - rocksdb_t* db, - const rocksdb_writeoptions_t* options, - const char* key, size_t keylen, - char** errptr); + rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key, + size_t keylen, char** errptr); extern ROCKSDB_LIBRARY_API void rocksdb_delete_cf( - rocksdb_t* db, - const rocksdb_writeoptions_t* options, - rocksdb_column_family_handle_t* column_family, - const char* key, size_t keylen, - char** errptr); + rocksdb_t* db, const rocksdb_writeoptions_t* options, + rocksdb_column_family_handle_t* column_family, const char* key, + size_t keylen, char** errptr); extern ROCKSDB_LIBRARY_API void rocksdb_merge( - rocksdb_t* db, - const rocksdb_writeoptions_t* options, - const char* key, size_t keylen, - const char* val, size_t vallen, - char** errptr); + rocksdb_t* db, const rocksdb_writeoptions_t* options, const char* key, + size_t keylen, const char* val, size_t vallen, char** errptr); extern ROCKSDB_LIBRARY_API void rocksdb_merge_cf( - rocksdb_t* db, - const rocksdb_writeoptions_t* options, - rocksdb_column_family_handle_t* column_family, - const char* key, size_t keylen, - const char* val, size_t vallen, - char** errptr); + rocksdb_t* db, const rocksdb_writeoptions_t* options, + rocksdb_column_family_handle_t* column_family, const char* key, + size_t keylen, const char* val, size_t vallen, char** errptr); extern ROCKSDB_LIBRARY_API void rocksdb_write( - rocksdb_t* db, - const rocksdb_writeoptions_t* options, - rocksdb_writebatch_t* batch, - char** errptr); + rocksdb_t* db, const rocksdb_writeoptions_t* options, + rocksdb_writebatch_t* batch, char** errptr); /* Returns NULL if not found. A malloc()ed array otherwise. Stores the length of the array in *vallen. */ extern ROCKSDB_LIBRARY_API char* rocksdb_get( - rocksdb_t* db, - const rocksdb_readoptions_t* options, - const char* key, size_t keylen, - size_t* vallen, - char** errptr); + rocksdb_t* db, const rocksdb_readoptions_t* options, const char* key, + size_t keylen, size_t* vallen, char** errptr); extern ROCKSDB_LIBRARY_API char* rocksdb_get_cf( - rocksdb_t* db, - const rocksdb_readoptions_t* options, - rocksdb_column_family_handle_t* column_family, - const char* key, size_t keylen, - size_t* vallen, - char** errptr); + rocksdb_t* db, const rocksdb_readoptions_t* options, + rocksdb_column_family_handle_t* column_family, const char* key, + size_t keylen, size_t* vallen, char** errptr); // if values_list[i] == NULL and errs[i] == NULL, // then we got status.IsNotFound(), which we will not return. @@ -293,223 +252,193 @@ extern ROCKSDB_LIBRARY_API char* rocksdb_get_cf( // each non-NULL values_list entry is a malloc()ed array, with // the length for each stored in values_list_sizes[i]. extern ROCKSDB_LIBRARY_API void rocksdb_multi_get( - rocksdb_t* db, - const rocksdb_readoptions_t* options, - size_t num_keys, const char* const* keys_list, - const size_t* keys_list_sizes, - char** values_list, size_t* values_list_sizes, - char** errs); + rocksdb_t* db, const rocksdb_readoptions_t* options, size_t num_keys, + const char* const* keys_list, const size_t* keys_list_sizes, + char** values_list, size_t* values_list_sizes, char** errs); extern ROCKSDB_LIBRARY_API void rocksdb_multi_get_cf( - rocksdb_t* db, - const rocksdb_readoptions_t* options, + rocksdb_t* db, const rocksdb_readoptions_t* options, const rocksdb_column_family_handle_t* const* column_families, size_t num_keys, const char* const* keys_list, - const size_t* keys_list_sizes, - char** values_list, size_t* values_list_sizes, - char** errs); + const size_t* keys_list_sizes, char** values_list, + size_t* values_list_sizes, char** errs); extern ROCKSDB_LIBRARY_API rocksdb_iterator_t* rocksdb_create_iterator( - rocksdb_t* db, - const rocksdb_readoptions_t* options); + rocksdb_t* db, const rocksdb_readoptions_t* options); extern ROCKSDB_LIBRARY_API rocksdb_iterator_t* rocksdb_create_iterator_cf( - rocksdb_t* db, - const rocksdb_readoptions_t* options, + rocksdb_t* db, const rocksdb_readoptions_t* options, rocksdb_column_family_handle_t* column_family); extern ROCKSDB_LIBRARY_API const rocksdb_snapshot_t* rocksdb_create_snapshot( rocksdb_t* db); extern ROCKSDB_LIBRARY_API void rocksdb_release_snapshot( - rocksdb_t* db, - const rocksdb_snapshot_t* snapshot); + rocksdb_t* db, const rocksdb_snapshot_t* snapshot); /* Returns NULL if property name is unknown. Else returns a pointer to a malloc()-ed null-terminated value. */ -extern ROCKSDB_LIBRARY_API char* rocksdb_property_value( - rocksdb_t* db, - const char* propname); +extern ROCKSDB_LIBRARY_API char* rocksdb_property_value(rocksdb_t* db, + const char* propname); extern ROCKSDB_LIBRARY_API char* rocksdb_property_value_cf( - rocksdb_t* db, - rocksdb_column_family_handle_t* column_family, + rocksdb_t* db, rocksdb_column_family_handle_t* column_family, const char* propname); extern ROCKSDB_LIBRARY_API void rocksdb_approximate_sizes( - rocksdb_t* db, - int num_ranges, - const char* const* range_start_key, const size_t* range_start_key_len, - const char* const* range_limit_key, const size_t* range_limit_key_len, - uint64_t* sizes); + rocksdb_t* db, int num_ranges, const char* const* range_start_key, + const size_t* range_start_key_len, const char* const* range_limit_key, + const size_t* range_limit_key_len, uint64_t* sizes); extern ROCKSDB_LIBRARY_API void rocksdb_approximate_sizes_cf( - rocksdb_t* db, - rocksdb_column_family_handle_t* column_family, - int num_ranges, - const char* const* range_start_key, const size_t* range_start_key_len, - const char* const* range_limit_key, const size_t* range_limit_key_len, - uint64_t* sizes); + rocksdb_t* db, rocksdb_column_family_handle_t* column_family, + int num_ranges, const char* const* range_start_key, + const size_t* range_start_key_len, const char* const* range_limit_key, + const size_t* range_limit_key_len, uint64_t* sizes); -extern ROCKSDB_LIBRARY_API void rocksdb_compact_range( - rocksdb_t* db, - const char* start_key, size_t start_key_len, - const char* limit_key, size_t limit_key_len); +extern ROCKSDB_LIBRARY_API void rocksdb_compact_range(rocksdb_t* db, + const char* start_key, + size_t start_key_len, + const char* limit_key, + size_t limit_key_len); extern ROCKSDB_LIBRARY_API void rocksdb_compact_range_cf( - rocksdb_t* db, - rocksdb_column_family_handle_t* column_family, - const char* start_key, size_t start_key_len, - const char* limit_key, size_t limit_key_len); + rocksdb_t* db, rocksdb_column_family_handle_t* column_family, + const char* start_key, size_t start_key_len, const char* limit_key, + size_t limit_key_len); -extern ROCKSDB_LIBRARY_API void rocksdb_delete_file( - rocksdb_t* db, - const char* name); +extern ROCKSDB_LIBRARY_API void rocksdb_delete_file(rocksdb_t* db, + const char* name); extern ROCKSDB_LIBRARY_API const rocksdb_livefiles_t* rocksdb_livefiles( rocksdb_t* db); extern ROCKSDB_LIBRARY_API void rocksdb_flush( - rocksdb_t* db, - const rocksdb_flushoptions_t* options, - char** errptr); + rocksdb_t* db, const rocksdb_flushoptions_t* options, char** errptr); -extern ROCKSDB_LIBRARY_API void rocksdb_disable_file_deletions( - rocksdb_t* db, - char** errptr); +extern ROCKSDB_LIBRARY_API void rocksdb_disable_file_deletions(rocksdb_t* db, + char** errptr); extern ROCKSDB_LIBRARY_API void rocksdb_enable_file_deletions( - rocksdb_t* db, - unsigned char force, - char** errptr); + rocksdb_t* db, unsigned char force, char** errptr); /* Management operations */ extern ROCKSDB_LIBRARY_API void rocksdb_destroy_db( - const rocksdb_options_t* options, - const char* name, - char** errptr); + const rocksdb_options_t* options, const char* name, char** errptr); extern ROCKSDB_LIBRARY_API void rocksdb_repair_db( - const rocksdb_options_t* options, - const char* name, - char** errptr); + const rocksdb_options_t* options, const char* name, char** errptr); /* Iterator */ extern ROCKSDB_LIBRARY_API void rocksdb_iter_destroy(rocksdb_iterator_t*); -extern ROCKSDB_LIBRARY_API unsigned char rocksdb_iter_valid(const rocksdb_iterator_t*); +extern ROCKSDB_LIBRARY_API unsigned char rocksdb_iter_valid( + const rocksdb_iterator_t*); extern ROCKSDB_LIBRARY_API void rocksdb_iter_seek_to_first(rocksdb_iterator_t*); extern ROCKSDB_LIBRARY_API void rocksdb_iter_seek_to_last(rocksdb_iterator_t*); -extern ROCKSDB_LIBRARY_API void rocksdb_iter_seek(rocksdb_iterator_t*, const char* k, size_t klen); +extern ROCKSDB_LIBRARY_API void rocksdb_iter_seek(rocksdb_iterator_t*, + const char* k, size_t klen); extern ROCKSDB_LIBRARY_API void rocksdb_iter_next(rocksdb_iterator_t*); extern ROCKSDB_LIBRARY_API void rocksdb_iter_prev(rocksdb_iterator_t*); -extern ROCKSDB_LIBRARY_API const char* rocksdb_iter_key(const rocksdb_iterator_t*, size_t* klen); -extern ROCKSDB_LIBRARY_API const char* rocksdb_iter_value(const rocksdb_iterator_t*, size_t* vlen); -extern ROCKSDB_LIBRARY_API void rocksdb_iter_get_error(const rocksdb_iterator_t*, char** errptr); +extern ROCKSDB_LIBRARY_API const char* rocksdb_iter_key( + const rocksdb_iterator_t*, size_t* klen); +extern ROCKSDB_LIBRARY_API const char* rocksdb_iter_value( + const rocksdb_iterator_t*, size_t* vlen); +extern ROCKSDB_LIBRARY_API void rocksdb_iter_get_error( + const rocksdb_iterator_t*, char** errptr); /* Write batch */ extern ROCKSDB_LIBRARY_API rocksdb_writebatch_t* rocksdb_writebatch_create(); -extern ROCKSDB_LIBRARY_API rocksdb_writebatch_t* rocksdb_writebatch_create_from(const char* rep, - size_t size); -extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_destroy(rocksdb_writebatch_t*); +extern ROCKSDB_LIBRARY_API rocksdb_writebatch_t* rocksdb_writebatch_create_from( + const char* rep, size_t size); +extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_destroy( + rocksdb_writebatch_t*); extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_clear(rocksdb_writebatch_t*); extern ROCKSDB_LIBRARY_API int rocksdb_writebatch_count(rocksdb_writebatch_t*); -extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_put( - rocksdb_writebatch_t*, - const char* key, size_t klen, - const char* val, size_t vlen); +extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_put(rocksdb_writebatch_t*, + const char* key, + size_t klen, + const char* val, + size_t vlen); extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_put_cf( - rocksdb_writebatch_t*, - rocksdb_column_family_handle_t* column_family, - const char* key, size_t klen, - const char* val, size_t vlen); + rocksdb_writebatch_t*, rocksdb_column_family_handle_t* column_family, + const char* key, size_t klen, const char* val, size_t vlen); extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_putv( - rocksdb_writebatch_t* b, - int num_keys, const char* const* keys_list, - const size_t* keys_list_sizes, - int num_values, const char* const* values_list, - const size_t* values_list_sizes); + rocksdb_writebatch_t* b, int num_keys, const char* const* keys_list, + const size_t* keys_list_sizes, int num_values, + const char* const* values_list, const size_t* values_list_sizes); extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_putv_cf( - rocksdb_writebatch_t* b, - rocksdb_column_family_handle_t* column_family, - int num_keys, const char* const* keys_list, - const size_t* keys_list_sizes, + rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family, + int num_keys, const char* const* keys_list, const size_t* keys_list_sizes, int num_values, const char* const* values_list, const size_t* values_list_sizes); -extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_merge( - rocksdb_writebatch_t*, - const char* key, size_t klen, - const char* val, size_t vlen); +extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_merge(rocksdb_writebatch_t*, + const char* key, + size_t klen, + const char* val, + size_t vlen); extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_merge_cf( - rocksdb_writebatch_t*, - rocksdb_column_family_handle_t* column_family, - const char* key, size_t klen, - const char* val, size_t vlen); + rocksdb_writebatch_t*, rocksdb_column_family_handle_t* column_family, + const char* key, size_t klen, const char* val, size_t vlen); extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_mergev( - rocksdb_writebatch_t* b, - int num_keys, const char* const* keys_list, - const size_t* keys_list_sizes, - int num_values, const char* const* values_list, - const size_t* values_list_sizes); + rocksdb_writebatch_t* b, int num_keys, const char* const* keys_list, + const size_t* keys_list_sizes, int num_values, + const char* const* values_list, const size_t* values_list_sizes); extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_mergev_cf( - rocksdb_writebatch_t* b, - rocksdb_column_family_handle_t* column_family, - int num_keys, const char* const* keys_list, - const size_t* keys_list_sizes, + rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family, + int num_keys, const char* const* keys_list, const size_t* keys_list_sizes, int num_values, const char* const* values_list, const size_t* values_list_sizes); -extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_delete( - rocksdb_writebatch_t*, - const char* key, size_t klen); +extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_delete(rocksdb_writebatch_t*, + const char* key, + size_t klen); extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_delete_cf( - rocksdb_writebatch_t*, - rocksdb_column_family_handle_t* column_family, + rocksdb_writebatch_t*, rocksdb_column_family_handle_t* column_family, const char* key, size_t klen); extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_deletev( - rocksdb_writebatch_t* b, - int num_keys, const char* const* keys_list, + rocksdb_writebatch_t* b, int num_keys, const char* const* keys_list, const size_t* keys_list_sizes); extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_deletev_cf( - rocksdb_writebatch_t* b, - rocksdb_column_family_handle_t* column_family, - int num_keys, const char* const* keys_list, - const size_t* keys_list_sizes); -extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_put_log_data( - rocksdb_writebatch_t*, - const char* blob, size_t len); + rocksdb_writebatch_t* b, rocksdb_column_family_handle_t* column_family, + int num_keys, const char* const* keys_list, const size_t* keys_list_sizes); +extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_put_log_data( + rocksdb_writebatch_t*, const char* blob, size_t len); extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_iterate( - rocksdb_writebatch_t*, - void* state, + rocksdb_writebatch_t*, void* state, void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen), void (*deleted)(void*, const char* k, size_t klen)); -extern ROCKSDB_LIBRARY_API const char* rocksdb_writebatch_data(rocksdb_writebatch_t*, size_t *size); +extern ROCKSDB_LIBRARY_API const char* rocksdb_writebatch_data( + rocksdb_writebatch_t*, size_t* size); /* Block based table options */ extern ROCKSDB_LIBRARY_API rocksdb_block_based_table_options_t* - rocksdb_block_based_options_create(); +rocksdb_block_based_options_create(); extern ROCKSDB_LIBRARY_API void rocksdb_block_based_options_destroy( rocksdb_block_based_table_options_t* options); extern ROCKSDB_LIBRARY_API void rocksdb_block_based_options_set_block_size( rocksdb_block_based_table_options_t* options, size_t block_size); -extern ROCKSDB_LIBRARY_API void rocksdb_block_based_options_set_block_size_deviation( +extern ROCKSDB_LIBRARY_API void +rocksdb_block_based_options_set_block_size_deviation( rocksdb_block_based_table_options_t* options, int block_size_deviation); -extern ROCKSDB_LIBRARY_API void rocksdb_block_based_options_set_block_restart_interval( +extern ROCKSDB_LIBRARY_API void +rocksdb_block_based_options_set_block_restart_interval( rocksdb_block_based_table_options_t* options, int block_restart_interval); extern ROCKSDB_LIBRARY_API void rocksdb_block_based_options_set_filter_policy( rocksdb_block_based_table_options_t* options, rocksdb_filterpolicy_t* filter_policy); extern ROCKSDB_LIBRARY_API void rocksdb_block_based_options_set_no_block_cache( - rocksdb_block_based_table_options_t* options, - unsigned char no_block_cache); + rocksdb_block_based_table_options_t* options, unsigned char no_block_cache); extern ROCKSDB_LIBRARY_API void rocksdb_block_based_options_set_block_cache( rocksdb_block_based_table_options_t* options, rocksdb_cache_t* block_cache); -extern ROCKSDB_LIBRARY_API void rocksdb_block_based_options_set_block_cache_compressed( +extern ROCKSDB_LIBRARY_API void +rocksdb_block_based_options_set_block_cache_compressed( rocksdb_block_based_table_options_t* options, rocksdb_cache_t* block_cache_compressed); -extern ROCKSDB_LIBRARY_API void rocksdb_block_based_options_set_whole_key_filtering( +extern ROCKSDB_LIBRARY_API void +rocksdb_block_based_options_set_whole_key_filtering( rocksdb_block_based_table_options_t*, unsigned char); extern ROCKSDB_LIBRARY_API void rocksdb_block_based_options_set_format_version( rocksdb_block_based_table_options_t*, int); @@ -518,18 +447,20 @@ enum { rocksdb_block_based_table_index_type_hash_search = 1, }; extern ROCKSDB_LIBRARY_API void rocksdb_block_based_options_set_index_type( - rocksdb_block_based_table_options_t*, int); // uses one of the above enums -extern ROCKSDB_LIBRARY_API void rocksdb_block_based_options_set_hash_index_allow_collision( + rocksdb_block_based_table_options_t*, int); // uses one of the above enums +extern ROCKSDB_LIBRARY_API void +rocksdb_block_based_options_set_hash_index_allow_collision( rocksdb_block_based_table_options_t*, unsigned char); -extern ROCKSDB_LIBRARY_API void rocksdb_block_based_options_set_cache_index_and_filter_blocks( +extern ROCKSDB_LIBRARY_API void +rocksdb_block_based_options_set_cache_index_and_filter_blocks( rocksdb_block_based_table_options_t*, unsigned char); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_block_based_table_factory( - rocksdb_options_t *opt, rocksdb_block_based_table_options_t* table_options); + rocksdb_options_t* opt, rocksdb_block_based_table_options_t* table_options); /* Cuckoo table options */ extern ROCKSDB_LIBRARY_API rocksdb_cuckoo_table_options_t* - rocksdb_cuckoo_options_create(); +rocksdb_cuckoo_options_create(); extern ROCKSDB_LIBRARY_API void rocksdb_cuckoo_options_destroy( rocksdb_cuckoo_table_options_t* options); extern ROCKSDB_LIBRARY_API void rocksdb_cuckoo_options_set_hash_ratio( @@ -538,12 +469,13 @@ extern ROCKSDB_LIBRARY_API void rocksdb_cuckoo_options_set_max_search_depth( rocksdb_cuckoo_table_options_t* options, uint32_t v); extern ROCKSDB_LIBRARY_API void rocksdb_cuckoo_options_set_cuckoo_block_size( rocksdb_cuckoo_table_options_t* options, uint32_t v); -extern ROCKSDB_LIBRARY_API void rocksdb_cuckoo_options_set_identity_as_first_hash( +extern ROCKSDB_LIBRARY_API void +rocksdb_cuckoo_options_set_identity_as_first_hash( rocksdb_cuckoo_table_options_t* options, unsigned char v); extern ROCKSDB_LIBRARY_API void rocksdb_cuckoo_options_set_use_module_hash( rocksdb_cuckoo_table_options_t* options, unsigned char v); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_cuckoo_table_factory( - rocksdb_options_t *opt, rocksdb_cuckoo_table_options_t* table_options); + rocksdb_options_t* opt, rocksdb_cuckoo_table_options_t* table_options); /* Options */ @@ -555,50 +487,55 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_optimize_for_point_lookup( rocksdb_options_t* opt, uint64_t block_cache_size_mb); extern ROCKSDB_LIBRARY_API void rocksdb_options_optimize_level_style_compaction( rocksdb_options_t* opt, uint64_t memtable_memory_budget); -extern ROCKSDB_LIBRARY_API void rocksdb_options_optimize_universal_style_compaction( +extern ROCKSDB_LIBRARY_API void +rocksdb_options_optimize_universal_style_compaction( rocksdb_options_t* opt, uint64_t memtable_memory_budget); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_compaction_filter( - rocksdb_options_t*, - rocksdb_compactionfilter_t*); + rocksdb_options_t*, rocksdb_compactionfilter_t*); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_compaction_filter_factory( rocksdb_options_t*, rocksdb_compactionfilterfactory_t*); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_compaction_filter_factory_v2( - rocksdb_options_t*, - rocksdb_compactionfilterfactoryv2_t*); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_compaction_filter_factory_v2( + rocksdb_options_t*, rocksdb_compactionfilterfactoryv2_t*); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_comparator( - rocksdb_options_t*, - rocksdb_comparator_t*); + rocksdb_options_t*, rocksdb_comparator_t*); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_merge_operator( - rocksdb_options_t*, - rocksdb_mergeoperator_t*); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_uint64add_merge_operator(rocksdb_options_t*); + rocksdb_options_t*, rocksdb_mergeoperator_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_uint64add_merge_operator( + rocksdb_options_t*); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_compression_per_level( - rocksdb_options_t* opt, - int* level_values, - size_t num_levels); + rocksdb_options_t* opt, int* level_values, size_t num_levels); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_create_if_missing( rocksdb_options_t*, unsigned char); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_create_missing_column_families( - rocksdb_options_t*, unsigned char); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_create_missing_column_families(rocksdb_options_t*, + unsigned char); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_error_if_exists( rocksdb_options_t*, unsigned char); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_paranoid_checks( rocksdb_options_t*, unsigned char); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_env(rocksdb_options_t*, rocksdb_env_t*); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_info_log(rocksdb_options_t*, rocksdb_logger_t*); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_info_log_level(rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_write_buffer_size(rocksdb_options_t*, size_t); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_open_files(rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_total_wal_size(rocksdb_options_t* opt, uint64_t n); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_env(rocksdb_options_t*, + rocksdb_env_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_info_log(rocksdb_options_t*, + rocksdb_logger_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_info_log_level( + rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_write_buffer_size( + rocksdb_options_t*, size_t); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_open_files( + rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_total_wal_size( + rocksdb_options_t* opt, uint64_t n); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_compression_options( rocksdb_options_t*, int, int, int); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_prefix_extractor( rocksdb_options_t*, rocksdb_slicetransform_t*); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_num_levels(rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_level0_file_num_compaction_trigger( - rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_level0_slowdown_writes_trigger( +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_num_levels( rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_level0_file_num_compaction_trigger(rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_level0_slowdown_writes_trigger(rocksdb_options_t*, int); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_level0_stop_writes_trigger( rocksdb_options_t*, int); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_mem_compaction_level( @@ -609,56 +546,72 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_set_target_file_size_multiplier( rocksdb_options_t*, int); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_bytes_for_level_base( rocksdb_options_t*, uint64_t); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_bytes_for_level_multiplier( - rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_max_bytes_for_level_multiplier(rocksdb_options_t*, int); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_expanded_compaction_factor( rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_grandparent_overlap_factor( - rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_bytes_for_level_multiplier_additional( +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_max_grandparent_overlap_factor(rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_max_bytes_for_level_multiplier_additional( rocksdb_options_t*, int* level_values, size_t num_levels); -extern ROCKSDB_LIBRARY_API void rocksdb_options_enable_statistics(rocksdb_options_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_options_enable_statistics( + rocksdb_options_t*); /* returns a pointer to a malloc()-ed, null terminated string */ -extern ROCKSDB_LIBRARY_API char *rocksdb_options_statistics_get_string(rocksdb_options_t *opt); +extern ROCKSDB_LIBRARY_API char* rocksdb_options_statistics_get_string( + rocksdb_options_t* opt); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_write_buffer_number(rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_min_write_buffer_number_to_merge(rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_write_buffer_number_to_maintain( +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_write_buffer_number( rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_background_compactions(rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_background_flushes(rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_log_file_size(rocksdb_options_t*, size_t); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_log_file_time_to_roll(rocksdb_options_t*, size_t); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_keep_log_file_num(rocksdb_options_t*, size_t); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_soft_rate_limit(rocksdb_options_t*, double); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_hard_rate_limit(rocksdb_options_t*, double); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_rate_limit_delay_max_milliseconds( - rocksdb_options_t*, unsigned int); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_min_write_buffer_number_to_merge(rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_max_write_buffer_number_to_maintain(rocksdb_options_t*, + int); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_background_compactions( + rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_background_flushes( + rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_log_file_size( + rocksdb_options_t*, size_t); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_log_file_time_to_roll( + rocksdb_options_t*, size_t); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_keep_log_file_num( + rocksdb_options_t*, size_t); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_soft_rate_limit( + rocksdb_options_t*, double); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_hard_rate_limit( + rocksdb_options_t*, double); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_rate_limit_delay_max_milliseconds(rocksdb_options_t*, + unsigned int); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_manifest_file_size( rocksdb_options_t*, size_t); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_no_block_cache( rocksdb_options_t*, unsigned char); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_table_cache_numshardbits( rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_table_cache_remove_scan_count_limit( - rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_table_cache_remove_scan_count_limit(rocksdb_options_t*, + int); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_arena_block_size( rocksdb_options_t*, size_t); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_use_fsync( rocksdb_options_t*, int); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_db_log_dir( rocksdb_options_t*, const char*); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_wal_dir( - rocksdb_options_t*, const char*); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_wal_dir(rocksdb_options_t*, + const char*); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_WAL_ttl_seconds( rocksdb_options_t*, uint64_t); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_WAL_size_limit_MB( rocksdb_options_t*, uint64_t); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_manifest_preallocation_size( rocksdb_options_t*, size_t); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_purge_redundant_kvs_while_flush( - rocksdb_options_t*, unsigned char); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_purge_redundant_kvs_while_flush(rocksdb_options_t*, + unsigned char); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_allow_os_buffer( rocksdb_options_t*, unsigned char); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_allow_mmap_reads( @@ -675,35 +628,47 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_set_block_size_deviation( rocksdb_options_t*, int); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_advise_random_on_open( rocksdb_options_t*, unsigned char); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_access_hint_on_compaction_start( - rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_access_hint_on_compaction_start(rocksdb_options_t*, int); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_use_adaptive_mutex( rocksdb_options_t*, unsigned char); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_bytes_per_sync( rocksdb_options_t*, uint64_t); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_verify_checksums_in_compaction( - rocksdb_options_t*, unsigned char); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_verify_checksums_in_compaction(rocksdb_options_t*, + unsigned char); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_filter_deletes( rocksdb_options_t*, unsigned char); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_sequential_skip_in_iterations( - rocksdb_options_t*, uint64_t); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_disable_data_sync(rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_disable_auto_compactions(rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_delete_obsolete_files_period_micros( - rocksdb_options_t*, uint64_t); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_source_compaction_factor(rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_prepare_for_bulk_load(rocksdb_options_t*); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_memtable_vector_rep(rocksdb_options_t*); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_hash_skip_list_rep(rocksdb_options_t*, size_t, int32_t, int32_t); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_hash_link_list_rep(rocksdb_options_t*, size_t); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_plain_table_factory(rocksdb_options_t*, uint32_t, int, double, size_t); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_max_sequential_skip_in_iterations(rocksdb_options_t*, + uint64_t); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_disable_data_sync( + rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_disable_auto_compactions( + rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_delete_obsolete_files_period_micros(rocksdb_options_t*, + uint64_t); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_source_compaction_factor( + rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void rocksdb_options_prepare_for_bulk_load( + rocksdb_options_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_memtable_vector_rep( + rocksdb_options_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_hash_skip_list_rep( + rocksdb_options_t*, size_t, int32_t, int32_t); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_hash_link_list_rep( + rocksdb_options_t*, size_t); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_plain_table_factory( + rocksdb_options_t*, uint32_t, int, double, size_t); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_min_level_to_compress(rocksdb_options_t* opt, int level); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_min_level_to_compress( + rocksdb_options_t* opt, int level); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_memtable_prefix_bloom_bits( rocksdb_options_t*, uint32_t); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_memtable_prefix_bloom_probes( - rocksdb_options_t*, uint32_t); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_memtable_prefix_bloom_probes(rocksdb_options_t*, uint32_t); extern ROCKSDB_LIBRARY_API void rocksdb_options_set_max_successive_merges( rocksdb_options_t*, size_t); @@ -724,156 +689,147 @@ enum { rocksdb_lz4_compression = 4, rocksdb_lz4hc_compression = 5 }; -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_compression(rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_compression( + rocksdb_options_t*, int); enum { rocksdb_level_compaction = 0, rocksdb_universal_compaction = 1, rocksdb_fifo_compaction = 2 }; -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_compaction_style(rocksdb_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_universal_compaction_options(rocksdb_options_t*, rocksdb_universal_compaction_options_t*); -extern ROCKSDB_LIBRARY_API void rocksdb_options_set_fifo_compaction_options(rocksdb_options_t* opt, - rocksdb_fifo_compaction_options_t* fifo); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_compaction_style( + rocksdb_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_options_set_universal_compaction_options( + rocksdb_options_t*, rocksdb_universal_compaction_options_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_fifo_compaction_options( + rocksdb_options_t* opt, rocksdb_fifo_compaction_options_t* fifo); /* Compaction Filter */ -extern ROCKSDB_LIBRARY_API rocksdb_compactionfilter_t* rocksdb_compactionfilter_create( - void* state, - void (*destructor)(void*), - unsigned char (*filter)( - void*, - int level, - const char* key, size_t key_length, - const char* existing_value, size_t value_length, - char** new_value, size_t *new_value_length, - unsigned char* value_changed), +extern ROCKSDB_LIBRARY_API rocksdb_compactionfilter_t* +rocksdb_compactionfilter_create( + void* state, void (*destructor)(void*), + unsigned char (*filter)(void*, int level, const char* key, + size_t key_length, const char* existing_value, + size_t value_length, char** new_value, + size_t* new_value_length, + unsigned char* value_changed), const char* (*name)(void*)); -extern ROCKSDB_LIBRARY_API void rocksdb_compactionfilter_destroy(rocksdb_compactionfilter_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_compactionfilter_destroy( + rocksdb_compactionfilter_t*); /* Compaction Filter Context */ -extern ROCKSDB_LIBRARY_API unsigned char rocksdb_compactionfiltercontext_is_full_compaction( +extern ROCKSDB_LIBRARY_API unsigned char +rocksdb_compactionfiltercontext_is_full_compaction( rocksdb_compactionfiltercontext_t* context); -extern ROCKSDB_LIBRARY_API unsigned char rocksdb_compactionfiltercontext_is_manual_compaction( +extern ROCKSDB_LIBRARY_API unsigned char +rocksdb_compactionfiltercontext_is_manual_compaction( rocksdb_compactionfiltercontext_t* context); /* Compaction Filter Factory */ extern ROCKSDB_LIBRARY_API rocksdb_compactionfilterfactory_t* - rocksdb_compactionfilterfactory_create( - void* state, void (*destructor)(void*), - rocksdb_compactionfilter_t* (*create_compaction_filter)( - void*, rocksdb_compactionfiltercontext_t* context), - const char* (*name)(void*)); +rocksdb_compactionfilterfactory_create( + void* state, void (*destructor)(void*), + rocksdb_compactionfilter_t* (*create_compaction_filter)( + void*, rocksdb_compactionfiltercontext_t* context), + const char* (*name)(void*)); extern ROCKSDB_LIBRARY_API void rocksdb_compactionfilterfactory_destroy( rocksdb_compactionfilterfactory_t*); /* Compaction Filter V2 */ -extern ROCKSDB_LIBRARY_API rocksdb_compactionfilterv2_t* rocksdb_compactionfilterv2_create( - void* state, - void (*destructor)(void*), +extern ROCKSDB_LIBRARY_API rocksdb_compactionfilterv2_t* +rocksdb_compactionfilterv2_create( + void* state, void (*destructor)(void*), // num_keys specifies the number of array entries in every *list parameter. // New values added to the new_values_list should be malloc'd and will be // freed by the caller. Specify true in the to_delete_list to remove an // entry during compaction; false to keep it. - void (*filter)( - void*, int level, size_t num_keys, - const char* const* keys_list, const size_t* keys_list_sizes, - const char* const* existing_values_list, const size_t* existing_values_list_sizes, - char** new_values_list, size_t* new_values_list_sizes, - unsigned char* to_delete_list), + void (*filter)(void*, int level, size_t num_keys, + const char* const* keys_list, const size_t* keys_list_sizes, + const char* const* existing_values_list, + const size_t* existing_values_list_sizes, + char** new_values_list, size_t* new_values_list_sizes, + unsigned char* to_delete_list), const char* (*name)(void*)); extern void rocksdb_compactionfilterv2_destroy(rocksdb_compactionfilterv2_t*); /* Compaction Filter Factory V2 */ -extern ROCKSDB_LIBRARY_API rocksdb_compactionfilterfactoryv2_t* rocksdb_compactionfilterfactoryv2_create( - void* state, - rocksdb_slicetransform_t* prefix_extractor, +extern ROCKSDB_LIBRARY_API rocksdb_compactionfilterfactoryv2_t* +rocksdb_compactionfilterfactoryv2_create( + void* state, rocksdb_slicetransform_t* prefix_extractor, void (*destructor)(void*), rocksdb_compactionfilterv2_t* (*create_compaction_filter_v2)( void*, const rocksdb_compactionfiltercontext_t* context), const char* (*name)(void*)); -extern ROCKSDB_LIBRARY_API void rocksdb_compactionfilterfactoryv2_destroy(rocksdb_compactionfilterfactoryv2_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_compactionfilterfactoryv2_destroy( + rocksdb_compactionfilterfactoryv2_t*); /* Comparator */ extern ROCKSDB_LIBRARY_API rocksdb_comparator_t* rocksdb_comparator_create( - void* state, - void (*destructor)(void*), - int (*compare)( - void*, - const char* a, size_t alen, - const char* b, size_t blen), + void* state, void (*destructor)(void*), + int (*compare)(void*, const char* a, size_t alen, const char* b, + size_t blen), const char* (*name)(void*)); -extern ROCKSDB_LIBRARY_API void rocksdb_comparator_destroy(rocksdb_comparator_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_comparator_destroy( + rocksdb_comparator_t*); /* Filter policy */ extern ROCKSDB_LIBRARY_API rocksdb_filterpolicy_t* rocksdb_filterpolicy_create( - void* state, - void (*destructor)(void*), - char* (*create_filter)( - void*, - const char* const* key_array, const size_t* key_length_array, - int num_keys, - size_t* filter_length), - unsigned char (*key_may_match)( - void*, - const char* key, size_t length, - const char* filter, size_t filter_length), - void (*delete_filter)( - void*, - const char* filter, size_t filter_length), + void* state, void (*destructor)(void*), + char* (*create_filter)(void*, const char* const* key_array, + const size_t* key_length_array, int num_keys, + size_t* filter_length), + unsigned char (*key_may_match)(void*, const char* key, size_t length, + const char* filter, size_t filter_length), + void (*delete_filter)(void*, const char* filter, size_t filter_length), const char* (*name)(void*)); -extern ROCKSDB_LIBRARY_API void rocksdb_filterpolicy_destroy(rocksdb_filterpolicy_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_filterpolicy_destroy( + rocksdb_filterpolicy_t*); -extern ROCKSDB_LIBRARY_API rocksdb_filterpolicy_t* rocksdb_filterpolicy_create_bloom( - int bits_per_key); +extern ROCKSDB_LIBRARY_API rocksdb_filterpolicy_t* +rocksdb_filterpolicy_create_bloom(int bits_per_key); /* Merge Operator */ -extern ROCKSDB_LIBRARY_API rocksdb_mergeoperator_t* rocksdb_mergeoperator_create( - void* state, - void (*destructor)(void*), - char* (*full_merge)( - void*, - const char* key, size_t key_length, - const char* existing_value, size_t existing_value_length, - const char* const* operands_list, const size_t* operands_list_length, - int num_operands, - unsigned char* success, size_t* new_value_length), - char* (*partial_merge)( - void*, - const char* key, size_t key_length, - const char* const* operands_list, const size_t* operands_list_length, - int num_operands, - unsigned char* success, size_t* new_value_length), - void (*delete_value)( - void*, - const char* value, size_t value_length), +extern ROCKSDB_LIBRARY_API rocksdb_mergeoperator_t* +rocksdb_mergeoperator_create( + void* state, void (*destructor)(void*), + char* (*full_merge)(void*, const char* key, size_t key_length, + const char* existing_value, + size_t existing_value_length, + const char* const* operands_list, + const size_t* operands_list_length, int num_operands, + unsigned char* success, size_t* new_value_length), + char* (*partial_merge)(void*, const char* key, size_t key_length, + const char* const* operands_list, + const size_t* operands_list_length, int num_operands, + unsigned char* success, size_t* new_value_length), + void (*delete_value)(void*, const char* value, size_t value_length), const char* (*name)(void*)); -extern ROCKSDB_LIBRARY_API void rocksdb_mergeoperator_destroy(rocksdb_mergeoperator_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_mergeoperator_destroy( + rocksdb_mergeoperator_t*); /* Read options */ extern ROCKSDB_LIBRARY_API rocksdb_readoptions_t* rocksdb_readoptions_create(); -extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_destroy(rocksdb_readoptions_t*); +extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_destroy( + rocksdb_readoptions_t*); extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_verify_checksums( - rocksdb_readoptions_t*, - unsigned char); + rocksdb_readoptions_t*, unsigned char); extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_fill_cache( rocksdb_readoptions_t*, unsigned char); extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_snapshot( - rocksdb_readoptions_t*, - const rocksdb_snapshot_t*); + rocksdb_readoptions_t*, const rocksdb_snapshot_t*); extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_iterate_upper_bound( - rocksdb_readoptions_t*, - const char* key, - size_t keylen); + rocksdb_readoptions_t*, const char* key, size_t keylen); extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_read_tier( rocksdb_readoptions_t*, int); extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_tailing( @@ -881,51 +837,57 @@ extern ROCKSDB_LIBRARY_API void rocksdb_readoptions_set_tailing( /* Write options */ -extern ROCKSDB_LIBRARY_API rocksdb_writeoptions_t* rocksdb_writeoptions_create(); -extern ROCKSDB_LIBRARY_API void rocksdb_writeoptions_destroy(rocksdb_writeoptions_t*); +extern ROCKSDB_LIBRARY_API rocksdb_writeoptions_t* +rocksdb_writeoptions_create(); +extern ROCKSDB_LIBRARY_API void rocksdb_writeoptions_destroy( + rocksdb_writeoptions_t*); extern ROCKSDB_LIBRARY_API void rocksdb_writeoptions_set_sync( rocksdb_writeoptions_t*, unsigned char); -extern ROCKSDB_LIBRARY_API void rocksdb_writeoptions_disable_WAL(rocksdb_writeoptions_t* opt, int disable); +extern ROCKSDB_LIBRARY_API void rocksdb_writeoptions_disable_WAL( + rocksdb_writeoptions_t* opt, int disable); /* Flush options */ -extern ROCKSDB_LIBRARY_API rocksdb_flushoptions_t* rocksdb_flushoptions_create(); -extern ROCKSDB_LIBRARY_API void rocksdb_flushoptions_destroy(rocksdb_flushoptions_t*); +extern ROCKSDB_LIBRARY_API rocksdb_flushoptions_t* +rocksdb_flushoptions_create(); +extern ROCKSDB_LIBRARY_API void rocksdb_flushoptions_destroy( + rocksdb_flushoptions_t*); extern ROCKSDB_LIBRARY_API void rocksdb_flushoptions_set_wait( rocksdb_flushoptions_t*, unsigned char); /* Cache */ -extern ROCKSDB_LIBRARY_API rocksdb_cache_t* rocksdb_cache_create_lru(size_t capacity); +extern ROCKSDB_LIBRARY_API rocksdb_cache_t* rocksdb_cache_create_lru( + size_t capacity); extern ROCKSDB_LIBRARY_API void rocksdb_cache_destroy(rocksdb_cache_t* cache); /* Env */ extern ROCKSDB_LIBRARY_API rocksdb_env_t* rocksdb_create_default_env(); -extern ROCKSDB_LIBRARY_API void rocksdb_env_set_background_threads(rocksdb_env_t* env, int n); -extern ROCKSDB_LIBRARY_API void rocksdb_env_set_high_priority_background_threads(rocksdb_env_t* env, int n); -extern ROCKSDB_LIBRARY_API void rocksdb_env_join_all_threads(rocksdb_env_t* env); +extern ROCKSDB_LIBRARY_API void rocksdb_env_set_background_threads( + rocksdb_env_t* env, int n); +extern ROCKSDB_LIBRARY_API void +rocksdb_env_set_high_priority_background_threads(rocksdb_env_t* env, int n); +extern ROCKSDB_LIBRARY_API void rocksdb_env_join_all_threads( + rocksdb_env_t* env); extern ROCKSDB_LIBRARY_API void rocksdb_env_destroy(rocksdb_env_t*); /* SliceTransform */ -extern ROCKSDB_LIBRARY_API rocksdb_slicetransform_t* rocksdb_slicetransform_create( - void* state, - void (*destructor)(void*), - char* (*transform)( - void*, - const char* key, size_t length, - size_t* dst_length), - unsigned char (*in_domain)( - void*, - const char* key, size_t length), - unsigned char (*in_range)( - void*, - const char* key, size_t length), +extern ROCKSDB_LIBRARY_API rocksdb_slicetransform_t* +rocksdb_slicetransform_create( + void* state, void (*destructor)(void*), + char* (*transform)(void*, const char* key, size_t length, + size_t* dst_length), + unsigned char (*in_domain)(void*, const char* key, size_t length), + unsigned char (*in_range)(void*, const char* key, size_t length), const char* (*name)(void*)); -extern ROCKSDB_LIBRARY_API rocksdb_slicetransform_t* rocksdb_slicetransform_create_fixed_prefix(size_t); -extern ROCKSDB_LIBRARY_API rocksdb_slicetransform_t* rocksdb_slicetransform_create_noop(); -extern ROCKSDB_LIBRARY_API void rocksdb_slicetransform_destroy(rocksdb_slicetransform_t*); +extern ROCKSDB_LIBRARY_API rocksdb_slicetransform_t* + rocksdb_slicetransform_create_fixed_prefix(size_t); +extern ROCKSDB_LIBRARY_API rocksdb_slicetransform_t* +rocksdb_slicetransform_create_noop(); +extern ROCKSDB_LIBRARY_API void rocksdb_slicetransform_destroy( + rocksdb_slicetransform_t*); /* Universal Compaction options */ @@ -934,62 +896,61 @@ enum { rocksdb_total_size_compaction_stop_style = 1 }; -extern ROCKSDB_LIBRARY_API rocksdb_universal_compaction_options_t* rocksdb_universal_compaction_options_create(); -extern ROCKSDB_LIBRARY_API void rocksdb_universal_compaction_options_set_size_ratio( - rocksdb_universal_compaction_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_universal_compaction_options_set_min_merge_width( - rocksdb_universal_compaction_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_universal_compaction_options_set_max_merge_width( - rocksdb_universal_compaction_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_universal_compaction_options_set_max_size_amplification_percent( - rocksdb_universal_compaction_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_universal_compaction_options_set_compression_size_percent( - rocksdb_universal_compaction_options_t*, int); -extern ROCKSDB_LIBRARY_API void rocksdb_universal_compaction_options_set_stop_style( - rocksdb_universal_compaction_options_t*, int); +extern ROCKSDB_LIBRARY_API rocksdb_universal_compaction_options_t* +rocksdb_universal_compaction_options_create(); +extern ROCKSDB_LIBRARY_API void +rocksdb_universal_compaction_options_set_size_ratio( + rocksdb_universal_compaction_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_universal_compaction_options_set_min_merge_width( + rocksdb_universal_compaction_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_universal_compaction_options_set_max_merge_width( + rocksdb_universal_compaction_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_universal_compaction_options_set_max_size_amplification_percent( + rocksdb_universal_compaction_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_universal_compaction_options_set_compression_size_percent( + rocksdb_universal_compaction_options_t*, int); +extern ROCKSDB_LIBRARY_API void +rocksdb_universal_compaction_options_set_stop_style( + rocksdb_universal_compaction_options_t*, int); extern ROCKSDB_LIBRARY_API void rocksdb_universal_compaction_options_destroy( - rocksdb_universal_compaction_options_t*); + rocksdb_universal_compaction_options_t*); -extern ROCKSDB_LIBRARY_API rocksdb_fifo_compaction_options_t* rocksdb_fifo_compaction_options_create(); -extern ROCKSDB_LIBRARY_API void rocksdb_fifo_compaction_options_set_max_table_files_size( +extern ROCKSDB_LIBRARY_API rocksdb_fifo_compaction_options_t* +rocksdb_fifo_compaction_options_create(); +extern ROCKSDB_LIBRARY_API void +rocksdb_fifo_compaction_options_set_max_table_files_size( rocksdb_fifo_compaction_options_t* fifo_opts, uint64_t size); extern ROCKSDB_LIBRARY_API void rocksdb_fifo_compaction_options_destroy( rocksdb_fifo_compaction_options_t* fifo_opts); extern ROCKSDB_LIBRARY_API int rocksdb_livefiles_count( - const rocksdb_livefiles_t*); + const rocksdb_livefiles_t*); extern ROCKSDB_LIBRARY_API const char* rocksdb_livefiles_name( - const rocksdb_livefiles_t*, - int index); + const rocksdb_livefiles_t*, int index); extern ROCKSDB_LIBRARY_API int rocksdb_livefiles_level( - const rocksdb_livefiles_t*, - int index); -extern ROCKSDB_LIBRARY_API size_t rocksdb_livefiles_size( - const rocksdb_livefiles_t*, - int index); + const rocksdb_livefiles_t*, int index); +extern ROCKSDB_LIBRARY_API size_t +rocksdb_livefiles_size(const rocksdb_livefiles_t*, int index); extern ROCKSDB_LIBRARY_API const char* rocksdb_livefiles_smallestkey( - const rocksdb_livefiles_t*, - int index, - size_t* size); + const rocksdb_livefiles_t*, int index, size_t* size); extern ROCKSDB_LIBRARY_API const char* rocksdb_livefiles_largestkey( - const rocksdb_livefiles_t*, - int index, - size_t* size); + const rocksdb_livefiles_t*, int index, size_t* size); extern ROCKSDB_LIBRARY_API void rocksdb_livefiles_destroy( - const rocksdb_livefiles_t*); + const rocksdb_livefiles_t*); /* Utility Helpers */ extern ROCKSDB_LIBRARY_API void rocksdb_get_options_from_string( - const rocksdb_options_t* base_options, - const char* opts_str, - rocksdb_options_t* new_options, - char** errptr); + const rocksdb_options_t* base_options, const char* opts_str, + rocksdb_options_t* new_options, char** errptr); -// referring to convention (3), this should be used by client +// referring to convention (3), this should be used by client // to free memory that was malloc()ed -extern ROCKSDB_LIBRARY_API void rocksdb_free( - void* ptr); +extern ROCKSDB_LIBRARY_API void rocksdb_free(void* ptr); #ifdef __cplusplus } /* end extern "C" */ diff --git a/include/rocksdb/thread_status.h b/include/rocksdb/thread_status.h index 4d53b28aa..5f3f3f16b 100644 --- a/include/rocksdb/thread_status.h +++ b/include/rocksdb/thread_status.h @@ -33,7 +33,7 @@ namespace rocksdb { // TODO(yhchiang): remove this function once c++14 is available // as std::max will be able to cover this. // Current MS compiler does not support constexpr -template +template struct constexpr_max { static const int result = (A > B) ? A : B; }; diff --git a/include/rocksdb/transaction_log.h b/include/rocksdb/transaction_log.h index e03a69eb0..1b80b9a0c 100644 --- a/include/rocksdb/transaction_log.h +++ b/include/rocksdb/transaction_log.h @@ -56,31 +56,29 @@ class LogFile { }; struct BatchResult { - SequenceNumber sequence = 0; - std::unique_ptr writeBatchPtr; + SequenceNumber sequence = 0; + std::unique_ptr writeBatchPtr; - // Add empty __ctor and __dtor for the rule of five - // However, preserve the original semantics and prohibit copying - // as the unique_ptr member does not copy. - BatchResult() { - } + // Add empty __ctor and __dtor for the rule of five + // However, preserve the original semantics and prohibit copying + // as the unique_ptr member does not copy. + BatchResult() {} - ~BatchResult() { - } + ~BatchResult() {} - BatchResult(const BatchResult&) = delete; + BatchResult(const BatchResult&) = delete; - BatchResult& operator=(const BatchResult&) = delete; + BatchResult& operator=(const BatchResult&) = delete; - BatchResult(BatchResult && bResult) : - sequence(std::move(bResult.sequence)), writeBatchPtr(std::move(bResult.writeBatchPtr)) { - } + BatchResult(BatchResult&& bResult) + : sequence(std::move(bResult.sequence)), + writeBatchPtr(std::move(bResult.writeBatchPtr)) {} - BatchResult& operator=(BatchResult && bResult) { - sequence = std::move(bResult.sequence); - writeBatchPtr = std::move(bResult.writeBatchPtr); - return *this; - } + BatchResult& operator=(BatchResult&& bResult) { + sequence = std::move(bResult.sequence); + writeBatchPtr = std::move(bResult.writeBatchPtr); + return *this; + } }; // A TransactionLogIterator is used to iterate over the transactions in a db. diff --git a/include/rocksdb/utilities/spatial_db.h b/include/rocksdb/utilities/spatial_db.h index 894930a68..50abbf446 100644 --- a/include/rocksdb/utilities/spatial_db.h +++ b/include/rocksdb/utilities/spatial_db.h @@ -54,24 +54,18 @@ struct Variant { /* implicit */ Variant(uint64_t i) : type_(kInt) { data_.i = i; } /* implicit */ Variant(double d) : type_(kDouble) { data_.d = d; } /* implicit */ Variant(const std::string& s) : type_(kString) { - new (&data_.s) std::string(s); + new (&data_.s) std::string(s); } - Variant(const Variant& v) : type_(v.type_) { - Init(v, data_); - } + Variant(const Variant& v) : type_(v.type_) { Init(v, data_); } Variant& operator=(const Variant& v); - Variant(Variant&& rhs) : type_(kNull) { - *this = std::move(rhs); - } + Variant(Variant&& rhs) : type_(kNull) { *this = std::move(rhs); } Variant& operator=(Variant&& v); - ~Variant() { - Destroy(type_, data_); - } + ~Variant() { Destroy(type_, data_); } Type type() const { return type_; } bool get_bool() const { return data_.b; } @@ -83,16 +77,16 @@ struct Variant { bool operator!=(const Variant& other) const { return !(*this == other); } private: - Type type_; union Data { - bool b; - uint64_t i; - double d; - // Current version of MS compiler not C++11 compliant so can not put std::string + bool b; + uint64_t i; + double d; + // Current version of MS compiler not C++11 compliant so can not put + // std::string // however, even then we still need the rest of the maintenance. - char s[sizeof(std::string)]; + char s[sizeof(std::string)]; } data_; // Avoid type_punned aliasing problem diff --git a/include/utilities/backupable_db.h b/include/utilities/backupable_db.h index 71411dd84..4ee239cc7 100644 --- a/include/utilities/backupable_db.h +++ b/include/utilities/backupable_db.h @@ -11,6 +11,7 @@ #include "pragma_error.h" -ROCKSDB_WARNING("Warning: This file was moved to rocksdb/utilities/backupable_db.h") +ROCKSDB_WARNING( + "Warning: This file was moved to rocksdb/utilities/backupable_db.h") #include "rocksdb/utilities/backupable_db.h" diff --git a/include/utilities/pragma_error.h b/include/utilities/pragma_error.h index c6bd5a211..05254704c 100644 --- a/include/utilities/pragma_error.h +++ b/include/utilities/pragma_error.h @@ -13,25 +13,24 @@ #define RDB_STR__(x) #x #define RDB_STR(x) RDB_STR__(x) - #if defined(ROCKSDB_PLATFORM_POSIX) // Wrap unportable warning macro -# define ROCKSDB_WARNING(x) _Pragma(RDB_STR(GCC warning(x))) - +#define ROCKSDB_WARNING(x) _Pragma(RDB_STR(GCC warning(x))) #elif defined(OS_WIN) // Wrap unportable warning macro #if defined(_MSC_VER) - // format it according to visual studio output (to get source lines and warnings in the IDE) - #define ROCKSDB_WARNING(x) __pragma( message(__FILE__ "(" RDB_STR(__LINE__) ") : warning: " x) ) +// format it according to visual studio output (to get source lines and warnings +// in the IDE) +#define ROCKSDB_WARNING(x) \ + __pragma(message(__FILE__ "(" RDB_STR(__LINE__) ") : warning: " x)) #else - // make #warning into #pragma GCC warning gcc 4.7+ and clang 3.2+ supported - #define ROCKSDB_WARNING(x) _Pragma(RDB_STR(GCC warning(x))) +// make #warning into #pragma GCC warning gcc 4.7+ and clang 3.2+ supported +#define ROCKSDB_WARNING(x) _Pragma(RDB_STR(GCC warning(x))) #endif - #endif #endif // STORAGE_LEVELDB_UTILITIES_PRAGMA_ERROR_H_ diff --git a/port/dirent.h b/port/dirent.h index db6cdd54f..ee4ded143 100644 --- a/port/dirent.h +++ b/port/dirent.h @@ -13,15 +13,15 @@ #define STORAGE_LEVELDB_PORT_DIRENT_H_ #ifdef ROCKSDB_PLATFORM_POSIX -# include -# include +#include +#include #elif defined(OS_WIN) namespace rocksdb { namespace port { struct dirent { - char d_name[_MAX_PATH]; /* filename */ + char d_name[_MAX_PATH]; /* filename */ }; struct DIR; @@ -32,7 +32,7 @@ dirent* readdir(DIR* dirp); int closedir(DIR* dirp); -} // namespace port +} // namespace port using port::dirent; using port::DIR; @@ -40,12 +40,8 @@ using port::opendir; using port::readdir; using port::closedir; -} // namespace rocksdb - -#endif - - -#endif // STORAGE_LEVELDB_PORT_DIRENT_H_ - +} // namespace rocksdb +#endif // OS_WIN +#endif // STORAGE_LEVELDB_PORT_DIRENT_H_ diff --git a/port/port.h b/port/port.h index 5d64aea9b..e949cd286 100644 --- a/port/port.h +++ b/port/port.h @@ -15,8 +15,8 @@ // porting to a new platform, see "port_example.h" for documentation // of what the new port_.h file must provide. #if defined(ROCKSDB_PLATFORM_POSIX) -# include "port/port_posix.h" +#include "port/port_posix.h" #elif defined(OS_WIN) -# include "port/win/port_win.h" +#include "port/win/port_win.h" #endif diff --git a/port/port_posix.h b/port/port_posix.h index ce3387795..45a9cf3b2 100644 --- a/port/port_posix.h +++ b/port/port_posix.h @@ -11,7 +11,8 @@ #pragma once -// size_t printf formatting named in the manner of C99 standard formatting strings such as PRIu64 +// size_t printf formatting named in the manner of C99 standard formatting +// strings such as PRIu64 // in fact, we could use that one #define ROCKSDB_PRIszt "zu" diff --git a/port/sys_time.h b/port/sys_time.h index 0ebf298aa..6c23d8e50 100644 --- a/port/sys_time.h +++ b/port/sys_time.h @@ -7,7 +7,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. See the AUTHORS file for names of contributors. -// This file is a portable substitute for sys/time.h which does not exist on Windows +// This file is a portable substitute for sys/time.h which does not exist on +// Windows #ifndef STORAGE_LEVELDB_PORT_SYS_TIME_H_ #define STORAGE_LEVELDB_PORT_SYS_TIME_H_ @@ -22,18 +23,16 @@ namespace port { // Avoid including winsock2.h for this definition typedef struct timeval { - long tv_sec; - long tv_usec; + long tv_sec; + long tv_usec; } timeval; void gettimeofday(struct timeval* tv, struct timezone* tz); -inline -struct tm* localtime_r(const time_t *timep, struct tm *result) { - errno_t ret = localtime_s(result, timep); - return (ret == 0) ? result : NULL; +inline struct tm* localtime_r(const time_t* timep, struct tm* result) { + errno_t ret = localtime_s(result, timep); + return (ret == 0) ? result : NULL; } - } using port::timeval; @@ -42,8 +41,8 @@ using port::localtime_r; } #else -# include -# include +#include +#include #endif -#endif // STORAGE_LEVELDB_PORT_SYS_TIME_H_ +#endif // STORAGE_LEVELDB_PORT_SYS_TIME_H_ diff --git a/port/util_logger.h b/port/util_logger.h index d3cff21b8..dbb67173f 100644 --- a/port/util_logger.h +++ b/port/util_logger.h @@ -14,11 +14,10 @@ // porting to a new platform, see "port_example.h" for documentation // of what the new port_.h file must provide. - #if defined(ROCKSDB_PLATFORM_POSIX) -# include "util/posix_logger.h" +#include "util/posix_logger.h" #elif defined(OS_WIN) -# include "port/win/win_logger.h" +#include "port/win/win_logger.h" #endif -#endif // STORAGE_LEVELDB_PORT_UTIL_LOGGER_H_ +#endif // STORAGE_LEVELDB_PORT_UTIL_LOGGER_H_ diff --git a/port/win/env_win.cc b/port/win/env_win.cc index d29a63a6e..31ce7b5bf 100644 --- a/port/win/env_win.cc +++ b/port/win/env_win.cc @@ -19,7 +19,6 @@ #include #include - #include "rocksdb/env.h" #include "rocksdb/slice.h" @@ -34,38 +33,29 @@ #include "util/thread_status_updater.h" #include "util/thread_status_util.h" - +#include // For UUID generation #include -#include // For UUID generation // This is only set from db_stress.cc and for testing only. // If non-zero, kill at various points in source code with probability 1/this int rocksdb_kill_odds = 0; -namespace rocksdb -{ +namespace rocksdb { std::string GetWindowsErrSz(DWORD err) { LPSTR lpMsgBuf; - FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - err, - 0, // Default language - reinterpret_cast(&lpMsgBuf), - 0, - NULL - ); + FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, err, + 0, // Default language + reinterpret_cast(&lpMsgBuf), 0, NULL); std::string Err = lpMsgBuf; LocalFree(lpMsgBuf); return Err; } -namespace -{ +namespace { const size_t c_OneMB = (1 << 20); @@ -73,44 +63,36 @@ ThreadStatusUpdater* CreateThreadStatusUpdater() { return new ThreadStatusUpdater(); } - // A wrapper for fadvise, if the platform doesn't support fadvise, // it will simply return Status::NotSupport. int Fadvise(int fd, off_t offset, size_t len, int advice) { - return 0; // simply do nothing. + return 0; // simply do nothing. } -inline -Status IOErrorFromWindowsError(const std::string& context, DWORD err) { +inline Status IOErrorFromWindowsError(const std::string& context, DWORD err) { return Status::IOError(context, GetWindowsErrSz(err)); } -inline -Status IOErrorFromLastWindowsError(const std::string& context) { +inline Status IOErrorFromLastWindowsError(const std::string& context) { return IOErrorFromWindowsError(context, GetLastError()); } -inline -Status IOError(const std::string& context, int err_number) { +inline Status IOError(const std::string& context, int err_number) { return Status::IOError(context, strerror(err_number)); } // TODO(sdong): temp logging. Need to help debugging. Remove it when // the feature is proved to be stable. inline void PrintThreadInfo(size_t thread_id, size_t terminatingId) { - fprintf(stdout, "Bg thread %Iu terminates %Iu\n", thread_id, terminatingId); } // returns the ID of the current process -inline -int current_process_id() { - return _getpid(); -} +inline int current_process_id() { return _getpid(); } #ifdef NDEBUG - // empty in release build - #define TEST_KILL_RANDOM(rocksdb_kill_odds) +// empty in release build +#define TEST_KILL_RANDOM(rocksdb_kill_odds) #else // Kill the process with probablity 1/odds for testing. @@ -120,12 +102,11 @@ void TestKillRandom(int odds, const std::string& srcfile, int srcline) { assert(odds > 0); bool crash = r.OneIn(odds); - if (crash) - { - fprintf(stdout, "Crashing at %s:%d\n", srcfile.c_str(), srcline); - fflush(stdout); - std::string* p_str = nullptr; - p_str->c_str(); + if (crash) { + fprintf(stdout, "Crashing at %s:%d\n", srcfile.c_str(), srcline); + fflush(stdout); + std::string* p_str = nullptr; + p_str->c_str(); } } @@ -134,11 +115,12 @@ void TestKillRandom(int odds, const std::string& srcfile, int srcline) { #define REDUCE_ODDS 2 #define REDUCE_ODDS2 4 -#define TEST_KILL_RANDOM(rocksdb_kill_odds) { \ - if (rocksdb_kill_odds > 0) { \ - TestKillRandom(rocksdb_kill_odds, __FILE__, __LINE__); \ - } \ -} +#define TEST_KILL_RANDOM(rocksdb_kill_odds) \ + { \ + if (rocksdb_kill_odds > 0) { \ + TestKillRandom(rocksdb_kill_odds, __FILE__, __LINE__); \ + } \ + } #endif @@ -146,18 +128,22 @@ void TestKillRandom(int odds, const std::string& srcfile, int srcline) { const auto CloseHandleFunc = [](HANDLE h) { ::CloseHandle(h); }; typedef std::unique_ptr UniqueCloseHandlePtr; - -// We preserve the original name of this interface to denote the original idea behind it. +// We preserve the original name of this interface to denote the original idea +// behind it. // All reads happen by a specified offset and pwrite interface does not change -// the position of the file pointer. Judging from the man page and errno it does execute -// lseek atomically to return the position of the file back where it was. WriteFile() does not -// have this capability. Therefore, for both pread and pwrite the pointer is advanced to the next position +// the position of the file pointer. Judging from the man page and errno it does +// execute +// lseek atomically to return the position of the file back where it was. +// WriteFile() does not +// have this capability. Therefore, for both pread and pwrite the pointer is +// advanced to the next position // which is fine for writes because they are (should be) sequential. -// Because all the reads/writes happen by the specified offset, the caller in theory should not +// Because all the reads/writes happen by the specified offset, the caller in +// theory should not // rely on the current file offset. -SSIZE_T pwrite(HANDLE hFile, const char * src, size_t numBytes, uint64_t offset) { - - OVERLAPPED overlapped = { 0 }; +SSIZE_T pwrite(HANDLE hFile, const char* src, size_t numBytes, + uint64_t offset) { + OVERLAPPED overlapped = {0}; ULARGE_INTEGER offsetUnion; offsetUnion.QuadPart = offset; @@ -169,19 +155,17 @@ SSIZE_T pwrite(HANDLE hFile, const char * src, size_t numBytes, uint64_t offset) unsigned long bytesWritten = 0; if (FALSE == WriteFile(hFile, src, numBytes, &bytesWritten, &overlapped)) { - result = -1; - } - else { - result = bytesWritten; + result = -1; + } else { + result = bytesWritten; } return result; } // See comments for pwrite above -SSIZE_T pread(HANDLE hFile, char * src, size_t numBytes, uint64_t offset) { - - OVERLAPPED overlapped = { 0 }; +SSIZE_T pread(HANDLE hFile, char* src, size_t numBytes, uint64_t offset) { + OVERLAPPED overlapped = {0}; ULARGE_INTEGER offsetUnion; offsetUnion.QuadPart = offset; @@ -193,106 +177,95 @@ SSIZE_T pread(HANDLE hFile, char * src, size_t numBytes, uint64_t offset) { unsigned long bytesRead = 0; if (FALSE == ReadFile(hFile, src, numBytes, &bytesRead, &overlapped)) { - return -1; - } - else { - result = bytesRead; + return -1; + } else { + result = bytesRead; } return result; } -// Note the below two do not set errno because they are used only here in this file -// on a Windows handle and, therefore, not necessary. Translating GetLastError() to errno +// Note the below two do not set errno because they are used only here in this +// file +// on a Windows handle and, therefore, not necessary. Translating GetLastError() +// to errno // is a sad business -inline -int fsync(HANDLE hFile) { - +inline int fsync(HANDLE hFile) { if (!FlushFileBuffers(hFile)) { - return -1; + return -1; } return 0; } -inline -size_t TruncateToPageBoundary(size_t page_size, size_t s) { +inline size_t TruncateToPageBoundary(size_t page_size, size_t s) { s -= (s & (page_size - 1)); assert((s % page_size) == 0); return s; } // Roundup x to a multiple of y -inline -size_t Roundup(size_t x, size_t y) { - return ((x + y - 1) / y) * y; -} - +inline size_t Roundup(size_t x, size_t y) { return ((x + y - 1) / y) * y; } // SetFileInformationByHandle() is capable of fast pre-allocates. // However, this does not change the file end position unless the file is // truncated and the pre-allocated space is not considered filled with zeros. -inline -Status fallocate(const std::string& filename, HANDLE hFile, uint64_t to_size) { - +inline Status fallocate(const std::string& filename, HANDLE hFile, + uint64_t to_size) { Status status; FILE_ALLOCATION_INFO alloc_info; alloc_info.AllocationSize.QuadPart = to_size; - if (!SetFileInformationByHandle(hFile, FileAllocationInfo, &alloc_info, sizeof(FILE_ALLOCATION_INFO))) { + if (!SetFileInformationByHandle(hFile, FileAllocationInfo, &alloc_info, + sizeof(FILE_ALLOCATION_INFO))) { auto lastError = GetLastError(); - status = IOErrorFromWindowsError("Failed to pre-allocate space: " + filename, lastError); + status = IOErrorFromWindowsError( + "Failed to pre-allocate space: " + filename, lastError); } return status; } -inline -Status ftruncate(const std::string& filename, HANDLE hFile, uint64_t toSize) { - +inline Status ftruncate(const std::string& filename, HANDLE hFile, + uint64_t toSize) { Status status; FILE_END_OF_FILE_INFO end_of_file; end_of_file.EndOfFile.QuadPart = toSize; - if (!SetFileInformationByHandle(hFile, FileEndOfFileInfo, &end_of_file, sizeof(FILE_END_OF_FILE_INFO))) { + if (!SetFileInformationByHandle(hFile, FileEndOfFileInfo, &end_of_file, + sizeof(FILE_END_OF_FILE_INFO))) { auto lastError = GetLastError(); - status = IOErrorFromWindowsError("Failed to Set end of file: " + filename, lastError); + status = IOErrorFromWindowsError("Failed to Set end of file: " + filename, + lastError); } return status; } class WinRandomRWFile : public RandomRWFile { - const std::string filename_; - HANDLE hFile_; - bool pending_fsync_; - -public: - - WinRandomRWFile(const std::string& fname, HANDLE hFile, const EnvOptions& options) - : filename_(fname), - hFile_(hFile), - pending_fsync_(false) { + HANDLE hFile_; + bool pending_fsync_; + public: + WinRandomRWFile(const std::string& fname, HANDLE hFile, + const EnvOptions& options) + : filename_(fname), hFile_(hFile), pending_fsync_(false) { assert(!options.use_mmap_writes && !options.use_mmap_reads); } ~WinRandomRWFile() { - if (hFile_ != INVALID_HANDLE_VALUE && hFile_ != NULL) { - ::CloseHandle(hFile_); + ::CloseHandle(hFile_); } } virtual Status Write(uint64_t offset, const Slice& data) override { - const char* src = data.data(); size_t left = data.size(); - pending_fsync_ = true; SSIZE_T done = 0; @@ -302,7 +275,8 @@ public: } if (done < 0) { - return IOErrorFromWindowsError("pwrite failed to: " + filename_, GetLastError()); + return IOErrorFromWindowsError("pwrite failed to: " + filename_, + GetLastError()); } IOSTATS_ADD(bytes_written, done); @@ -314,8 +288,8 @@ public: return Status::OK(); } - virtual Status Read(uint64_t offset, size_t n, Slice* result, char* scratch) const override { - + virtual Status Read(uint64_t offset, size_t n, Slice* result, + char* scratch) const override { Status s; SSIZE_T r = -1; @@ -323,14 +297,13 @@ public: size_t left = n; while (left > 0) { - { IOSTATS_TIMER_GUARD(read_nanos); r = pread(hFile_, ptr, n, offset); } if (r <= 0) { - break; + break; } ptr += r; @@ -343,25 +316,26 @@ public: *result = Slice(scratch, (r < 0) ? 0 : r); if (r < 0) { - s = IOErrorFromWindowsError("pread failed from: " + filename_, GetLastError()); + s = IOErrorFromWindowsError("pread failed from: " + filename_, + GetLastError()); } return s; } virtual Status Close() override { - Status s = Status::OK(); if (hFile_ != INVALID_HANDLE_VALUE && ::CloseHandle(hFile_) == FALSE) { - s = IOErrorFromWindowsError("Failed to close file: " + filename_, GetLastError()); + s = IOErrorFromWindowsError("Failed to close file: " + filename_, + GetLastError()); } hFile_ = INVALID_HANDLE_VALUE; return s; } virtual Status Sync() override { - if (pending_fsync_ && fsync(hFile_) < 0) { - return IOErrorFromWindowsError("Failed to Sync() buffers for: " + filename_, GetLastError()); + return IOErrorFromWindowsError( + "Failed to Sync() buffers for: " + filename_, GetLastError()); } pending_fsync_ = false; return Status::OK(); @@ -369,38 +343,39 @@ public: virtual Status Fsync() override { if (pending_fsync_ && fsync(hFile_) < 0) { - return IOErrorFromWindowsError("Failed to Fsync() for: " + filename_, GetLastError()); + return IOErrorFromWindowsError("Failed to Fsync() for: " + filename_, + GetLastError()); } pending_fsync_ = false; return Status::OK(); } - + virtual Status Allocate(off_t offset, off_t len) override { IOSTATS_TIMER_GUARD(allocate_nanos); return fallocate(filename_, hFile_, len); } }; - // mmap() based random-access class WinMmapReadableFile : public RandomAccessFile { + const std::string fileName_; + HANDLE hFile_; + HANDLE hMap_; - const std::string fileName_; - HANDLE hFile_; - HANDLE hMap_; + const void* mapped_region_; + const size_t length_; - const void* mapped_region_; - const size_t length_; - -public: + public: // mapped_region_[0,length-1] contains the mmapped contents of the file. - WinMmapReadableFile(const std::string &fileName, HANDLE hFile, HANDLE hMap, const void* mapped_region, size_t length) - : fileName_(fileName), hFile_(hFile), hMap_(hMap), mapped_region_(mapped_region), length_(length) { - - } + WinMmapReadableFile(const std::string& fileName, HANDLE hFile, HANDLE hMap, + const void* mapped_region, size_t length) + : fileName_(fileName), + hFile_(hFile), + hMap_(hMap), + mapped_region_(mapped_region), + length_(length) {} ~WinMmapReadableFile() { - BOOL ret = ::UnmapViewOfFile(mapped_region_); assert(ret); @@ -411,16 +386,16 @@ public: assert(ret); } - virtual Status Read(uint64_t offset, size_t n, Slice* result, char* scratch) const override { - + virtual Status Read(uint64_t offset, size_t n, Slice* result, + char* scratch) const override { Status s; if (offset + n > length_) { - *result = Slice(); - s = IOError(fileName_, EINVAL); - } - else { - *result = Slice(reinterpret_cast(mapped_region_) + offset, n); + *result = Slice(); + s = IOError(fileName_, EINVAL); + } else { + *result = + Slice(reinterpret_cast(mapped_region_) + offset, n); } return s; } @@ -435,31 +410,35 @@ public: // file before reading from it, or for log files, the reading code // knows enough to skip zero suffixes. class WinMmapFile : public WritableFile { -private: - + private: const std::string filename_; - HANDLE hFile_; - HANDLE hMap_; + HANDLE hFile_; + HANDLE hMap_; - const size_t page_size_; // We flush the mapping view in page_size increments. We may decide if this is a memory page size or SSD page size - const size_t allocation_granularity_; // View must start at such a granularity - size_t mapping_size_; // We want file mapping to be of a specific size because then the file is expandable - size_t view_size_; // How much memory to map into a view at a time + const size_t page_size_; // We flush the mapping view in page_size + // increments. We may decide if this is a memory + // page size or SSD page size + const size_t + allocation_granularity_; // View must start at such a granularity + size_t mapping_size_; // We want file mapping to be of a specific size + // because then the file is expandable + size_t view_size_; // How much memory to map into a view at a time - char* mapped_begin_; // Must begin at the file offset that is aligned with allocation_granularity_ - char* mapped_end_; - char* dst_; // Where to write next (in range [mapped_begin_,mapped_end_]) - char* last_sync_; // Where have we synced up to + char* mapped_begin_; // Must begin at the file offset that is aligned with + // allocation_granularity_ + char* mapped_end_; + char* dst_; // Where to write next (in range [mapped_begin_,mapped_end_]) + char* last_sync_; // Where have we synced up to - uint64_t file_offset_; // Offset of mapped_begin_ in file + uint64_t file_offset_; // Offset of mapped_begin_ in file // Do we have unsynced writes? - bool pending_sync_; + bool pending_sync_; // Can only truncate or reserve to a sector size aligned if // used on files that are opened with Unbuffered I/O Status TruncateFile(uint64_t toSize) { - return ftruncate(filename_, hFile_, toSize); + return ftruncate(filename_, hFile_, toSize); } // Can only truncate or reserve to a sector size aligned if @@ -471,15 +450,13 @@ private: return fallocate(filename_, hFile_, toSize); } - Status UnmapCurrentRegion() { - Status status; if (mapped_begin_ != nullptr) { - if (!::UnmapViewOfFile(mapped_begin_)) { - status = IOErrorFromWindowsError("Failed to unmap file view: " + filename_, GetLastError()); + status = IOErrorFromWindowsError( + "Failed to unmap file view: " + filename_, GetLastError()); } // UnmapView automatically sends data to disk but not the metadata @@ -487,15 +464,15 @@ private: // therefore, we donot need separate flag for metadata pending_sync_ = false; mapped_begin_ = nullptr; - mapped_end_ = nullptr; - dst_ = nullptr; - last_sync_ = nullptr; + mapped_end_ = nullptr; + dst_ = nullptr; + last_sync_ = nullptr; // Move on to the next portion of the file file_offset_ += view_size_; // Increase the amount we map the next time, but capped at 1MB - view_size_ *= 2; + view_size_ *= 2; view_size_ = std::min(view_size_, c_OneMB); } @@ -503,20 +480,21 @@ private: } Status MapNewRegion() { - Status status; assert(mapped_begin_ == nullptr); size_t minMappingSize = file_offset_ + view_size_; - // Check if we need to create a new mapping since we want to write beyond the current one + // Check if we need to create a new mapping since we want to write beyond + // the current one // If the mapping view is now too short - // CreateFileMapping will extend the size of the file automatically if the mapping size is greater than - // the current length of the file, which reserves the space and makes writing faster, except, windows can not map an empty file. + // CreateFileMapping will extend the size of the file automatically if the + // mapping size is greater than + // the current length of the file, which reserves the space and makes + // writing faster, except, windows can not map an empty file. // Thus the first time around we must actually extend the file ourselves if (hMap_ == NULL || minMappingSize > mapping_size_) { - if (NULL == hMap_) { // Creating mapping for the first time so reserve the space on disk status = ReserveFileSpace(minMappingSize); @@ -532,14 +510,16 @@ private: hMap_ = NULL; } - // Calculate the new mapping size which will hopefully reserve space for several consecutive sliding views + // Calculate the new mapping size which will hopefully reserve space for + // several consecutive sliding views // Query preallocation block size if set size_t preallocationBlockSize = 0; - size_t lastAllocatedBlockSize = 0; // Not used + size_t lastAllocatedBlockSize = 0; // Not used GetPreallocationStatus(&preallocationBlockSize, &lastAllocatedBlockSize); if (preallocationBlockSize) { - preallocationBlockSize = Roundup(preallocationBlockSize, allocation_granularity_); + preallocationBlockSize = + Roundup(preallocationBlockSize, allocation_granularity_); } else { preallocationBlockSize = 2 * view_size_; } @@ -551,106 +531,112 @@ private: hMap_ = CreateFileMappingA( hFile_, - NULL, // Security attributes - PAGE_READWRITE, // There is not a write only mode for mapping - mappingSize.HighPart, // Enable mapping the whole file but the actual amount mapped is determined by MapViewOfFile + NULL, // Security attributes + PAGE_READWRITE, // There is not a write only mode for mapping + mappingSize.HighPart, // Enable mapping the whole file but the actual + // amount mapped is determined by MapViewOfFile mappingSize.LowPart, NULL); // Mapping name - if (NULL == hMap_) { - return IOErrorFromWindowsError("WindowsMmapFile failed to create file mapping for: " + filename_, GetLastError()); - } + if (NULL == hMap_) { + return IOErrorFromWindowsError( + "WindowsMmapFile failed to create file mapping for: " + filename_, + GetLastError()); + } } ULARGE_INTEGER offset; offset.QuadPart = file_offset_; // View must begin at the granularity aligned offset - mapped_begin_ = reinterpret_cast(MapViewOfFileEx(hMap_, FILE_MAP_WRITE, offset.HighPart, offset.LowPart, view_size_, NULL)); + mapped_begin_ = reinterpret_cast( + MapViewOfFileEx(hMap_, FILE_MAP_WRITE, offset.HighPart, offset.LowPart, + view_size_, NULL)); if (!mapped_begin_) { - status = IOErrorFromWindowsError("WindowsMmapFile failed to map file view: " + filename_, GetLastError()); + status = IOErrorFromWindowsError( + "WindowsMmapFile failed to map file view: " + filename_, + GetLastError()); } else { - mapped_end_ = mapped_begin_ + view_size_; - dst_ = mapped_begin_; - last_sync_ = mapped_begin_; - pending_sync_ = false; + mapped_end_ = mapped_begin_ + view_size_; + dst_ = mapped_begin_; + last_sync_ = mapped_begin_; + pending_sync_ = false; } return status; } -public: - - WinMmapFile(const std::string& fname, HANDLE hFile, size_t page_size, size_t allocation_granularity, const EnvOptions& options) + public: + WinMmapFile(const std::string& fname, HANDLE hFile, size_t page_size, + size_t allocation_granularity, const EnvOptions& options) : filename_(fname), - hFile_(hFile), - hMap_(NULL), - page_size_(page_size), - allocation_granularity_(allocation_granularity), - mapping_size_(0), - view_size_(0), - mapped_begin_(nullptr), - mapped_end_(nullptr), - dst_(nullptr), - last_sync_(nullptr), - file_offset_(0), - pending_sync_(false) { + hFile_(hFile), + hMap_(NULL), + page_size_(page_size), + allocation_granularity_(allocation_granularity), + mapping_size_(0), + view_size_(0), + mapped_begin_(nullptr), + mapped_end_(nullptr), + dst_(nullptr), + last_sync_(nullptr), + file_offset_(0), + pending_sync_(false) { + // Allocation granularity must be obtained from GetSystemInfo() and must be + // a power of two. + assert(allocation_granularity > 0); + assert((allocation_granularity & (allocation_granularity - 1)) == 0); - // Allocation granularity must be obtained from GetSystemInfo() and must be a power of two. - assert(allocation_granularity > 0); - assert((allocation_granularity & (allocation_granularity - 1)) == 0); + assert(page_size > 0); + assert((page_size & (page_size - 1)) == 0); - assert(page_size > 0); - assert((page_size & (page_size - 1)) == 0); + // Only for memory mapped writes + assert(options.use_mmap_writes); - // Only for memory mapped writes - assert(options.use_mmap_writes); + // Make sure buffering is not disabled. It is ignored for mapping + // purposes but also imposes restriction on moving file position + // it is not a problem so much with reserving space since it is probably a + // factor + // of allocation_granularity but we also want to truncate the file in + // Close() at + // arbitrary position so we do not have to feel this with zeros. + assert(options.use_os_buffer); - // Make sure buffering is not disabled. It is ignored for mapping - // purposes but also imposes restriction on moving file position - // it is not a problem so much with reserving space since it is probably a factor - // of allocation_granularity but we also want to truncate the file in Close() at - // arbitrary position so we do not have to feel this with zeros. - assert(options.use_os_buffer); - - // View size must be both the multiple of allocation_granularity AND the page size - if ((allocation_granularity_ % page_size_) == 0) { - view_size_ = 2 * allocation_granularity; - } else if ((page_size_ % allocation_granularity_) == 0) { - view_size_ = 2 * page_size_; - } else { - // we can multiply them together - assert(false); - } + // View size must be both the multiple of allocation_granularity AND the + // page size + if ((allocation_granularity_ % page_size_) == 0) { + view_size_ = 2 * allocation_granularity; + } else if ((page_size_ % allocation_granularity_) == 0) { + view_size_ = 2 * page_size_; + } else { + // we can multiply them together + assert(false); + } } - ~WinMmapFile() { - if (hFile_) { - this->Close(); - } + if (hFile_) { + this->Close(); + } } virtual Status Append(const Slice& data) override { - const char* src = data.data(); size_t left = data.size(); while (left > 0) { - assert(mapped_begin_ <= dst_); size_t avail = mapped_end_ - dst_; if (avail == 0) { + Status s = UnmapCurrentRegion(); + if (s.ok()) { + s = MapNewRegion(); + } - Status s = UnmapCurrentRegion(); - if (s.ok()) { - s = MapNewRegion(); - } - - if (!s.ok()) { - return s; - } + if (!s.ok()) { + return s; + } } size_t n = std::min(left, avail); @@ -666,7 +652,6 @@ public: } virtual Status Close() override { - Status s; assert(NULL != hFile_); @@ -678,12 +663,12 @@ public: s = UnmapCurrentRegion(); - if (NULL != hMap_ ) { - + if (NULL != hMap_) { BOOL ret = ::CloseHandle(hMap_); if (!ret && s.ok()) { - auto lastError = GetLastError(); - s = IOErrorFromWindowsError("Failed to Close mapping for file: " + filename_, lastError); + auto lastError = GetLastError(); + s = IOErrorFromWindowsError( + "Failed to Close mapping for file: " + filename_, lastError); } hMap_ = NULL; @@ -695,37 +680,38 @@ public: hFile_ = NULL; if (!ret && s.ok()) { - auto lastError = GetLastError(); - s = IOErrorFromWindowsError("Failed to close file map handle: " + filename_, lastError); + auto lastError = GetLastError(); + s = IOErrorFromWindowsError( + "Failed to close file map handle: " + filename_, lastError); } return s; } - virtual Status Flush() override { - return Status::OK(); - } + virtual Status Flush() override { return Status::OK(); } // Flush only data virtual Status Sync() override { - Status s; // Some writes occurred since last sync if (pending_sync_) { - assert(mapped_begin_); assert(dst_); assert(dst_ > mapped_begin_); assert(dst_ < mapped_end_); - size_t page_begin = TruncateToPageBoundary(page_size_, last_sync_ - mapped_begin_); - size_t page_end = TruncateToPageBoundary(page_size_, dst_ - mapped_begin_ - 1); + size_t page_begin = + TruncateToPageBoundary(page_size_, last_sync_ - mapped_begin_); + size_t page_end = + TruncateToPageBoundary(page_size_, dst_ - mapped_begin_ - 1); last_sync_ = dst_; // Flush only the amount of that is a multiple of pages - if(!::FlushViewOfFile(mapped_begin_ + page_begin, (page_end - page_begin) + page_size_)) { - s = IOErrorFromWindowsError("Failed to FlushViewOfFile: " + filename_, GetLastError()); + if (!::FlushViewOfFile(mapped_begin_ + page_begin, + (page_end - page_begin) + page_size_)) { + s = IOErrorFromWindowsError("Failed to FlushViewOfFile: " + filename_, + GetLastError()); } pending_sync_ = false; @@ -738,7 +724,6 @@ public: * Flush data as well as metadata to stable storage. */ virtual Status Fsync() override { - Status s; // Flush metadata if pending @@ -749,7 +734,8 @@ public: // Flush metadata if (s.ok() && pending) { if (!::FlushFileBuffers(hFile_)) { - s = IOErrorFromWindowsError("Failed to FlushFileBuffers: " + filename_, GetLastError()); + s = IOErrorFromWindowsError("Failed to FlushFileBuffers: " + filename_, + GetLastError()); } } @@ -762,74 +748,55 @@ public: * to extend file by map_size every time. */ virtual uint64_t GetFileSize() override { - size_t used = dst_ - mapped_begin_; return file_offset_ + used; } virtual Status InvalidateCache(size_t offset, size_t length) override { - return Status::OK(); } virtual Status Allocate(off_t offset, off_t len) override { - return Status::OK(); } }; - // This class is to manage an aligned user // allocated buffer for unbuffered I/O purposes // though it does not make a difference if you need a buffer. class AlignedBuffer { - const size_t alignment_; std::unique_ptr buf_; - size_t capacity_; - size_t cursize_; - char* bufstart_; - -public: - - explicit AlignedBuffer(size_t alignment) : - alignment_(alignment), - capacity_(0), - cursize_(0), - bufstart_(nullptr) { + size_t capacity_; + size_t cursize_; + char* bufstart_; + public: + explicit AlignedBuffer(size_t alignment) + : alignment_(alignment), capacity_(0), cursize_(0), bufstart_(nullptr) { assert(alignment > 0); assert((alignment & (alignment - 1)) == 0); } - size_t GetAlignment() const { - return alignment_; - } + size_t GetAlignment() const { return alignment_; } - size_t GetCapacity() const { - return capacity_; - } + size_t GetCapacity() const { return capacity_; } - size_t GetCurrentSize() const { - return cursize_; - } + size_t GetCurrentSize() const { return cursize_; } - const char* GetBufferStart() const { - return bufstart_; - } + const char* GetBufferStart() const { return bufstart_; } - void Clear() { - cursize_ = 0; - } + void Clear() { cursize_ = 0; } // Allocates a new buffer and sets bufstart_ to the aligned first byte void AllocateNewBuffer(size_t requestedCapacity) { - size_t size = Roundup(requestedCapacity, alignment_); buf_.reset(new char[size + alignment_]); char* p = buf_.get(); - bufstart_ = reinterpret_cast((reinterpret_cast(p)+(alignment_ - 1)) & ~static_cast(alignment_ - 1)); + bufstart_ = reinterpret_cast( + (reinterpret_cast(p) + (alignment_ - 1)) & + ~static_cast(alignment_ - 1)); capacity_ = size; cursize_ = 0; } @@ -837,7 +804,6 @@ public: // Used for write // Returns the number of bytes appended size_t Append(const char* src, size_t append_size) { - size_t buffer_remaining = capacity_ - cursize_; size_t to_copy = std::min(append_size, buffer_remaining); @@ -878,31 +844,29 @@ public: } // Returns place to start writing - char* GetDestination() { - return bufstart_ + cursize_; - } + char* GetDestination() { return bufstart_ + cursize_; } - void SetSize(size_t cursize) { - cursize_ = cursize; - } + void SetSize(size_t cursize) { cursize_ = cursize; } }; - -class WinSequentialFile: public SequentialFile { -private: +class WinSequentialFile : public SequentialFile { + private: const std::string filename_; - FILE* file_; - int fd_; - bool use_os_buffer_; + FILE* file_; + int fd_; + bool use_os_buffer_; -public: - WinSequentialFile(const std::string& fname, FILE* f, const EnvOptions& options) : - filename_(fname), file_(f), fd_(fileno(f)), use_os_buffer_(options.use_os_buffer) { - } - - virtual ~WinSequentialFile() { + public: + WinSequentialFile(const std::string& fname, FILE* f, + const EnvOptions& options) + : filename_(fname), + file_(f), + fd_(fileno(f)), + use_os_buffer_(options.use_os_buffer) {} + + virtual ~WinSequentialFile() { assert(file_ != nullptr); - fclose(file_); + fclose(file_); } virtual Status Read(size_t n, Slice* result, char* scratch) override { @@ -912,7 +876,7 @@ public: // read() and fread() as well as write/fwrite do not guarantee // to fullfil the entire request in one call thus the loop. do { - r = fread(scratch, 1, n, file_); + r = fread(scratch, 1, n, file_); } while (r == 0 && ferror(file_)); IOSTATS_ADD(bytes_read, r); @@ -920,13 +884,12 @@ public: *result = Slice(scratch, r); if (r < n) { - if (feof(file_)) { // We leave status as ok if we hit the end of the file // We also clear the error so that the reads can continue // if a new data is written to the file clearerr(file_); - } else { + } else { // A partial read with an error: return a non-ok status s = Status::IOError(filename_, strerror(errno)); } @@ -937,37 +900,34 @@ public: virtual Status Skip(uint64_t n) override { if (fseek(file_, n, SEEK_CUR)) { - return IOError(filename_, errno); + return IOError(filename_, errno); } return Status::OK(); } - virtual Status InvalidateCache(size_t offset, size_t length) override { - return Status::OK(); - } + virtual Status InvalidateCache(size_t offset, size_t length) override { + return Status::OK(); + } }; // pread() based random-access -class WinRandomAccessFile: public RandomAccessFile { - const std::string filename_; - HANDLE hFile_; - const bool use_os_buffer_; - mutable std::mutex buffer_mut_; - mutable AlignedBuffer buffer_; - mutable uint64_t buffered_start_; // file offset set that is currently buffered - -public: - - WinRandomAccessFile(const std::string& fname, - HANDLE hFile, - size_t alignment, - const EnvOptions& options) : - filename_(fname), - hFile_(hFile), - use_os_buffer_(options.use_os_buffer), - buffer_(alignment), - buffered_start_(0) { +class WinRandomAccessFile : public RandomAccessFile { + const std::string filename_; + HANDLE hFile_; + const bool use_os_buffer_; + mutable std::mutex buffer_mut_; + mutable AlignedBuffer buffer_; + mutable uint64_t + buffered_start_; // file offset set that is currently buffered + public: + WinRandomAccessFile(const std::string& fname, HANDLE hFile, size_t alignment, + const EnvOptions& options) + : filename_(fname), + hFile_(hFile), + use_os_buffer_(options.use_os_buffer), + buffer_(alignment), + buffered_start_(0) { assert(!options.use_mmap_reads); // Unbuffered access, use internal buffer for reads @@ -978,15 +938,15 @@ public: buffer_.AllocateNewBuffer(alignment * 2); } } - - virtual ~WinRandomAccessFile() { + + virtual ~WinRandomAccessFile() { if (hFile_ != NULL && hFile_ != INVALID_HANDLE_VALUE) { - ::CloseHandle(hFile_); + ::CloseHandle(hFile_); } } - virtual Status Read(uint64_t offset, size_t n, Slice* result, char* scratch) const override { - + virtual Status Read(uint64_t offset, size_t n, Slice* result, + char* scratch) const override { Status s; SSIZE_T r = -1; size_t left = n; @@ -1002,7 +962,6 @@ public: // in the buffer if (offset >= buffered_start_ && offset < (buffered_start_ + buffer_.GetCurrentSize())) { - size_t buffer_offset = offset - buffered_start_; r = buffer_.Read(dest, buffer_offset, left); assert(r >= 0); @@ -1016,20 +975,24 @@ public: if (left > 0) { // Figure out the start/end offset for reading and amount to read const size_t alignment = buffer_.GetAlignment(); - const size_t start_page_start = TruncateToPageBoundary(alignment, offset); - const size_t end_page_start = TruncateToPageBoundary(alignment, offset + left - 1); - const size_t actual_bytes_toread = (end_page_start - start_page_start) + alignment; + const size_t start_page_start = + TruncateToPageBoundary(alignment, offset); + const size_t end_page_start = + TruncateToPageBoundary(alignment, offset + left - 1); + const size_t actual_bytes_toread = + (end_page_start - start_page_start) + alignment; if (buffer_.GetCapacity() < actual_bytes_toread) { buffer_.AllocateNewBuffer(actual_bytes_toread); } else { buffer_.Clear(); } - + SSIZE_T read = 0; { IOSTATS_TIMER_GUARD(read_nanos); - read = pread(hFile_, buffer_.GetDestination(), actual_bytes_toread, start_page_start); + read = pread(hFile_, buffer_.GetDestination(), actual_bytes_toread, + start_page_start); } if (read > 0) { @@ -1050,10 +1013,10 @@ public: } } else { - r = pread(hFile_, scratch, left, offset); - if (r > 0) { - left -= r; - } + r = pread(hFile_, scratch, left, offset); + if (r > 0) { + left -= r; + } } IOSTATS_ADD_IF_POSITIVE(bytes_read, n - left); @@ -1065,67 +1028,64 @@ public: return s; } - virtual void Hint(AccessPattern pattern) override { - } + virtual void Hint(AccessPattern pattern) override {} - virtual Status InvalidateCache(size_t offset, size_t length) override { - return Status::OK(); - } + virtual Status InvalidateCache(size_t offset, size_t length) override { + return Status::OK(); + } }; // This is a sequential write class. It has been mimicked (as others) after -// the original Posix class. We add support for unbuffered I/O on windows as well -// we utilize the original buffer as an alignment buffer to write directly to file with no buffering. -// No buffering requires that the provided buffer is aligned to the physical sector size (SSD page size) and +// the original Posix class. We add support for unbuffered I/O on windows as +// well +// we utilize the original buffer as an alignment buffer to write directly to +// file with no buffering. +// No buffering requires that the provided buffer is aligned to the physical +// sector size (SSD page size) and // that all SetFilePointer() operations to occur with such an alignment. // We thus always write in sector/page size increments to the drive and leave -// the tail for the next write OR for Close() at which point we pad with zeros. No padding is required for +// the tail for the next write OR for Close() at which point we pad with zeros. +// No padding is required for // buffered access. class WinWritableFile : public WritableFile { -private: + private: + const std::string filename_; + HANDLE hFile_; + AlignedBuffer buffer_; - const std::string filename_; - HANDLE hFile_; - AlignedBuffer buffer_; + uint64_t filesize_; // How much data is actually written disk + uint64_t reservedsize_; // how far we have reserved space - uint64_t filesize_; // How much data is actually written disk - uint64_t reservedsize_; // how far we have reserved space + bool pending_sync_; - bool pending_sync_; + RateLimiter* rate_limiter_; - RateLimiter* rate_limiter_; + const bool use_os_buffer_; // Used to indicate unbuffered access, the file + // must be opened as unbuffered if false - const bool use_os_buffer_; // Used to indicate unbuffered access, the file must be opened as unbuffered if false + public: + WinWritableFile(const std::string& fname, HANDLE hFile, size_t alignment, + size_t capacity, const EnvOptions& options) + : filename_(fname), + hFile_(hFile), + buffer_(alignment), + filesize_(0), + reservedsize_(0), + pending_sync_(false), + rate_limiter_(options.rate_limiter), + use_os_buffer_(options.use_os_buffer) { + assert(!options.use_mmap_writes); -public: - - WinWritableFile(const std::string& fname, - HANDLE hFile, - size_t alignment, - size_t capacity, - const EnvOptions& options) : - filename_(fname), - hFile_(hFile), - buffer_(alignment), - filesize_(0), - reservedsize_(0), - pending_sync_(false), - rate_limiter_(options.rate_limiter), - use_os_buffer_(options.use_os_buffer) { - - assert(!options.use_mmap_writes); - - buffer_.AllocateNewBuffer(capacity); + buffer_.AllocateNewBuffer(capacity); } ~WinWritableFile() { if (NULL != hFile_ && INVALID_HANDLE_VALUE != hFile_) { - WinWritableFile::Close(); + WinWritableFile::Close(); } } virtual Status Append(const Slice& data) override { - const char* src = data.data(); assert(data.size() < INT_MAX); @@ -1139,8 +1099,7 @@ public: // Flush only when I/O is buffered if (use_os_buffer_ && - (buffer_.GetCapacity() - buffer_.GetCurrentSize()) < left) { - + (buffer_.GetCapacity() - buffer_.GetCurrentSize()) < left) { if (buffer_.GetCurrentSize() > 0) { s = Flush(); if (!s.ok()) { @@ -1156,16 +1115,15 @@ public: } // We always use the internal buffer for the unbuffered I/O - // or we simply use it for its original purpose to accumulate many small chunks + // or we simply use it for its original purpose to accumulate many small + // chunks if (!use_os_buffer_ || (buffer_.GetCapacity() >= left)) { while (left > 0) { - size_t appended = buffer_.Append(src, left); left -= appended; src += appended; if (left > 0) { - s = Flush(); if (!s.ok()) { break; @@ -1195,7 +1153,6 @@ public: } virtual Status Close() override { - Status s; // If there is any data in the cache not written we need to deal with it @@ -1203,13 +1160,12 @@ public: const uint64_t final_size = filesize_ + cursize; if (cursize > 0) { - - // If OS buffering is on, we just flush the remainder, otherwise need - if (!use_os_buffer_) { - s = WriteUnbuffered(); - } else { - s = WriteBuffered(buffer_.GetBufferStart(), cursize); - } + // If OS buffering is on, we just flush the remainder, otherwise need + if (!use_os_buffer_) { + s = WriteUnbuffered(); + } else { + s = WriteBuffered(buffer_.GetBufferStart(), cursize); + } } if (s.ok()) { @@ -1219,14 +1175,16 @@ public: // Sync data if buffer was flushed if (s.ok() && (cursize > 0) && fsync(hFile_) < 0) { auto lastError = GetLastError(); - s = IOErrorFromWindowsError("fsync failed at Close() for: " + filename_, lastError); + s = IOErrorFromWindowsError("fsync failed at Close() for: " + filename_, + lastError); } if (FALSE == ::CloseHandle(hFile_)) { - if (s.ok()) { - auto lastError = GetLastError(); - s = IOErrorFromWindowsError("CloseHandle failed for: " + filename_, lastError); - } + if (s.ok()) { + auto lastError = GetLastError(); + s = IOErrorFromWindowsError("CloseHandle failed for: " + filename_, + lastError); + } } hFile_ = INVALID_HANDLE_VALUE; @@ -1235,49 +1193,46 @@ public: // write out the cached data to the OS cache virtual Status Flush() override { + Status status; - Status status; - - if (buffer_.GetCurrentSize() > 0) { - if(!use_os_buffer_) { - status = WriteUnbuffered(); - } else { - status = WriteBuffered(buffer_.GetBufferStart(), buffer_.GetCurrentSize()); - if (status.ok()) { - buffer_.SetSize(0); - } + if (buffer_.GetCurrentSize() > 0) { + if (!use_os_buffer_) { + status = WriteUnbuffered(); + } else { + status = + WriteBuffered(buffer_.GetBufferStart(), buffer_.GetCurrentSize()); + if (status.ok()) { + buffer_.SetSize(0); } } - return status; + } + return status; } virtual Status Sync() override { - Status s = Flush(); if (!s.ok()) { - return s; + return s; } // Calls flush buffers if (pending_sync_ && fsync(hFile_) < 0) { - auto lastError = GetLastError(); - s = IOErrorFromWindowsError("fsync failed at Sync() for: " + filename_, lastError); + auto lastError = GetLastError(); + s = IOErrorFromWindowsError("fsync failed at Sync() for: " + filename_, + lastError); } else { - pending_sync_ = false; + pending_sync_ = false; } return s; } - virtual Status Fsync() override { - return Sync(); - } + virtual Status Fsync() override { return Sync(); } virtual uint64_t GetFileSize() override { return filesize_ + buffer_.GetCurrentSize(); } virtual Status Allocate(off_t offset, off_t len) override { - Status status; TEST_KILL_RANDOM(rocksdb_kill_odds); @@ -1298,12 +1253,11 @@ public: return status; } -private: - - // This method writes to disk the specified data and makes use of the rate limiter + private: + // This method writes to disk the specified data and makes use of the rate + // limiter // if available Status WriteBuffered(const char* data, size_t size) { - Status s; assert(use_os_buffer_); const char* src = data; @@ -1317,7 +1271,9 @@ private: DWORD bytesWritten = 0; if (!WriteFile(hFile_, src, bytes_allowed, &bytesWritten, NULL)) { auto lastError = GetLastError(); - s = IOErrorFromWindowsError("Failed to write buffered via rate_limiter: " + filename_, lastError); + s = IOErrorFromWindowsError( + "Failed to write buffered via rate_limiter: " + filename_, + lastError); break; } else { actually_written += bytesWritten; @@ -1332,13 +1288,15 @@ private: return s; } - // This flushes the accumulated data in the buffer. We pad data with zeros if necessary to the whole page. + // This flushes the accumulated data in the buffer. We pad data with zeros if + // necessary to the whole page. // However, during automatic flushes padding would not be necessary. - // We always use RateLimiter if available. We move (Refit) any buffer bytes that are left over the - // whole number of pages to be written again on the next flush because we can only write on aligned + // We always use RateLimiter if available. We move (Refit) any buffer bytes + // that are left over the + // whole number of pages to be written again on the next flush because we can + // only write on aligned // offsets. Status WriteUnbuffered() { - Status s; assert(!use_os_buffer_); @@ -1346,10 +1304,13 @@ private: assert((filesize_ % alignment) == 0); // Calculate whole page final file advance if all writes succeed - size_t file_advance = TruncateToPageBoundary(alignment, buffer_.GetCurrentSize()); + size_t file_advance = + TruncateToPageBoundary(alignment, buffer_.GetCurrentSize()); - // Calculate the leftover tail, we write it here padded with zeros BUT we will write - // it again in the future either on Close() OR when the current whole page fills out + // Calculate the leftover tail, we write it here padded with zeros BUT we + // will write + // it again in the future either on Close() OR when the current whole page + // fills out size_t leftover_tail = buffer_.GetCurrentSize() - file_advance; // Round up and pad @@ -1361,16 +1322,19 @@ private: size_t actually_written = 0; while (left > 0) { - - // Request how much is allowed. If this is less than one alignment we may be blocking a lot on every write - // because we can not write less than one alignment (page) unit thus check the configuration. + // Request how much is allowed. If this is less than one alignment we may + // be blocking a lot on every write + // because we can not write less than one alignment (page) unit thus check + // the configuration. size_t bytes_allowed = RequestToken(left, true); - SSIZE_T ret = pwrite(hFile_, buffer_.GetBufferStart() + actually_written, bytes_allowed, file_offset); + SSIZE_T ret = pwrite(hFile_, buffer_.GetBufferStart() + actually_written, + bytes_allowed, file_offset); // Error break if (ret < 0) { auto lastError = GetLastError(); - s = IOErrorFromWindowsError("Failed to pwrite for unbuffered: " + filename_, lastError); + s = IOErrorFromWindowsError( + "Failed to pwrite for unbuffered: " + filename_, lastError); buffer_.SetSize(file_advance + leftover_tail); break; } @@ -1388,7 +1352,8 @@ private: buffer_.RefitTail(file_advance, leftover_tail); // This is where we start writing next time which may or not be // the actual file size on disk. They match if the buffer size - // is a multiple of whole pages otherwise filesize_ is leftover_tail behind + // is a multiple of whole pages otherwise filesize_ is leftover_tail + // behind filesize_ += file_advance; } return s; @@ -1399,8 +1364,8 @@ private: // satisfied in the order of the I/O priority size_t RequestToken(size_t bytes, bool align) const { if (rate_limiter_ && io_priority_ < Env::IO_TOTAL) { - bytes = std::min(bytes, - static_cast(rate_limiter_->GetSingleBurstBytes())); + bytes = std::min( + bytes, static_cast(rate_limiter_->GetSingleBurstBytes())); if (align) { // Here we may actually require more than burst and block @@ -1417,54 +1382,43 @@ private: }; class WinDirectory : public Directory { -public: - WinDirectory() { - } + public: + WinDirectory() {} - virtual Status Fsync() override { - return Status::OK(); - } + virtual Status Fsync() override { return Status::OK(); } }; class WinFileLock : public FileLock { -public: - - explicit WinFileLock(HANDLE hFile) : - hFile_(hFile) { - + public: + explicit WinFileLock(HANDLE hFile) : hFile_(hFile) { assert(hFile != NULL); assert(hFile != INVALID_HANDLE_VALUE); } - ~WinFileLock() { - + ~WinFileLock() { BOOL ret = ::CloseHandle(hFile_); assert(ret); } -private: + private: HANDLE hFile_; }; -namespace -{ +namespace { void WinthreadCall(const char* label, std::error_code result) { - if (0 != result.value()) { fprintf(stderr, "pthread %s: %s\n", label, strerror(result.value())); abort(); } } - } class WinEnv : public Env { -public: + public: WinEnv(); virtual ~WinEnv() { - for (auto& th : threads_to_join_) { th.join(); } @@ -1480,7 +1434,6 @@ public: } virtual Status DeleteFile(const std::string& fname) override { - Status result; if (_unlink(fname.c_str())) { @@ -1491,7 +1444,6 @@ public: } Status GetCurrentTime(int64_t* unix_time) override { - time_t time = std::time(nullptr); if (time == (time_t)(-1)) { return Status::NotSupported("Failed to get time"); @@ -1501,8 +1453,9 @@ public: return Status::OK(); } - virtual Status NewSequentialFile(const std::string& fname, std::unique_ptr* result, const EnvOptions& options) override { - + virtual Status NewSequentialFile(const std::string& fname, + std::unique_ptr* result, + const EnvOptions& options) override { Status s; result->reset(); @@ -1513,28 +1466,26 @@ public: HANDLE hFile = 0; { IOSTATS_TIMER_GUARD(open_nanos); - hFile = CreateFileA(fname.c_str(), - GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, - OPEN_EXISTING, // Original fopen mode is "rb" - FILE_ATTRIBUTE_NORMAL, - NULL); + hFile = CreateFileA( + fname.c_str(), GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, + OPEN_EXISTING, // Original fopen mode is "rb" + FILE_ATTRIBUTE_NORMAL, NULL); } if (INVALID_HANDLE_VALUE == hFile) { auto lastError = GetLastError(); - s = IOErrorFromWindowsError("Failed to open NewSequentialFile" + fname, lastError); + s = IOErrorFromWindowsError("Failed to open NewSequentialFile" + fname, + lastError); } else { - int fd = _open_osfhandle(reinterpret_cast(hFile), 0); if (fd == -1) { auto code = errno; CloseHandle(hFile); - s = IOError("Failed to _open_osfhandle for NewSequentialFile: " + fname, code); + s = IOError("Failed to _open_osfhandle for NewSequentialFile: " + fname, + code); } else { - - FILE * file = _fdopen(fd, "rb"); + FILE* file = _fdopen(fd, "rb"); if (file == nullptr) { auto code = errno; _close(fd); @@ -1547,8 +1498,9 @@ public: return s; } - virtual Status NewRandomAccessFile(const std::string& fname, std::unique_ptr* result, const EnvOptions& options) override { - + virtual Status NewRandomAccessFile(const std::string& fname, + std::unique_ptr* result, + const EnvOptions& options) override { result->reset(); Status s; @@ -1567,80 +1519,78 @@ public: HANDLE hFile = 0; { IOSTATS_TIMER_GUARD(open_nanos); - hFile = CreateFileA( - fname.c_str(), - GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, - OPEN_EXISTING, - fileFlags, - NULL); + hFile = + CreateFileA(fname.c_str(), GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, OPEN_EXISTING, fileFlags, NULL); } if (INVALID_HANDLE_VALUE == hFile) { auto lastError = GetLastError(); - return IOErrorFromWindowsError("NewRandomAccessFile failed to Create/Open: " + fname, lastError); + return IOErrorFromWindowsError( + "NewRandomAccessFile failed to Create/Open: " + fname, lastError); } UniqueCloseHandlePtr fileGuard(hFile, CloseHandleFunc); // CAUTION! This will map the entire file into the process address space if (options.use_mmap_reads && sizeof(void*) >= 8) { - // Use mmap when virtual address-space is plentiful. uint64_t fileSize; s = GetFileSize(fname, &fileSize); if (s.ok()) { - // Will not map empty files if (fileSize == 0) { - return IOError("NewRandomAccessFile failed to map empty file: " + fname, EINVAL); + return IOError( + "NewRandomAccessFile failed to map empty file: " + fname, EINVAL); } - HANDLE hMap = CreateFileMappingA(hFile, - NULL, - PAGE_READONLY, - 0, // Whole file at its present length - 0, - NULL); // Mapping name + HANDLE hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, + 0, // Whole file at its present length + 0, + NULL); // Mapping name if (!hMap) { auto lastError = GetLastError(); - return IOErrorFromWindowsError("Failed to create file mapping for NewRandomAccessFile: " + fname, lastError); + return IOErrorFromWindowsError( + "Failed to create file mapping for NewRandomAccessFile: " + fname, + lastError); } - UniqueCloseHandlePtr mapGuard (hMap, CloseHandleFunc); + UniqueCloseHandlePtr mapGuard(hMap, CloseHandleFunc); - const void* mapped_region = MapViewOfFileEx(hMap, - FILE_MAP_READ, - 0, // High DWORD of access start - 0, // Low DWORD - fileSize, - NULL); // Let the OS choose the mapping + const void* mapped_region = + MapViewOfFileEx(hMap, FILE_MAP_READ, + 0, // High DWORD of access start + 0, // Low DWORD + fileSize, + NULL); // Let the OS choose the mapping if (!mapped_region) { auto lastError = GetLastError(); - return IOErrorFromWindowsError("Failed to MapViewOfFile for NewRandomAccessFile: " + fname, lastError); + return IOErrorFromWindowsError( + "Failed to MapViewOfFile for NewRandomAccessFile: " + fname, + lastError); } - result->reset(new WinMmapReadableFile(fname, hFile, hMap, mapped_region, fileSize)); + result->reset(new WinMmapReadableFile(fname, hFile, hMap, mapped_region, + fileSize)); mapGuard.release(); fileGuard.release(); } - } - else { - + } else { result->reset(new WinRandomAccessFile(fname, hFile, page_size_, options)); fileGuard.release(); } return s; } - virtual Status NewWritableFile(const std::string& fname, std::unique_ptr* result, const EnvOptions& options) override { - + virtual Status NewWritableFile(const std::string& fname, + std::unique_ptr* result, + const EnvOptions& options) override { const size_t c_BufferCapacity = 64 * 1024; EnvOptions local_options(options); @@ -1651,11 +1601,13 @@ public: DWORD fileFlags = FILE_ATTRIBUTE_NORMAL; if (!local_options.use_os_buffer && !local_options.use_mmap_writes) { - fileFlags = FILE_FLAG_NO_BUFFERING; + fileFlags = FILE_FLAG_NO_BUFFERING; } - // Desired access. We are want to write only here but if we want to memory map - // the file then there is no write only mode so we have to create it Read/Write + // Desired access. We are want to write only here but if we want to memory + // map + // the file then there is no write only mode so we have to create it + // Read/Write // However, MapViewOfFile specifies only Write only DWORD desired_access = GENERIC_WRITE; DWORD shared_mode = FILE_SHARE_READ; @@ -1663,39 +1615,47 @@ public: if (local_options.use_mmap_writes) { desired_access |= GENERIC_READ; } else { - // Adding this solely for tests to pass (fault_injection_test, wal_manager_test). + // Adding this solely for tests to pass (fault_injection_test, + // wal_manager_test). shared_mode |= (FILE_SHARE_WRITE | FILE_SHARE_DELETE); } HANDLE hFile = 0; { IOSTATS_TIMER_GUARD(open_nanos); - hFile = CreateFileA(fname.c_str(), - desired_access, // Access desired - shared_mode, - NULL, // Security attributes - CREATE_ALWAYS, // Posix env says O_CREAT | O_RDWR | O_TRUNC - fileFlags, // Flags - NULL); // Template File + hFile = CreateFileA( + fname.c_str(), + desired_access, // Access desired + shared_mode, + NULL, // Security attributes + CREATE_ALWAYS, // Posix env says O_CREAT | O_RDWR | O_TRUNC + fileFlags, // Flags + NULL); // Template File } - + if (INVALID_HANDLE_VALUE == hFile) { auto lastError = GetLastError(); - return IOErrorFromWindowsError("Failed to create a NewWriteableFile: " + fname, lastError); + return IOErrorFromWindowsError( + "Failed to create a NewWriteableFile: " + fname, lastError); } if (options.use_mmap_writes) { - // We usually do not use mmmapping on SSD and thus we pass memory page_size - result->reset(new WinMmapFile(fname, hFile, page_size_, allocation_granularity_, local_options)); + // We usually do not use mmmapping on SSD and thus we pass memory + // page_size + result->reset(new WinMmapFile(fname, hFile, page_size_, + allocation_granularity_, local_options)); } else { - // Here we want the buffer allocation to be aligned by the SSD page size and to be a multiple of it - result->reset(new WinWritableFile(fname, hFile, page_size_, c_BufferCapacity, local_options)); + // Here we want the buffer allocation to be aligned by the SSD page size + // and to be a multiple of it + result->reset(new WinWritableFile(fname, hFile, page_size_, + c_BufferCapacity, local_options)); } return s; } - virtual Status NewRandomRWFile(const std::string& fname, std::unique_ptr* result, - const EnvOptions& options) override { + virtual Status NewRandomRWFile(const std::string& fname, + std::unique_ptr* result, + const EnvOptions& options) override { result->reset(); // no support for mmap yet (same as POSIX env) @@ -1708,27 +1668,25 @@ public: HANDLE hFile = 0; { IOSTATS_TIMER_GUARD(open_nanos); - hFile = CreateFileA(fname.c_str(), - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ, - NULL, - OPEN_ALWAYS, // Posix env specifies O_CREAT, it will open existing file or create new - FILE_ATTRIBUTE_NORMAL, - NULL); + hFile = CreateFileA(fname.c_str(), GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ, NULL, + OPEN_ALWAYS, // Posix env specifies O_CREAT, it will + // open existing file or create new + FILE_ATTRIBUTE_NORMAL, NULL); } if (INVALID_HANDLE_VALUE == hFile) { auto lastError = GetLastError(); - s = IOErrorFromWindowsError("Failed to Open/Create NewRandomRWFile" + fname, lastError); - } - else { - + s = IOErrorFromWindowsError( + "Failed to Open/Create NewRandomRWFile" + fname, lastError); + } else { result->reset(new WinRandomRWFile(fname, hFile, options)); } return s; } - virtual Status NewDirectory(const std::string& name, std::unique_ptr* result) override { + virtual Status NewDirectory(const std::string& name, + std::unique_ptr* result) override { Status s; // Must be nullptr on failure result->reset(); @@ -1748,20 +1706,19 @@ public: return _access(fname.c_str(), F_OK_) == 0; } - virtual Status GetChildren(const std::string& dir, std::vector* result) override { - + virtual Status GetChildren(const std::string& dir, + std::vector* result) override { std::vector output; Status status; auto CloseDir = [](DIR* p) { closedir(p); }; - std::unique_ptr dirp(opendir(dir.c_str()), CloseDir); + std::unique_ptr dirp(opendir(dir.c_str()), + CloseDir); if (!dirp) { status = IOError(dir, errno); - } - else { - + } else { if (result->capacity() > 0) { output.reserve(result->capacity()); } @@ -1782,15 +1739,14 @@ public: Status result; if (_mkdir(name.c_str()) != 0) { - auto code = errno; - result = IOError("Failed to create dir: " + name, code); + auto code = errno; + result = IOError("Failed to create dir: " + name, code); } return result; } virtual Status CreateDirIfMissing(const std::string& name) override { - Status result; if (DirExists(name)) { @@ -1799,10 +1755,11 @@ public: if (_mkdir(name.c_str()) != 0) { if (errno == EEXIST) { - result = Status::IOError("`" + name + "' exists but is not a directory"); - } else { - auto code = errno; - result = IOError("Failed to create dir: " + name, code); + result = + Status::IOError("`" + name + "' exists but is not a directory"); + } else { + auto code = errno; + result = IOError("Failed to create dir: " + name, code); } } @@ -1810,30 +1767,29 @@ public: } virtual Status DeleteDir(const std::string& name) override { - Status result; if (_rmdir(name.c_str()) != 0) { - auto code = errno; - result = IOError("Failed to remove dir: " + name, code); + auto code = errno; + result = IOError("Failed to remove dir: " + name, code); } return result; } - virtual Status GetFileSize(const std::string& fname, uint64_t* size) override { + virtual Status GetFileSize(const std::string& fname, + uint64_t* size) override { + Status s; - Status s; - - WIN32_FILE_ATTRIBUTE_DATA attrs; - if (GetFileAttributesExA(fname.c_str(), GetFileExInfoStandard, &attrs)) { - ULARGE_INTEGER file_size; - file_size.HighPart = attrs.nFileSizeHigh; - file_size.LowPart = attrs.nFileSizeLow; - *size = file_size.QuadPart; - } else { - auto lastError = GetLastError(); - s = IOErrorFromWindowsError("Can not get size for: " + fname, lastError); - } - return s; + WIN32_FILE_ATTRIBUTE_DATA attrs; + if (GetFileAttributesExA(fname.c_str(), GetFileExInfoStandard, &attrs)) { + ULARGE_INTEGER file_size; + file_size.HighPart = attrs.nFileSizeHigh; + file_size.LowPart = attrs.nFileSizeLow; + *size = file_size.QuadPart; + } else { + auto lastError = GetLastError(); + s = IOErrorFromWindowsError("Can not get size for: " + fname, lastError); + } + return s; } static inline uint64_t FileTimeToUnixTime(const FILETIME& ftTime) { @@ -1841,19 +1797,21 @@ public: // UNIX epoch starts on 1970-01-01T00:00:00Z // Windows FILETIME starts on 1601-01-01T00:00:00Z // Therefore, we need to subtract the below number of seconds from - // the seconds that we obtain from FILETIME with an obvious loss of precision + // the seconds that we obtain from FILETIME with an obvious loss of + // precision const uint64_t c_SecondBeforeUnixEpoch = 11644473600U; ULARGE_INTEGER li; li.HighPart = ftTime.dwHighDateTime; li.LowPart = ftTime.dwLowDateTime; - uint64_t result = (li.QuadPart / c_FileTimePerSecond) - c_SecondBeforeUnixEpoch; + uint64_t result = + (li.QuadPart / c_FileTimePerSecond) - c_SecondBeforeUnixEpoch; return result; } - virtual Status GetFileModificationTime(const std::string& fname, uint64_t* file_mtime) override { - + virtual Status GetFileModificationTime(const std::string& fname, + uint64_t* file_mtime) override { Status s; WIN32_FILE_ATTRIBUTE_DATA attrs; @@ -1861,21 +1819,21 @@ public: *file_mtime = FileTimeToUnixTime(attrs.ftLastWriteTime); } else { auto lastError = GetLastError(); - s = IOErrorFromWindowsError("Can not get file modification time for: " + fname, lastError); + s = IOErrorFromWindowsError( + "Can not get file modification time for: " + fname, lastError); *file_mtime = 0; } return s; } - virtual Status RenameFile(const std::string& src, const std::string& target) override { - + virtual Status RenameFile(const std::string& src, + const std::string& target) override { Status result; // rename() is not capable of replacing the existing file as on Linux // so use OS API directly if (!MoveFileExA(src.c_str(), target.c_str(), MOVEFILE_REPLACE_EXISTING)) { - DWORD lastError = GetLastError(); std::string text("Failed to rename: "); @@ -1887,12 +1845,11 @@ public: return result; } - virtual Status LinkFile(const std::string& src, const std::string& target) override { - + virtual Status LinkFile(const std::string& src, + const std::string& target) override { Status result; if (!CreateHardLinkA(target.c_str(), src.c_str(), NULL)) { - DWORD lastError = GetLastError(); std::string text("Failed to link: "); @@ -1904,7 +1861,8 @@ public: return result; } - virtual Status LockFile(const std::string& lockFname, FileLock** lock) override { + virtual Status LockFile(const std::string& lockFname, + FileLock** lock) override { assert(lock != nullptr); *lock = NULL; @@ -1920,14 +1878,15 @@ public: { IOSTATS_TIMER_GUARD(open_nanos); hFile = CreateFileA(lockFname.c_str(), (GENERIC_READ | GENERIC_WRITE), - ExclusiveAccessON, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + ExclusiveAccessON, NULL, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, NULL); } if (INVALID_HANDLE_VALUE == hFile) { auto lastError = GetLastError(); - result = IOErrorFromWindowsError("Failed to create lock file: " + lockFname, lastError); + result = IOErrorFromWindowsError( + "Failed to create lock file: " + lockFname, lastError); } else { - *lock = new WinFileLock(hFile); } @@ -1944,8 +1903,9 @@ public: return result; } - virtual void Schedule(void (*function)(void*), void* arg, Priority pri = LOW, void* tag = nullptr) override; - + virtual void Schedule(void (*function)(void*), void* arg, Priority pri = LOW, + void* tag = nullptr) override; + virtual int UnSchedule(void* arg, Priority pri) override; virtual void StartThread(void (*function)(void* arg), void* arg) override; @@ -1955,20 +1915,19 @@ public: virtual unsigned int GetThreadPoolQueueLen(Priority pri = LOW) const override; virtual Status GetTestDirectory(std::string* result) override { - std::string output; const char* env = getenv("TEST_TMPDIR"); if (env && env[0] != '\0') { output = env; CreateDir(output); - } else { + } else { env = getenv("TMP"); if (env && env[0] != '\0') { - output = env; - } else { - output = "c:\\tmp"; + output = env; + } else { + output = "c:\\tmp"; } CreateDir(output); @@ -1985,7 +1944,7 @@ public: } virtual Status GetThreadList( - std::vector* thread_list) override { + std::vector* thread_list) override { assert(thread_status_updater_); return thread_status_updater_->GetThreadList(thread_list); } @@ -1994,13 +1953,11 @@ public: uint64_t thread_id = GetCurrentThreadId(); return thread_id; } - - virtual uint64_t GetThreadID() const override { - return gettid(); - } - virtual Status NewLogger(const std::string& fname, std::shared_ptr* result) override { + virtual uint64_t GetThreadID() const override { return gettid(); } + virtual Status NewLogger(const std::string& fname, + std::shared_ptr* result) override { Status s; result->reset(); @@ -2008,23 +1965,26 @@ public: HANDLE hFile = 0; { IOSTATS_TIMER_GUARD(open_nanos); - hFile = CreateFileA(fname.c_str(), - GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_DELETE, // In RocksDb log files are renamed and deleted before they are closed. This enables doing so. - NULL, - CREATE_ALWAYS, // Original fopen mode is "w" - FILE_ATTRIBUTE_NORMAL, - NULL); + hFile = CreateFileA( + fname.c_str(), GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_DELETE, // In RocksDb log files are + // renamed and deleted before + // they are closed. This enables + // doing so. + NULL, + CREATE_ALWAYS, // Original fopen mode is "w" + FILE_ATTRIBUTE_NORMAL, NULL); } if (INVALID_HANDLE_VALUE == hFile) { auto lastError = GetLastError(); s = IOErrorFromWindowsError("Failed to open LogFile" + fname, lastError); } else { - { - // With log files we want to set the true creation time as of now because the system - // for some reason caches the attributes of the previous file that just been renamed from + // With log files we want to set the true creation time as of now + // because the system + // for some reason caches the attributes of the previous file that just + // been renamed from // this name so auto_roll_logger_test fails FILETIME ft; GetSystemTimeAsFileTime(&ft); @@ -2038,8 +1998,7 @@ public: CloseHandle(hFile); s = IOError("Failed to _open_osfhandle: " + fname, code); } else { - - FILE * file = _fdopen(fd, "w"); + FILE* file = _fdopen(fd, "w"); if (file == nullptr) { auto code = errno; _close(fd); @@ -2054,7 +2013,8 @@ public: virtual uint64_t NowMicros() override { using namespace std::chrono; - return duration_cast(system_clock::now().time_since_epoch()).count(); + return duration_cast(system_clock::now().time_since_epoch()) + .count(); } virtual uint64_t NowNanos() override { @@ -2071,12 +2031,11 @@ public: return li.QuadPart; } - virtual void SleepForMicroseconds(int micros) override { + virtual void SleepForMicroseconds(int micros) override { std::this_thread::sleep_for(std::chrono::microseconds(micros)); } virtual Status GetHostName(char* name, uint64_t len) override { - Status s; DWORD nSize = len; @@ -2084,43 +2043,36 @@ public: auto lastError = GetLastError(); s = IOErrorFromWindowsError("GetHostName", lastError); } else { - name[nSize] = 0; + name[nSize] = 0; } return s; } virtual Status GetCurrTime(int64_t* unix_time) { - Status s; time_t ret = time(nullptr); - if (ret == (time_t) -1) { - *unix_time = 0; - s = IOError("GetCurrTime", errno); + if (ret == (time_t)-1) { + *unix_time = 0; + s = IOError("GetCurrTime", errno); } else { - *unix_time = (int64_t)ret; + *unix_time = (int64_t)ret; } return s; } - virtual Status GetAbsolutePath(const std::string& db_path, std::string* output_path) override { - + virtual Status GetAbsolutePath(const std::string& db_path, + std::string* output_path) override { // Check if we already have an absolute path // that starts with non dot and has a semicolon in it - if ((!db_path.empty() && - (db_path[0] == '/' || db_path[0] == '\\')) || - ( - db_path.size() > 2 && - db_path[0] != '.' && - ((db_path[1] == ':' && db_path[2] == '\\') || - (db_path[1] == ':' && db_path[2] == '/')) - ) - ) { - - *output_path = db_path; - return Status::OK(); + if ((!db_path.empty() && (db_path[0] == '/' || db_path[0] == '\\')) || + (db_path.size() > 2 && db_path[0] != '.' && + ((db_path[1] == ':' && db_path[2] == '\\') || + (db_path[1] == ':' && db_path[2] == '/')))) { + *output_path = db_path; + return Status::OK(); } std::string result; @@ -2128,7 +2080,8 @@ public: char* ret = _getcwd(&result[0], _MAX_PATH); if (ret == nullptr) { - return Status::IOError("Failed to get current working directory", strerror(errno)); + return Status::IOError("Failed to get current working directory", + strerror(errno)); } result.resize(strlen(result.data())); @@ -2149,7 +2102,6 @@ public: } virtual std::string TimeToString(uint64_t secondsSince1970) override { - std::string result; const time_t seconds = secondsSince1970; @@ -2161,11 +2113,12 @@ public: if (ret) { result = std::to_string(seconds); } else { - result.resize(maxsize); char* p = &result[0]; - int len = snprintf(p, maxsize, "%04d/%02d/%02d-%02d:%02d:%02d ", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec); + int len = snprintf(p, maxsize, "%04d/%02d/%02d-%02d:%02d:%02d ", + t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, + t.tm_min, t.tm_sec); assert(len > 0); result.resize(len); @@ -2174,11 +2127,14 @@ public: return result; } - EnvOptions OptimizeForLogWrite(const EnvOptions& env_options, const DBOptions& db_options) const override { + EnvOptions OptimizeForLogWrite(const EnvOptions& env_options, + const DBOptions& db_options) const override { EnvOptions optimized = env_options; optimized.use_mmap_writes = false; optimized.bytes_per_sync = db_options.wal_bytes_per_sync; - optimized.use_os_buffer = true; // This is because we flush only whole pages on unbuffered io and the last records are not guaranteed to be flushed. + optimized.use_os_buffer = + true; // This is because we flush only whole pages on unbuffered io and + // the last records are not guaranteed to be flushed. // TODO(icanadi) it's faster if fallocate_with_keep_size is false, but it // breaks TransactionLogIteratorStallAtLastRecord unit test. Fix the unit // test and make this false @@ -2186,7 +2142,8 @@ public: return optimized; } - EnvOptions OptimizeForManifestWrite(const EnvOptions& env_options) const override{ + EnvOptions OptimizeForManifestWrite( + const EnvOptions& env_options) const override { EnvOptions optimized = env_options; optimized.use_mmap_writes = false; optimized.use_os_buffer = true; @@ -2195,99 +2152,84 @@ public: } private: - - // Returns true iff the named directory exists and is a directory. - virtual bool DirExists(const std::string& dname) { - - WIN32_FILE_ATTRIBUTE_DATA attrs; - if (GetFileAttributesExA(dname.c_str(), GetFileExInfoStandard, &attrs)) { - return 0 != (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); - } - return false; - } - - bool SupportsFastAllocate(const std::string& /* path */) { - return false; + // Returns true iff the named directory exists and is a directory. + virtual bool DirExists(const std::string& dname) { + WIN32_FILE_ATTRIBUTE_DATA attrs; + if (GetFileAttributesExA(dname.c_str(), GetFileExInfoStandard, &attrs)) { + return 0 != (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); } + return false; + } + bool SupportsFastAllocate(const std::string& /* path */) { return false; } class ThreadPool { - public: - ThreadPool() : - total_threads_limit_(1), + public: + ThreadPool() + : total_threads_limit_(1), bgthreads_(0), queue_(), queue_len_(0U), exit_all_threads_(false), low_io_priority_(false), - env_(nullptr) { - } - - ~ThreadPool() { - assert(bgthreads_.size() == 0U); + env_(nullptr) {} + + ~ThreadPool() { assert(bgthreads_.size() == 0U); } + + void JoinAllThreads() { + { + std::lock_guard lock(mu_); + assert(!exit_all_threads_); + exit_all_threads_ = true; + bgsignal_.notify_all(); } - void JoinAllThreads() { - - { - std::lock_guard lock(mu_); - assert(!exit_all_threads_); - exit_all_threads_ = true; - bgsignal_.notify_all(); - } - - for (std::thread& th : bgthreads_) { - th.join(); - } - - // Subject to assert in the __dtor - bgthreads_.clear(); + for (std::thread& th : bgthreads_) { + th.join(); } - void SetHostEnv(Env* env) { - env_ = env; - } + // Subject to assert in the __dtor + bgthreads_.clear(); + } - // Return true if there is at least one thread needs to terminate. - bool HasExcessiveThread() const { - return bgthreads_.size() > total_threads_limit_; - } + void SetHostEnv(Env* env) { env_ = env; } - // Return true iff the current thread is the excessive thread to terminate. - // Always terminate the running thread that is added last, even if there are - // more than one thread to terminate. - bool IsLastExcessiveThread(size_t thread_id) const { - return HasExcessiveThread() && thread_id == bgthreads_.size() - 1; - } + // Return true if there is at least one thread needs to terminate. + bool HasExcessiveThread() const { + return bgthreads_.size() > total_threads_limit_; + } - // Is one of the threads to terminate. - bool IsExcessiveThread(size_t thread_id) const { - return thread_id >= total_threads_limit_; - } + // Return true iff the current thread is the excessive thread to terminate. + // Always terminate the running thread that is added last, even if there are + // more than one thread to terminate. + bool IsLastExcessiveThread(size_t thread_id) const { + return HasExcessiveThread() && thread_id == bgthreads_.size() - 1; + } - // Return the thread priority. - // This would allow its member-thread to know its priority. - Env::Priority GetThreadPriority() { - return priority_; - } + // Is one of the threads to terminate. + bool IsExcessiveThread(size_t thread_id) const { + return thread_id >= total_threads_limit_; + } - // Set the thread priority. - void SetThreadPriority(Env::Priority priority) { - priority_ = priority; - } + // Return the thread priority. + // This would allow its member-thread to know its priority. + Env::Priority GetThreadPriority() { return priority_; } + + // Set the thread priority. + void SetThreadPriority(Env::Priority priority) { priority_ = priority; } void BGThread(size_t thread_id) { - while (true) { // Wait until there is an item that is ready to run std::unique_lock uniqueLock(mu_); - + // Stop waiting if the thread needs to do work or needs to terminate. - while (!exit_all_threads_ && !IsLastExcessiveThread(thread_id) && (queue_.empty() || IsExcessiveThread(thread_id))) { + while (!exit_all_threads_ && !IsLastExcessiveThread(thread_id) && + (queue_.empty() || IsExcessiveThread(thread_id))) { bgsignal_.wait(uniqueLock); } - if (exit_all_threads_) { + if (exit_all_threads_) { // mechanism to let BG threads exit safely uniqueLock.unlock(); break; @@ -2305,8 +2247,8 @@ public: bgthreads_.pop_back(); if (HasExcessiveThread()) { - // There is still at least more excessive thread to terminate. - WakeUpAllThreads(); + // There is still at least more excessive thread to terminate. + WakeUpAllThreads(); } uniqueLock.unlock(); @@ -2315,7 +2257,7 @@ public: break; } - void(*function)(void*) = queue_.front().function; + void (*function)(void*) = queue_.front().function; void* arg = queue_.front().arg; queue_.pop_front(); queue_len_.store(queue_.size(), std::memory_order_relaxed); @@ -2328,24 +2270,25 @@ public: // Helper struct for passing arguments when creating threads. struct BGThreadMetadata { ThreadPool* thread_pool_; - size_t thread_id_; // Thread count in the thread. + size_t thread_id_; // Thread count in the thread. - explicit BGThreadMetadata(ThreadPool* thread_pool, size_t thread_id) : thread_pool_(thread_pool), thread_id_(thread_id) {} + explicit BGThreadMetadata(ThreadPool* thread_pool, size_t thread_id) + : thread_pool_(thread_pool), thread_id_(thread_id) {} }; static void* BGThreadWrapper(void* arg) { - - std::unique_ptr meta(reinterpret_cast(arg)); + std::unique_ptr meta( + reinterpret_cast(arg)); size_t thread_id = meta->thread_id_; ThreadPool* tp = meta->thread_pool_; #if ROCKSDB_USING_THREAD_STATUS // for thread-status - ThreadStatusUtil::RegisterThread(tp->env_, - (tp->GetThreadPriority() == Env::Priority::HIGH ? - ThreadStatus::HIGH_PRIORITY : - ThreadStatus::LOW_PRIORITY)); + ThreadStatusUtil::RegisterThread( + tp->env_, (tp->GetThreadPriority() == Env::Priority::HIGH + ? ThreadStatus::HIGH_PRIORITY + : ThreadStatus::LOW_PRIORITY)); #endif tp->BGThread(thread_id); #if ROCKSDB_USING_THREAD_STATUS @@ -2354,136 +2297,132 @@ public: return nullptr; } - void WakeUpAllThreads() { - bgsignal_.notify_all(); + void WakeUpAllThreads() { bgsignal_.notify_all(); } + + void SetBackgroundThreadsInternal(size_t num, bool allow_reduce) { + std::lock_guard lg(mu_); + + if (exit_all_threads_) { + return; } - void SetBackgroundThreadsInternal(size_t num, bool allow_reduce) { - - std::lock_guard lg(mu_); - - if (exit_all_threads_) { - return; - } - - if (num > total_threads_limit_ || + if (num > total_threads_limit_ || (num < total_threads_limit_ && allow_reduce)) { - total_threads_limit_ = std::max(size_t(1), num); - WakeUpAllThreads(); - StartBGThreads(); - } - assert(total_threads_limit_ > 0); - } - - void IncBackgroundThreadsIfNeeded(int num) { - SetBackgroundThreadsInternal(num, false); - } - - void SetBackgroundThreads(int num) { - SetBackgroundThreadsInternal(num, true); - } - - void StartBGThreads() { - // Start background thread if necessary - while (bgthreads_.size() < total_threads_limit_) { - std::thread p_t(&ThreadPool::BGThreadWrapper, new BGThreadMetadata(this, bgthreads_.size())); - bgthreads_.push_back(std::move(p_t)); - } - } - - void Schedule(void (*function)(void* arg1), void* arg, void* tag) { - - std::lock_guard lg(mu_); - - if (exit_all_threads_) { - return; - } - + total_threads_limit_ = std::max(size_t(1), num); + WakeUpAllThreads(); StartBGThreads(); + } + assert(total_threads_limit_ > 0); + } - // Add to priority queue - queue_.push_back(BGItem()); - queue_.back().function = function; - queue_.back().arg = arg; - queue_.back().tag = tag; - queue_len_.store(queue_.size(), std::memory_order_relaxed); + void IncBackgroundThreadsIfNeeded(int num) { + SetBackgroundThreadsInternal(num, false); + } - if (!HasExcessiveThread()) { - // Wake up at least one waiting thread. - bgsignal_.notify_one(); + void SetBackgroundThreads(int num) { + SetBackgroundThreadsInternal(num, true); + } + + void StartBGThreads() { + // Start background thread if necessary + while (bgthreads_.size() < total_threads_limit_) { + std::thread p_t(&ThreadPool::BGThreadWrapper, + new BGThreadMetadata(this, bgthreads_.size())); + bgthreads_.push_back(std::move(p_t)); + } + } + + void Schedule(void (*function)(void* arg1), void* arg, void* tag) { + std::lock_guard lg(mu_); + + if (exit_all_threads_) { + return; + } + + StartBGThreads(); + + // Add to priority queue + queue_.push_back(BGItem()); + queue_.back().function = function; + queue_.back().arg = arg; + queue_.back().tag = tag; + queue_len_.store(queue_.size(), std::memory_order_relaxed); + + if (!HasExcessiveThread()) { + // Wake up at least one waiting thread. + bgsignal_.notify_one(); + } else { + // Need to wake up all threads to make sure the one woken + // up is not the one to terminate. + WakeUpAllThreads(); + } + } + + int UnSchedule(void* arg) { + int count = 0; + + std::lock_guard lg(mu_); + + // Remove from priority queue + BGQueue::iterator it = queue_.begin(); + while (it != queue_.end()) { + if (arg == (*it).tag) { + it = queue_.erase(it); + count++; } else { - // Need to wake up all threads to make sure the one woken - // up is not the one to terminate. - WakeUpAllThreads(); + ++it; } } - - int UnSchedule(void* arg) { - int count = 0; - - std::lock_guard lg(mu_); + queue_len_.store(queue_.size(), std::memory_order_relaxed); - // Remove from priority queue - BGQueue::iterator it = queue_.begin(); - while (it != queue_.end()) { - if (arg == (*it).tag) { - it = queue_.erase(it); - count++; - } else { - ++it; - } - } - - queue_len_.store(queue_.size(), std::memory_order_relaxed); + return count; + } - return count; - } + unsigned int GetQueueLen() const { + return static_cast( + queue_len_.load(std::memory_order_relaxed)); + } - unsigned int GetQueueLen() const { - return static_cast(queue_len_.load(std::memory_order_relaxed)); - } + private: + // Entry per Schedule() call + struct BGItem { + void* arg; + void (*function)(void*); + void* tag; + }; - private: - // Entry per Schedule() call - struct BGItem { - void* arg; - void (*function)(void*); - void* tag; - }; + typedef std::deque BGQueue; - typedef std::deque BGQueue; - - std::mutex mu_; - std::condition_variable bgsignal_; - size_t total_threads_limit_; - std::vector bgthreads_; - BGQueue queue_; - std::atomic_size_t queue_len_; // Queue length. Used for stats reporting - bool exit_all_threads_; - bool low_io_priority_; - Env::Priority priority_; - Env* env_; + std::mutex mu_; + std::condition_variable bgsignal_; + size_t total_threads_limit_; + std::vector bgthreads_; + BGQueue queue_; + std::atomic_size_t queue_len_; // Queue length. Used for stats reporting + bool exit_all_threads_; + bool low_io_priority_; + Env::Priority priority_; + Env* env_; }; - bool checkedDiskForMmap_; - bool forceMmapOff; // do we override Env options? - size_t page_size_; - size_t allocation_granularity_; - uint64_t perf_counter_frequency_; - std::vector thread_pools_; - mutable std::mutex mu_; - std::vector threads_to_join_; + bool checkedDiskForMmap_; + bool forceMmapOff; // do we override Env options? + size_t page_size_; + size_t allocation_granularity_; + uint64_t perf_counter_frequency_; + std::vector thread_pools_; + mutable std::mutex mu_; + std::vector threads_to_join_; }; -WinEnv::WinEnv() : - checkedDiskForMmap_(false), - forceMmapOff(false), - page_size_(4 * 1012), - allocation_granularity_(page_size_), - perf_counter_frequency_(0), - thread_pools_(Priority::TOTAL) { - +WinEnv::WinEnv() + : checkedDiskForMmap_(false), + forceMmapOff(false), + page_size_(4 * 1012), + allocation_granularity_(page_size_), + perf_counter_frequency_(0), + thread_pools_(Priority::TOTAL) { SYSTEM_INFO sinfo; GetSystemInfo(&sinfo); @@ -2499,7 +2438,7 @@ WinEnv::WinEnv() : for (int pool_id = 0; pool_id < Env::Priority::TOTAL; ++pool_id) { thread_pools_[pool_id].SetThreadPriority( - static_cast(pool_id)); + static_cast(pool_id)); // This allows later initializing the thread-local-env of each thread. thread_pools_[pool_id].SetHostEnv(this); } @@ -2508,7 +2447,8 @@ WinEnv::WinEnv() : thread_status_updater_ = CreateThreadStatusUpdater(); } -void WinEnv::Schedule(void(*function)(void*), void* arg, Priority pri, void* tag) { +void WinEnv::Schedule(void (*function)(void*), void* arg, Priority pri, + void* tag) { assert(pri >= Priority::LOW && pri <= Priority::HIGH); thread_pools_[pri].Schedule(function, arg, tag); } @@ -2522,41 +2462,38 @@ unsigned int WinEnv::GetThreadPoolQueueLen(Priority pri) const { return thread_pools_[pri].GetQueueLen(); } -namespace -{ +namespace { struct StartThreadState { - void (*user_function)(void*); - void* arg; + void (*user_function)(void*); + void* arg; }; } static void* StartThreadWrapper(void* arg) { - std::unique_ptr state(reinterpret_cast(arg)); + std::unique_ptr state( + reinterpret_cast(arg)); state->user_function(state->arg); return nullptr; } void WinEnv::StartThread(void (*function)(void* arg), void* arg) { - StartThreadState* state = new StartThreadState; state->user_function = function; state->arg = arg; try { + std::thread th(&StartThreadWrapper, state); - std::thread th(&StartThreadWrapper, state); + std::lock_guard lg(mu_); + threads_to_join_.push_back(std::move(th)); - std::lock_guard lg(mu_); - threads_to_join_.push_back(std::move(th)); - - } catch (const std::system_error& ex) { - WinthreadCall("start thread", ex.code()); + } catch (const std::system_error& ex) { + WinthreadCall("start thread", ex.code()); } } void WinEnv::WaitForJoin() { - for (auto& th : threads_to_join_) { - th.join(); + th.join(); } threads_to_join_.clear(); @@ -2565,7 +2502,6 @@ void WinEnv::WaitForJoin() { } // namespace std::string Env::GenerateUniqueId() { - std::string result; UUID uuid; @@ -2575,7 +2511,6 @@ std::string Env::GenerateUniqueId() { auto status = UuidToStringA(&uuid, &rpc_str); assert(status == RPC_S_OK); - result = reinterpret_cast(rpc_str); status = RpcStringFreeA(&rpc_str); @@ -2584,15 +2519,19 @@ std::string Env::GenerateUniqueId() { return result; } -// We choose to create this on the heap and using std::once for the following reasons -// 1) Currently available MS compiler does not implement atomic C++11 initialization of +// We choose to create this on the heap and using std::once for the following +// reasons +// 1) Currently available MS compiler does not implement atomic C++11 +// initialization of // function local statics -// 2) We choose not to destroy the env because joining the threads from the system loader -// which destroys the statics (same as from DLLMain) creates a system loader dead-lock. +// 2) We choose not to destroy the env because joining the threads from the +// system loader +// which destroys the statics (same as from DLLMain) creates a system loader +// dead-lock. // in this manner any remaining threads are terminated OK. namespace { - std::once_flag winenv_once_flag; - Env* envptr; +std::once_flag winenv_once_flag; +Env* envptr; }; Env* Env::Default() { diff --git a/port/win/port_win.cc b/port/win/port_win.cc index 0ea706c79..fc7208104 100644 --- a/port/win/port_win.cc +++ b/port/win/port_win.cc @@ -28,181 +28,162 @@ #include "util/logging.h" -namespace rocksdb -{ -namespace port -{ +namespace rocksdb { +namespace port { void gettimeofday(struct timeval* tv, struct timezone* /* tz */) { + using namespace std::chrono; - using namespace std::chrono; + microseconds usNow( + duration_cast(system_clock::now().time_since_epoch())); - microseconds usNow (duration_cast(system_clock::now().time_since_epoch())); + seconds secNow(duration_cast(usNow)); - seconds secNow(duration_cast(usNow)); - - tv->tv_sec = secNow.count(); - tv->tv_usec = usNow.count() - duration_cast(secNow).count(); + tv->tv_sec = secNow.count(); + tv->tv_usec = usNow.count() - duration_cast(secNow).count(); } +Mutex::Mutex(bool adaptive) : lock(m_mutex, std::defer_lock) {} -Mutex::Mutex(bool adaptive) : lock(m_mutex, std::defer_lock) { -} - -Mutex::~Mutex() { -} +Mutex::~Mutex() {} void Mutex::Lock() { - - lock.lock(); + lock.lock(); #ifndef NDEBUG - locked_ = true; + locked_ = true; #endif } void Mutex::Unlock() { - #ifndef NDEBUG - locked_ = false; + locked_ = false; #endif - lock.unlock(); + lock.unlock(); } void Mutex::AssertHeld() { #ifndef NDEBUG - assert(locked_); + assert(locked_); #endif } -CondVar::CondVar(Mutex* mu) : mu_(mu) { -} +CondVar::CondVar(Mutex* mu) : mu_(mu) {} -CondVar::~CondVar() { -} +CondVar::~CondVar() {} void CondVar::Wait() { #ifndef NDEBUG - mu_->locked_ = false; + mu_->locked_ = false; #endif - cv_.wait(mu_->getLock()); + cv_.wait(mu_->getLock()); #ifndef NDEBUG - mu_->locked_ = true; + mu_->locked_ = true; #endif } - bool CondVar::TimedWait(uint64_t abs_time_us) { #ifndef NDEBUG - mu_->locked_ = false; + mu_->locked_ = false; #endif - using namespace std::chrono; + using namespace std::chrono; - microseconds usAbsTime(abs_time_us); - microseconds usNow(duration_cast(system_clock::now().time_since_epoch())); - microseconds relTimeUs = (usAbsTime > usNow) ? (usAbsTime - usNow) : microseconds::zero(); + microseconds usAbsTime(abs_time_us); + microseconds usNow( + duration_cast(system_clock::now().time_since_epoch())); + microseconds relTimeUs = + (usAbsTime > usNow) ? (usAbsTime - usNow) : microseconds::zero(); - std::_Cv_status cvStatus = cv_.wait_for(mu_->getLock(), relTimeUs); + std::_Cv_status cvStatus = cv_.wait_for(mu_->getLock(), relTimeUs); #ifndef NDEBUG - mu_->locked_ = true; + mu_->locked_ = true; #endif - if (cvStatus == std::cv_status::timeout) { - return true; - } + if (cvStatus == std::cv_status::timeout) { + return true; + } - return false; + return false; } -void CondVar::Signal() { +void CondVar::Signal() { cv_.notify_one(); } - cv_.notify_one(); -} - -void CondVar::SignalAll() { - cv_.notify_all (); -} +void CondVar::SignalAll() { cv_.notify_all(); } void InitOnce(OnceType* once, void (*initializer)()) { - - std::call_once(*once, initializer); + std::call_once(*once, initializer); } // Private structure, exposed only by pointer struct DIR { - intptr_t handle_; - bool firstread_; - struct __finddata64_t data_; - dirent entry_; + intptr_t handle_; + bool firstread_; + struct __finddata64_t data_; + dirent entry_; - DIR() : handle_(-1), firstread_(true) {} + DIR() : handle_(-1), firstread_(true) {} - DIR(const DIR&) = delete; - DIR& operator=(const DIR&) = delete; + DIR(const DIR&) = delete; + DIR& operator=(const DIR&) = delete; - ~DIR() { - - if (-1 != handle_) { - _findclose(handle_); - } + ~DIR() { + if (-1 != handle_) { + _findclose(handle_); } + } }; - DIR* opendir(const char* name) { + if (!name || *name == 0) { + errno = ENOENT; + return nullptr; + } - if (!name || *name == 0) { - errno = ENOENT; - return nullptr; - } + std::string pattern(name); + pattern.append("\\").append("*"); - std::string pattern(name); - pattern.append("\\").append("*"); + std::unique_ptr dir(new DIR); - std::unique_ptr dir(new DIR); + dir->handle_ = _findfirst64(pattern.c_str(), &dir->data_); - dir->handle_ = _findfirst64(pattern.c_str(), &dir->data_); + if (dir->handle_ == -1) { + return nullptr; + } - if (dir->handle_ == -1) { - return nullptr; - } + strncpy_s(dir->entry_.d_name, dir->data_.name, strlen(dir->data_.name)); - strncpy_s(dir->entry_.d_name, dir->data_.name, strlen(dir->data_.name)); - - return dir.release(); + return dir.release(); } struct dirent* readdir(DIR* dirp) { + if (!dirp || dirp->handle_ == -1) { + errno = EBADF; + return nullptr; + } - if (!dirp || dirp->handle_ == -1) { - errno = EBADF; - return nullptr; - } - - if (dirp->firstread_) { - dirp->firstread_ = false; - return &dirp->entry_; - } - - auto ret = _findnext64(dirp->handle_, &dirp->data_); - - if (ret != 0) { - return nullptr; - } - - strncpy_s(dirp->entry_.d_name, dirp->data_.name, strlen(dirp->data_.name)); - + if (dirp->firstread_) { + dirp->firstread_ = false; return &dirp->entry_; + } + + auto ret = _findnext64(dirp->handle_, &dirp->data_); + + if (ret != 0) { + return nullptr; + } + + strncpy_s(dirp->entry_.d_name, dirp->data_.name, strlen(dirp->data_.name)); + + return &dirp->entry_; } int closedir(DIR* dirp) { - delete dirp; - return 0; + delete dirp; + return 0; } int truncate(const char* path, int64_t len) { - if (path == nullptr) { errno = EFAULT; return -1; @@ -213,13 +194,12 @@ int truncate(const char* path, int64_t len) { return -1; } - HANDLE hFile = CreateFile(path, - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, // Security attrs - OPEN_EXISTING, // Truncate existing file only - FILE_ATTRIBUTE_NORMAL, - NULL); + HANDLE hFile = + CreateFile(path, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, // Security attrs + OPEN_EXISTING, // Truncate existing file only + FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE == hFile) { auto lastError = GetLastError(); @@ -237,10 +217,8 @@ int truncate(const char* path, int64_t len) { FILE_END_OF_FILE_INFO end_of_file; end_of_file.EndOfFile.QuadPart = len; - if (!SetFileInformationByHandle(hFile, - FileEndOfFileInfo, - &end_of_file, - sizeof(FILE_END_OF_FILE_INFO))) { + if (!SetFileInformationByHandle(hFile, FileEndOfFileInfo, &end_of_file, + sizeof(FILE_END_OF_FILE_INFO))) { errno = EIO; result = -1; } @@ -260,14 +238,13 @@ namespace rocksdb { namespace port { -__declspec(noinline) -void WINAPI InitializeJemalloc() { - je_init(); - atexit(je_uninit); +__declspec(noinline) void WINAPI InitializeJemalloc() { + je_init(); + atexit(je_uninit); } -} // port -} // rocksdb +} // port +} // rocksdb extern "C" { @@ -275,37 +252,39 @@ extern "C" { #pragma comment(linker, "/INCLUDE:p_rocksdb_init_jemalloc") -typedef void (WINAPI *CRT_Startup_Routine)(void); +typedef void(WINAPI* CRT_Startup_Routine)(void); // .CRT section is merged with .rdata on x64 so it must be constant data. // must be of external linkage -// We put this into XCT since we want to run this earlier than C++ static constructors +// We put this into XCT since we want to run this earlier than C++ static +// constructors // which are placed into XCU #pragma const_seg(".CRT$XCT") extern const CRT_Startup_Routine p_rocksdb_init_jemalloc; -const CRT_Startup_Routine p_rocksdb_init_jemalloc = rocksdb::port::InitializeJemalloc; +const CRT_Startup_Routine p_rocksdb_init_jemalloc = + rocksdb::port::InitializeJemalloc; #pragma const_seg() -#else // _WIN64 +#else // _WIN64 // x86 untested #pragma comment(linker, "/INCLUDE:_p_rocksdb_init_jemalloc") #pragma section(".CRT$XCT", read) -JEMALLOC_SECTION(".CRT$XCT") JEMALLOC_ATTR(used) -static const void (WINAPI *p_rocksdb_init_jemalloc)(void) = rocksdb::port::InitializeJemalloc; +JEMALLOC_SECTION(".CRT$XCT") JEMALLOC_ATTR(used) static const void( + WINAPI* p_rocksdb_init_jemalloc)(void) = rocksdb::port::InitializeJemalloc; -#endif // _WIN64 +#endif // _WIN64 -} // extern "C" +} // extern "C" // Global operators to be replaced by a linker void* operator new(size_t size) { void* p = je_malloc(size); if (!p) { - throw std::bad_alloc(); + throw std::bad_alloc(); } return p; } @@ -318,13 +297,8 @@ void* operator new[](size_t size) { return p; } -void operator delete(void* p) { - je_free(p); -} +void operator delete(void* p) { je_free(p); } -void operator delete[](void* p) { - je_free(p); -} - -#endif // JEMALLOC +void operator delete[](void* p) { je_free(p); } +#endif // JEMALLOC diff --git a/port/win/port_win.h b/port/win/port_win.h index f9f7fc613..a0086c6aa 100644 --- a/port/win/port_win.h +++ b/port/win/port_win.h @@ -14,7 +14,7 @@ // Always want minimum headers #ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN #endif // Assume that for everywhere @@ -42,7 +42,8 @@ typedef SSIZE_T ssize_t; -// size_t printf formatting named in the manner of C99 standard formatting strings such as PRIu64 +// size_t printf formatting named in the manner of C99 standard formatting +// strings such as PRIu64 // in fact, we could use that one #define ROCKSDB_PRIszt "Iu" @@ -77,8 +78,7 @@ namespace rocksdb { #define PREFETCH(addr, rw, locality) -namespace port -{ +namespace port { // For use at db/file_indexer.h kLevelMaxIndex const int kMaxInt32 = INT32_MAX; @@ -88,82 +88,67 @@ const bool kLittleEndian = true; class CondVar; -class Mutex -{ -public: - /* implicit */ Mutex(bool adaptive = false); - ~Mutex(); +class Mutex { + public: + /* implicit */ Mutex(bool adaptive = false); + ~Mutex(); - void Lock(); - void Unlock(); - - // this will assert if the mutex is not locked - // it does NOT verify that mutex is held by a calling thread - void AssertHeld(); + void Lock(); + void Unlock(); - std::unique_lock& getLock() { - return lock; - } + // this will assert if the mutex is not locked + // it does NOT verify that mutex is held by a calling thread + void AssertHeld(); -private: - friend class CondVar; - std::mutex m_mutex; - std::unique_lock lock; + std::unique_lock& getLock() { return lock; } + + private: + friend class CondVar; + std::mutex m_mutex; + std::unique_lock lock; #ifndef NDEBUG - bool locked_; + bool locked_; #endif - // No copying - Mutex(const Mutex&); - void operator=(const Mutex&); + // No copying + Mutex(const Mutex&); + void operator=(const Mutex&); }; -class RWMutex -{ -public: - RWMutex() { - InitializeSRWLock(&srwLock_); - } +class RWMutex { + public: + RWMutex() { InitializeSRWLock(&srwLock_); } - void ReadLock() { - AcquireSRWLockShared(&srwLock_); - } + void ReadLock() { AcquireSRWLockShared(&srwLock_); } - void WriteLock() { - AcquireSRWLockExclusive(&srwLock_); - } + void WriteLock() { AcquireSRWLockExclusive(&srwLock_); } - void ReadUnlock() { - ReleaseSRWLockShared(&srwLock_); - } + void ReadUnlock() { ReleaseSRWLockShared(&srwLock_); } - void WriteUnlock() { - ReleaseSRWLockExclusive(&srwLock_); - } + void WriteUnlock() { ReleaseSRWLockExclusive(&srwLock_); } - // Empty as in POSIX - void AssertHeld() { } - -private: + // Empty as in POSIX + void AssertHeld() {} + private: SRWLOCK srwLock_; // No copying allowed RWMutex(const RWMutex&); void operator=(const RWMutex&); }; -class CondVar -{ -public: - explicit CondVar(Mutex* mu); - ~CondVar(); - void Wait(); - bool TimedWait(uint64_t expiration_time); - void Signal(); - void SignalAll(); -private: - std::condition_variable cv_; - Mutex * mu_; +class CondVar { + public: + explicit CondVar(Mutex* mu); + ~CondVar(); + void Wait(); + bool TimedWait(uint64_t expiration_time); + void Signal(); + void SignalAll(); + + private: + std::condition_variable cv_; + Mutex* mu_; }; typedef std::once_flag OnceType; @@ -171,16 +156,15 @@ typedef std::once_flag OnceType; extern void InitOnce(OnceType* once, void (*initializer)()); inline bool Snappy_Compress(const CompressionOptions& opts, const char* input, - size_t length, ::std::string* output) -{ + size_t length, ::std::string* output) { #ifdef SNAPPY - output->resize(snappy::MaxCompressedLength(length)); - size_t outlen; - snappy::RawCompress(input, length, &(*output)[0], &outlen); - output->resize(outlen); - return true; + output->resize(snappy::MaxCompressedLength(length)); + size_t outlen; + snappy::RawCompress(input, length, &(*output)[0], &outlen); + output->resize(outlen); + return true; #endif - return false; + return false; } inline bool Snappy_GetUncompressedLength(const char* input, size_t length, @@ -192,8 +176,7 @@ inline bool Snappy_GetUncompressedLength(const char* input, size_t length, #endif } -inline bool Snappy_Uncompress(const char* input, size_t length, - char* output) { +inline bool Snappy_Uncompress(const char* input, size_t length, char* output) { #ifdef SNAPPY return snappy::RawUncompress(input, length, output); #else @@ -223,14 +206,14 @@ inline bool Zlib_Compress(const CompressionOptions& opts, const char* input, output->resize(length); // Compress the input, and put compressed data in output. - _stream.next_in = (Bytef *)input; + _stream.next_in = (Bytef*)input; _stream.avail_in = length; // Initialize the output size. _stream.avail_out = length; - _stream.next_out = (Bytef *)&(*output)[0]; + _stream.next_out = (Bytef*)&(*output)[0]; - int old_sz =0, new_sz =0, new_sz_delta =0; + int old_sz = 0, new_sz = 0, new_sz_delta = 0; bool done = false; while (!done) { int st = deflate(&_stream, Z_FINISH); @@ -246,7 +229,7 @@ inline bool Zlib_Compress(const CompressionOptions& opts, const char* input, new_sz = output->size() + (new_sz_delta < 10 ? 10 : new_sz_delta); output->resize(new_sz); // Set more output. - _stream.next_out = (Bytef *)&(*output)[old_sz]; + _stream.next_out = (Bytef*)&(*output)[old_sz]; _stream.avail_out = new_sz - old_sz; break; case Z_BUF_ERROR: @@ -264,7 +247,7 @@ inline bool Zlib_Compress(const CompressionOptions& opts, const char* input, } inline char* Zlib_Uncompress(const char* input_data, size_t input_length, - int* decompress_size, int windowBits = -14) { + int* decompress_size, int windowBits = -14) { #ifdef ZLIB z_stream _stream; memset(&_stream, 0, sizeof(z_stream)); @@ -272,13 +255,13 @@ inline char* Zlib_Uncompress(const char* input_data, size_t input_length, // For raw inflate, the windowBits should be -8..-15. // If windowBits is bigger than zero, it will use either zlib // header or gzip header. Adding 32 to it will do automatic detection. - int st = inflateInit2(&_stream, - windowBits > 0 ? windowBits + 32 : windowBits); + int st = + inflateInit2(&_stream, windowBits > 0 ? windowBits + 32 : windowBits); if (st != Z_OK) { return nullptr; } - _stream.next_in = (Bytef *)input_data; + _stream.next_in = (Bytef*)input_data; _stream.avail_in = input_length; // Assume the decompressed data size will 5x of compressed size. @@ -286,14 +269,14 @@ inline char* Zlib_Uncompress(const char* input_data, size_t input_length, char* output = new char[output_len]; int old_sz = output_len; - _stream.next_out = (Bytef *)output; + _stream.next_out = (Bytef*)output; _stream.avail_out = output_len; char* tmp = nullptr; int output_len_delta; bool done = false; - //while(_stream.next_in != nullptr && _stream.avail_in != 0) { + // while(_stream.next_in != nullptr && _stream.avail_in != 0) { while (!done) { int st = inflate(&_stream, Z_SYNC_FLUSH); switch (st) { @@ -311,7 +294,7 @@ inline char* Zlib_Uncompress(const char* input_data, size_t input_length, output = tmp; // Set more output. - _stream.next_out = (Bytef *)(output + old_sz); + _stream.next_out = (Bytef*)(output + old_sz); _stream.avail_out = output_len - old_sz; break; case Z_BUF_ERROR: @@ -349,15 +332,15 @@ inline bool BZip2_Compress(const CompressionOptions& opts, const char* input, output->resize(length); // Compress the input, and put compressed data in output. - _stream.next_in = (char *)input; + _stream.next_in = (char*)input; _stream.avail_in = length; // Initialize the output size. - _stream.next_out = (char *)&(*output)[0]; + _stream.next_out = (char*)&(*output)[0]; _stream.avail_out = length; - int old_sz =0, new_sz =0; - while(_stream.next_in != nullptr && _stream.avail_in != 0) { + int old_sz = 0, new_sz = 0; + while (_stream.next_in != nullptr && _stream.avail_in != 0) { int st = BZ2_bzCompress(&_stream, BZ_FINISH); switch (st) { case BZ_STREAM_END: @@ -369,7 +352,7 @@ inline bool BZip2_Compress(const CompressionOptions& opts, const char* input, new_sz = (int)(output->size() * 1.2); output->resize(new_sz); // Set more output. - _stream.next_out = (char *)&(*output)[old_sz]; + _stream.next_out = (char*)&(*output)[old_sz]; _stream.avail_out = new_sz - old_sz; break; case BZ_SEQUENCE_ERROR: @@ -397,7 +380,7 @@ inline char* BZip2_Uncompress(const char* input_data, size_t input_length, return nullptr; } - _stream.next_in = (char *)input_data; + _stream.next_in = (char*)input_data; _stream.avail_in = input_length; // Assume the decompressed data size will be 5x of compressed size. @@ -405,12 +388,12 @@ inline char* BZip2_Uncompress(const char* input_data, size_t input_length, char* output = new char[output_len]; int old_sz = output_len; - _stream.next_out = (char *)output; + _stream.next_out = (char*)output; _stream.avail_out = output_len; char* tmp = nullptr; - while(_stream.next_in != nullptr && _stream.avail_in != 0) { + while (_stream.next_in != nullptr && _stream.avail_in != 0) { int st = BZ2_bzDecompress(&_stream); switch (st) { case BZ_STREAM_END: @@ -425,7 +408,7 @@ inline char* BZip2_Uncompress(const char* input_data, size_t input_length, output = tmp; // Set more output. - _stream.next_out = (char *)(output + old_sz); + _stream.next_out = (char*)(output + old_sz); _stream.avail_out = output_len - old_sz; break; default: @@ -442,12 +425,12 @@ inline char* BZip2_Uncompress(const char* input_data, size_t input_length, return nullptr; } -inline bool LZ4_Compress(const CompressionOptions &opts, const char *input, +inline bool LZ4_Compress(const CompressionOptions& opts, const char* input, size_t length, ::std::string* output) { #ifdef LZ4 int compressBound = LZ4_compressBound(length); output->resize(8 + compressBound); - char *p = const_cast(output->c_str()); + char* p = const_cast(output->c_str()); memcpy(p, &length, sizeof(length)); size_t outlen; outlen = LZ4_compress_limitedOutput(input, p + 8, length, compressBound); @@ -468,7 +451,7 @@ inline char* LZ4_Uncompress(const char* input_data, size_t input_length, } int output_len; memcpy(&output_len, input_data, sizeof(output_len)); - char *output = new char[output_len]; + char* output = new char[output_len]; *decompress_size = LZ4_decompress_safe_partial( input_data + 8, output, input_length - 8, output_len, output_len); if (*decompress_size < 0) { @@ -480,12 +463,12 @@ inline char* LZ4_Uncompress(const char* input_data, size_t input_length, return nullptr; } -inline bool LZ4HC_Compress(const CompressionOptions &opts, const char* input, +inline bool LZ4HC_Compress(const CompressionOptions& opts, const char* input, size_t length, ::std::string* output) { #ifdef LZ4 int compressBound = LZ4_compressBound(length); output->resize(8 + compressBound); - char *p = const_cast(output->c_str()); + char* p = const_cast(output->c_str()); memcpy(p, &length, sizeof(length)); size_t outlen; #ifdef LZ4_VERSION_MAJOR // they only started defining this since r113 @@ -515,47 +498,43 @@ inline bool LZ4HC_Compress(const CompressionOptions &opts, const char* input, // For Thread Local Storage abstraction typedef DWORD pthread_key_t; -inline -int pthread_key_create(pthread_key_t *key, void(*destructor)(void*)) { - // Not used - (void)destructor; +inline int pthread_key_create(pthread_key_t* key, void (*destructor)(void*)) { + // Not used + (void)destructor; - pthread_key_t k = TlsAlloc(); - if (TLS_OUT_OF_INDEXES == k) { - return ENOMEM; - } + pthread_key_t k = TlsAlloc(); + if (TLS_OUT_OF_INDEXES == k) { + return ENOMEM; + } - *key = k; - return 0; + *key = k; + return 0; } -inline -int pthread_key_delete(pthread_key_t key) { - if (!TlsFree(key)) { - return EINVAL; - } - return 0; +inline int pthread_key_delete(pthread_key_t key) { + if (!TlsFree(key)) { + return EINVAL; + } + return 0; } -inline -int pthread_setspecific(pthread_key_t key, const void *value) { - if (!TlsSetValue(key, const_cast(value))) { - return ENOMEM; - } - return 0; +inline int pthread_setspecific(pthread_key_t key, const void* value) { + if (!TlsSetValue(key, const_cast(value))) { + return ENOMEM; + } + return 0; } -inline -void* pthread_getspecific(pthread_key_t key) { - void* result = TlsGetValue(key); - if (!result) { - if (GetLastError() != ERROR_SUCCESS) { - errno = EINVAL; - } else { - errno = NOERROR; - } +inline void* pthread_getspecific(pthread_key_t key) { + void* result = TlsGetValue(key); + if (!result) { + if (GetLastError() != ERROR_SUCCESS) { + errno = EINVAL; + } else { + errno = NOERROR; } - return result; + } + return result; } // UNIX equiv although errno numbers will be off @@ -563,7 +542,7 @@ void* pthread_getspecific(pthread_key_t key) { // feel space with zeros in case the file is extended. int truncate(const char* path, int64_t length); -} // namespace port +} // namespace port using port::pthread_key_t; using port::pthread_key_create; @@ -572,6 +551,6 @@ using port::pthread_setspecific; using port::pthread_getspecific; using port::truncate; -} // namespace rocksdb +} // namespace rocksdb #endif // STORAGE_LEVELDB_PORT_PORT_POSIX_H_ diff --git a/port/win/win_logger.cc b/port/win/win_logger.cc index 44c279af3..a4cf2de65 100644 --- a/port/win/win_logger.cc +++ b/port/win/win_logger.cc @@ -24,42 +24,37 @@ namespace rocksdb { -WinLogger::WinLogger(uint64_t (*gettid)(), Env* env, FILE * file, const InfoLogLevel log_level) - : Logger(log_level), - gettid_(gettid), - log_size_(0), - last_flush_micros_(0), - env_(env), - flush_pending_(false), - file_(file) { -} +WinLogger::WinLogger(uint64_t (*gettid)(), Env* env, FILE* file, + const InfoLogLevel log_level) + : Logger(log_level), + gettid_(gettid), + log_size_(0), + last_flush_micros_(0), + env_(env), + flush_pending_(false), + file_(file) {} void WinLogger::DebugWriter(const char* str, int len) { - size_t sz = fwrite(str, 1, len, file_); - if (sz == 0) { - perror("fwrite .. [BAD]"); - } + size_t sz = fwrite(str, 1, len, file_); + if (sz == 0) { + perror("fwrite .. [BAD]"); + } } -WinLogger::~WinLogger() { - close(); -} +WinLogger::~WinLogger() { close(); } -void WinLogger::close() { - fclose(file_); -} +void WinLogger::close() { fclose(file_); } void WinLogger::Flush() { - if (flush_pending_) { - flush_pending_ = false; - fflush(file_); - } + if (flush_pending_) { + flush_pending_ = false; + fflush(file_); + } - last_flush_micros_ = env_->NowMicros(); + last_flush_micros_ = env_->NowMicros(); } void WinLogger::Logv(const char* format, va_list ap) { - IOSTATS_TIMER_GUARD(logger_nanos); const uint64_t thread_id = (*gettid_)(); @@ -69,88 +64,82 @@ void WinLogger::Logv(const char* format, va_list ap) { char buffer[500]; std::unique_ptr largeBuffer; for (int iter = 0; iter < 2; ++iter) { - char* base; - int bufsize; - if (iter == 0) { - bufsize = sizeof(buffer); - base = buffer; + char* base; + int bufsize; + if (iter == 0) { + bufsize = sizeof(buffer); + base = buffer; + } else { + bufsize = 30000; + largeBuffer.reset(new char[bufsize]); + base = largeBuffer.get(); + } + + char* p = base; + char* limit = base + bufsize; + + struct timeval now_tv; + gettimeofday(&now_tv, nullptr); + const time_t seconds = now_tv.tv_sec; + struct tm t; + localtime_s(&t, &seconds); + p += snprintf(p, limit - p, "%04d/%02d/%02d-%02d:%02d:%02d.%06d %llx ", + t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, + t.tm_min, t.tm_sec, static_cast(now_tv.tv_usec), + static_cast(thread_id)); + + // Print the message + if (p < limit) { + va_list backup_ap; + va_copy(backup_ap, ap); + int done = vsnprintf(p, limit - p, format, backup_ap); + if (done > 0) { + p += done; } else { - bufsize = 30000; - largeBuffer.reset(new char[bufsize]); - base = largeBuffer.get(); + continue; } + va_end(backup_ap); + } - char* p = base; - char* limit = base + bufsize; - - struct timeval now_tv; - gettimeofday(&now_tv, nullptr); - const time_t seconds = now_tv.tv_sec; - struct tm t; - localtime_s(&t, &seconds); - p += snprintf(p, limit - p, "%04d/%02d/%02d-%02d:%02d:%02d.%06d %llx ", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, - t.tm_hour, - t.tm_min, - t.tm_sec, - static_cast(now_tv.tv_usec), - static_cast(thread_id)); - - // Print the message - if (p < limit) { - va_list backup_ap; - va_copy(backup_ap, ap); - int done = vsnprintf(p, limit - p, format, backup_ap); - if (done > 0){ - p += done; - } else { - continue; - } - va_end(backup_ap); + // Truncate to available space if necessary + if (p >= limit) { + if (iter == 0) { + continue; // Try again with larger buffer + } else { + p = limit - 1; } + } - // Truncate to available space if necessary - if (p >= limit) { - if (iter == 0) - { - continue; // Try again with larger buffer - } else { - p = limit - 1; - } - } + // Add newline if necessary + if (p == base || p[-1] != '\n') { + *p++ = '\n'; + } - // Add newline if necessary - if (p == base || p[-1] != '\n') { - *p++ = '\n'; - } + assert(p <= limit); + const size_t write_size = p - base; - assert(p <= limit); - const size_t write_size = p - base; + size_t sz = fwrite(base, 1, write_size, file_); + if (sz == 0) { + perror("fwrite .. [BAD]"); + } - size_t sz = fwrite(base, 1, write_size, file_); - if (sz == 0) { - perror("fwrite .. [BAD]"); - } + flush_pending_ = true; + assert(sz == write_size); + if (sz > 0) { + log_size_ += write_size; + } - flush_pending_ = true; - assert(sz == write_size); - if (sz > 0) { - log_size_ += write_size; - } - - uint64_t now_micros = static_cast(now_tv.tv_sec) * 1000000 + - now_tv.tv_usec; - if (now_micros - last_flush_micros_ >= flush_every_seconds_ * 1000000) { - flush_pending_ = false; - fflush(file_); - last_flush_micros_ = now_micros; - } - break; + uint64_t now_micros = + static_cast(now_tv.tv_sec) * 1000000 + now_tv.tv_usec; + if (now_micros - last_flush_micros_ >= flush_every_seconds_ * 1000000) { + flush_pending_ = false; + fflush(file_); + last_flush_micros_ = now_micros; + } + break; } } -size_t WinLogger::GetLogFileSize() const { - return log_size_; -} - +size_t WinLogger::GetLogFileSize() const { return log_size_; } } // namespace rocksdb diff --git a/port/win/win_logger.h b/port/win/win_logger.h index b7c85100b..3f330d488 100644 --- a/port/win/win_logger.h +++ b/port/win/win_logger.h @@ -23,8 +23,8 @@ class Env; const int kDebugLogChunkSize = 128 * 1024; class WinLogger : public rocksdb::Logger { -public: - WinLogger(uint64_t(*gettid)(), Env* env, FILE * file, + public: + WinLogger(uint64_t (*gettid)(), Env* env, FILE* file, const InfoLogLevel log_level = InfoLogLevel::ERROR_LEVEL); virtual ~WinLogger(); @@ -43,14 +43,13 @@ public: void DebugWriter(const char* str, int len); -private: - - FILE* file_; - uint64_t(*gettid_)(); // Return the thread id for the current thread - std::atomic_size_t log_size_; + private: + FILE* file_; + uint64_t (*gettid_)(); // Return the thread id for the current thread + std::atomic_size_t log_size_; std::atomic_uint_fast64_t last_flush_micros_; - Env* env_; - bool flush_pending_; + Env* env_; + bool flush_pending_; const static uint64_t flush_every_seconds_ = 5; }; diff --git a/table/block_based_table_builder.cc b/table/block_based_table_builder.cc index 4b58e9382..588f2475b 100644 --- a/table/block_based_table_builder.cc +++ b/table/block_based_table_builder.cc @@ -374,8 +374,10 @@ Slice CompressBlock(const Slice& raw, // kBlockBasedTableMagicNumber was picked by running // echo rocksdb.table.block_based | sha1sum // and taking the leading 64 bits. -// Please note that kBlockBasedTableMagicNumber may also be accessed by other .cc files -// for that reason we declare it extern in the header but to get the space allocated +// Please note that kBlockBasedTableMagicNumber may also be accessed by other +// .cc files +// for that reason we declare it extern in the header but to get the space +// allocated // it must be not extern in one place. const uint64_t kBlockBasedTableMagicNumber = 0x88e241b785f4cff7ull; // We also support reading and writing legacy block based table format (for diff --git a/table/block_based_table_factory.cc b/table/block_based_table_factory.cc index 66310c414..6c1e0a21c 100644 --- a/table/block_based_table_factory.cc +++ b/table/block_based_table_factory.cc @@ -123,7 +123,8 @@ std::string BlockBasedTableFactory::GetPrintableTableOptions() const { table_options_.block_cache_compressed.get()); ret.append(buffer); if (table_options_.block_cache_compressed) { - snprintf(buffer, kBufferSize, " block_cache_compressed_size: %" ROCKSDB_PRIszt "\n", + snprintf(buffer, kBufferSize, + " block_cache_compressed_size: %" ROCKSDB_PRIszt "\n", table_options_.block_cache_compressed->GetCapacity()); ret.append(buffer); } diff --git a/table/cuckoo_table_builder_test.cc b/table/cuckoo_table_builder_test.cc index 0003d75ad..bd9283659 100644 --- a/table/cuckoo_table_builder_test.cc +++ b/table/cuckoo_table_builder_test.cc @@ -146,14 +146,13 @@ TEST_F(CuckooBuilderTest, WriteSuccessNoCollisionFullKey) { uint32_t num_hash_fun = 4; std::vector user_keys = {"key01", "key02", "key03", "key04"}; std::vector values = {"v01", "v02", "v03", "v04"}; - // Need to have a temporary variable here as VS compiler does not currently support operator= with initializer_list as a parameter - std::unordered_map> hm = - { - {user_keys[0], {0, 1, 2, 3}}, - {user_keys[1], {1, 2, 3, 4}}, - {user_keys[2], {2, 3, 4, 5}}, - {user_keys[3], {3, 4, 5, 6}} - }; + // Need to have a temporary variable here as VS compiler does not currently + // support operator= with initializer_list as a parameter + std::unordered_map> hm = { + {user_keys[0], {0, 1, 2, 3}}, + {user_keys[1], {1, 2, 3, 4}}, + {user_keys[2], {2, 3, 4, 5}}, + {user_keys[3], {3, 4, 5, 6}}}; hash_map = std::move(hm); std::vector expected_locations = {0, 1, 2, 3}; @@ -190,13 +189,13 @@ TEST_F(CuckooBuilderTest, WriteSuccessWithCollisionFullKey) { uint32_t num_hash_fun = 4; std::vector user_keys = {"key01", "key02", "key03", "key04"}; std::vector values = {"v01", "v02", "v03", "v04"}; - // Need to have a temporary variable here as VS compiler does not currently support operator= with initializer_list as a parameter - std::unordered_map> hm = - { - {user_keys[0], {0, 1, 2, 3}}, - {user_keys[1], {0, 1, 2, 3}}, - {user_keys[2], {0, 1, 2, 3}}, - {user_keys[3], {0, 1, 2, 3}}, + // Need to have a temporary variable here as VS compiler does not currently + // support operator= with initializer_list as a parameter + std::unordered_map> hm = { + {user_keys[0], {0, 1, 2, 3}}, + {user_keys[1], {0, 1, 2, 3}}, + {user_keys[2], {0, 1, 2, 3}}, + {user_keys[3], {0, 1, 2, 3}}, }; hash_map = std::move(hm); @@ -234,13 +233,13 @@ TEST_F(CuckooBuilderTest, WriteSuccessWithCollisionAndCuckooBlock) { uint32_t num_hash_fun = 4; std::vector user_keys = {"key01", "key02", "key03", "key04"}; std::vector values = {"v01", "v02", "v03", "v04"}; - // Need to have a temporary variable here as VS compiler does not currently support operator= with initializer_list as a parameter - std::unordered_map> hm = - { - {user_keys[0], {0, 1, 2, 3}}, - {user_keys[1], {0, 1, 2, 3}}, - {user_keys[2], {0, 1, 2, 3}}, - {user_keys[3], {0, 1, 2, 3}}, + // Need to have a temporary variable here as VS compiler does not currently + // support operator= with initializer_list as a parameter + std::unordered_map> hm = { + {user_keys[0], {0, 1, 2, 3}}, + {user_keys[1], {0, 1, 2, 3}}, + {user_keys[2], {0, 1, 2, 3}}, + {user_keys[3], {0, 1, 2, 3}}, }; hash_map = std::move(hm); @@ -284,14 +283,14 @@ TEST_F(CuckooBuilderTest, WithCollisionPathFullKey) { std::vector user_keys = {"key01", "key02", "key03", "key04", "key05"}; std::vector values = {"v01", "v02", "v03", "v04", "v05"}; - // Need to have a temporary variable here as VS compiler does not currently support operator= with initializer_list as a parameter - std::unordered_map> hm = - { - {user_keys[0], {0, 1}}, - {user_keys[1], {1, 2}}, - {user_keys[2], {2, 3}}, - {user_keys[3], {3, 4}}, - {user_keys[4], {0, 2}}, + // Need to have a temporary variable here as VS compiler does not currently + // support operator= with initializer_list as a parameter + std::unordered_map> hm = { + {user_keys[0], {0, 1}}, + {user_keys[1], {1, 2}}, + {user_keys[2], {2, 3}}, + {user_keys[3], {3, 4}}, + {user_keys[4], {0, 2}}, }; hash_map = std::move(hm); @@ -330,14 +329,14 @@ TEST_F(CuckooBuilderTest, WithCollisionPathFullKeyAndCuckooBlock) { std::vector user_keys = {"key01", "key02", "key03", "key04", "key05"}; std::vector values = {"v01", "v02", "v03", "v04", "v05"}; - // Need to have a temporary variable here as VS compiler does not currently support operator= with initializer_list as a parameter - std::unordered_map> hm = - { - {user_keys[0], {0, 1}}, - {user_keys[1], {1, 2}}, - {user_keys[2], {3, 4}}, - {user_keys[3], {4, 5}}, - {user_keys[4], {0, 3}}, + // Need to have a temporary variable here as VS compiler does not currently + // support operator= with initializer_list as a parameter + std::unordered_map> hm = { + {user_keys[0], {0, 1}}, + {user_keys[1], {1, 2}}, + {user_keys[2], {3, 4}}, + {user_keys[3], {4, 5}}, + {user_keys[4], {0, 3}}, }; hash_map = std::move(hm); @@ -375,14 +374,13 @@ TEST_F(CuckooBuilderTest, WriteSuccessNoCollisionUserKey) { uint32_t num_hash_fun = 4; std::vector user_keys = {"key01", "key02", "key03", "key04"}; std::vector values = {"v01", "v02", "v03", "v04"}; - // Need to have a temporary variable here as VS compiler does not currently support operator= with initializer_list as a parameter - std::unordered_map> hm = - { - {user_keys[0], {0, 1, 2, 3}}, - {user_keys[1], {1, 2, 3, 4}}, - {user_keys[2], {2, 3, 4, 5}}, - {user_keys[3], {3, 4, 5, 6}} - }; + // Need to have a temporary variable here as VS compiler does not currently + // support operator= with initializer_list as a parameter + std::unordered_map> hm = { + {user_keys[0], {0, 1, 2, 3}}, + {user_keys[1], {1, 2, 3, 4}}, + {user_keys[2], {2, 3, 4, 5}}, + {user_keys[3], {3, 4, 5, 6}}}; hash_map = std::move(hm); std::vector expected_locations = {0, 1, 2, 3}; @@ -415,13 +413,13 @@ TEST_F(CuckooBuilderTest, WriteSuccessWithCollisionUserKey) { uint32_t num_hash_fun = 4; std::vector user_keys = {"key01", "key02", "key03", "key04"}; std::vector values = {"v01", "v02", "v03", "v04"}; - // Need to have a temporary variable here as VS compiler does not currently support operator= with initializer_list as a parameter - std::unordered_map> hm = - { - {user_keys[0], {0, 1, 2, 3}}, - {user_keys[1], {0, 1, 2, 3}}, - {user_keys[2], {0, 1, 2, 3}}, - {user_keys[3], {0, 1, 2, 3}}, + // Need to have a temporary variable here as VS compiler does not currently + // support operator= with initializer_list as a parameter + std::unordered_map> hm = { + {user_keys[0], {0, 1, 2, 3}}, + {user_keys[1], {0, 1, 2, 3}}, + {user_keys[2], {0, 1, 2, 3}}, + {user_keys[3], {0, 1, 2, 3}}, }; hash_map = std::move(hm); @@ -456,14 +454,14 @@ TEST_F(CuckooBuilderTest, WithCollisionPathUserKey) { std::vector user_keys = {"key01", "key02", "key03", "key04", "key05"}; std::vector values = {"v01", "v02", "v03", "v04", "v05"}; - // Need to have a temporary variable here as VS compiler does not currently support operator= with initializer_list as a parameter - std::unordered_map> hm = - { - {user_keys[0], {0, 1}}, - {user_keys[1], {1, 2}}, - {user_keys[2], {2, 3}}, - {user_keys[3], {3, 4}}, - {user_keys[4], {0, 2}}, + // Need to have a temporary variable here as VS compiler does not currently + // support operator= with initializer_list as a parameter + std::unordered_map> hm = { + {user_keys[0], {0, 1}}, + {user_keys[1], {1, 2}}, + {user_keys[2], {2, 3}}, + {user_keys[3], {3, 4}}, + {user_keys[4], {0, 2}}, }; hash_map = std::move(hm); @@ -500,14 +498,14 @@ TEST_F(CuckooBuilderTest, FailWhenCollisionPathTooLong) { uint32_t num_hash_fun = 2; std::vector user_keys = {"key01", "key02", "key03", "key04", "key05"}; - // Need to have a temporary variable here as VS compiler does not currently support operator= with initializer_list as a parameter - std::unordered_map> hm = - { - {user_keys[0], {0, 1}}, - {user_keys[1], {1, 2}}, - {user_keys[2], {2, 3}}, - {user_keys[3], {3, 4}}, - {user_keys[4], {0, 1}}, + // Need to have a temporary variable here as VS compiler does not currently + // support operator= with initializer_list as a parameter + std::unordered_map> hm = { + {user_keys[0], {0, 1}}, + {user_keys[1], {1, 2}}, + {user_keys[2], {2, 3}}, + {user_keys[3], {3, 4}}, + {user_keys[4], {0, 1}}, }; hash_map = std::move(hm); @@ -527,8 +525,10 @@ TEST_F(CuckooBuilderTest, FailWhenCollisionPathTooLong) { } TEST_F(CuckooBuilderTest, FailWhenSameKeyInserted) { - // Need to have a temporary variable here as VS compiler does not currently support operator= with initializer_list as a parameter - std::unordered_map> hm = { { "repeatedkey", { 0, 1, 2, 3 } } }; + // Need to have a temporary variable here as VS compiler does not currently + // support operator= with initializer_list as a parameter + std::unordered_map> hm = { + {"repeatedkey", {0, 1, 2, 3}}}; hash_map = std::move(hm); uint32_t num_hash_fun = 4; std::string user_key = "repeatedkey"; diff --git a/table/cuckoo_table_factory.h b/table/cuckoo_table_factory.h index 63a760997..c78fe6931 100644 --- a/table/cuckoo_table_factory.h +++ b/table/cuckoo_table_factory.h @@ -18,9 +18,9 @@ static inline uint64_t CuckooHash( const Slice& user_key, uint32_t hash_cnt, bool use_module_hash, uint64_t table_size_, bool identity_as_first_hash, uint64_t (*get_slice_hash)(const Slice&, uint32_t, uint64_t)) { - #if !defined NDEBUG || defined OS_WIN - // This part is used only in unit tests but we have to keep it for Windows build as we run test in both debug and release modes under Windows. + // This part is used only in unit tests but we have to keep it for Windows + // build as we run test in both debug and release modes under Windows. if (get_slice_hash != nullptr) { return get_slice_hash(user_key, hash_cnt, table_size_); } diff --git a/table/format.h b/table/format.h index 7b231da28..5f1a3dc96 100644 --- a/table/format.h +++ b/table/format.h @@ -182,19 +182,17 @@ struct BlockContents { BlockContents() : cachable(false), compression_type(kNoCompression) {} BlockContents(const Slice& _data, bool _cachable, - CompressionType _compression_type) - : data(_data), cachable(_cachable), compression_type(_compression_type) {} + CompressionType _compression_type) + : data(_data), cachable(_cachable), compression_type(_compression_type) {} BlockContents(std::unique_ptr&& _data, size_t _size, bool _cachable, - CompressionType _compression_type) - : data(_data.get(), _size), - cachable(_cachable), - compression_type(_compression_type), - allocation(std::move(_data)) {} + CompressionType _compression_type) + : data(_data.get(), _size), + cachable(_cachable), + compression_type(_compression_type), + allocation(std::move(_data)) {} - BlockContents(BlockContents&& other) { - *this = std::move(other); - } + BlockContents(BlockContents&& other) { *this = std::move(other); } BlockContents& operator=(BlockContents&& other) { data = std::move(other.data); diff --git a/table/plain_table_index.cc b/table/plain_table_index.cc index 1f1ed5456..3e422c3c2 100644 --- a/table/plain_table_index.cc +++ b/table/plain_table_index.cc @@ -203,8 +203,8 @@ Slice PlainTableIndexBuilder::FillIndexes( assert(sub_index_offset == sub_index_size_); Log(InfoLogLevel::DEBUG_LEVEL, ioptions_.info_log, - "hash table size: %d, suffix_map length %" ROCKSDB_PRIszt, - index_size_, sub_index_size_); + "hash table size: %d, suffix_map length %" ROCKSDB_PRIszt, index_size_, + sub_index_size_); return Slice(allocated, GetTotalSize()); } diff --git a/third-party/fbson/FbsonDocument.h b/third-party/fbson/FbsonDocument.h index a9a8afa47..c70f9ecb2 100644 --- a/third-party/fbson/FbsonDocument.h +++ b/third-party/fbson/FbsonDocument.h @@ -472,7 +472,7 @@ class BlobVal : public FbsonValue { BlobVal(); -private: + private: // Disable as this class can only be allocated dynamically BlobVal(const BlobVal&) = delete; BlobVal& operator=(const BlobVal&) = delete; diff --git a/third-party/fbson/FbsonStream.h b/third-party/fbson/FbsonStream.h index bd59ea172..22851240d 100644 --- a/third-party/fbson/FbsonStream.h +++ b/third-party/fbson/FbsonStream.h @@ -31,10 +31,9 @@ #endif #if defined OS_WIN && !defined snprintf -# define snprintf _snprintf +#define snprintf _snprintf #endif - #include #include diff --git a/tools/db_repl_stress.cc b/tools/db_repl_stress.cc index 22e30344e..0fca5d506 100644 --- a/tools/db_repl_stress.cc +++ b/tools/db_repl_stress.cc @@ -137,8 +137,10 @@ int main(int argc, const char** argv) { replThread.stop.store(true, std::memory_order_release); if (replThread.no_read < dataPump.no_records) { // no. read should be => than inserted. - fprintf(stderr, "No. of Record's written and read not same\nRead : %" ROCKSDB_PRIszt - " Written : %" ROCKSDB_PRIszt "\n", replThread.no_read, dataPump.no_records); + fprintf(stderr, + "No. of Record's written and read not same\nRead : %" ROCKSDB_PRIszt + " Written : %" ROCKSDB_PRIszt "\n", + replThread.no_read, dataPump.no_records); exit(1); } fprintf(stderr, "Successful!\n"); diff --git a/tools/db_stress.cc b/tools/db_stress.cc index 9e4ed58c9..173b93371 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -770,7 +770,7 @@ class SharedState { std::vector> values_; // Has to make it owned by a smart ptr as port::Mutex is not copyable // and storing it in the container may require copying depending on the impl. - std::vector>> key_locks_; + std::vector > > key_locks_; }; const uint32_t SharedState::SENTINEL = 0xffffffff; @@ -937,115 +937,90 @@ class StressTest { return true; } - std::unordered_map> options_tbl = { - {"write_buffer_size", - { - ToString(FLAGS_write_buffer_size), + std::unordered_map > options_tbl = { + {"write_buffer_size", + {ToString(FLAGS_write_buffer_size), ToString(FLAGS_write_buffer_size * 2), - ToString(FLAGS_write_buffer_size * 4) - } - }, - {"max_write_buffer_number", - { - ToString(FLAGS_max_write_buffer_number), + ToString(FLAGS_write_buffer_size * 4)}}, + {"max_write_buffer_number", + {ToString(FLAGS_max_write_buffer_number), ToString(FLAGS_max_write_buffer_number * 2), - ToString(FLAGS_max_write_buffer_number * 4) - } - }, - {"arena_block_size", - { - ToString(Options().arena_block_size), - ToString(FLAGS_write_buffer_size / 4), - ToString(FLAGS_write_buffer_size / 8), - } - }, - {"memtable_prefix_bloom_bits", {"0", "8", "10"}}, - {"memtable_prefix_bloom_probes", {"4", "5", "6"}}, - {"memtable_prefix_bloom_huge_page_tlb_size", - { - "0", - ToString(2 * 1024 * 1024) - } - }, - {"max_successive_merges", {"0", "2", "4"}}, - {"filter_deletes", {"0", "1"}}, - {"inplace_update_num_locks", {"100", "200", "300"}}, - // TODO(ljin): enable test for this option - // {"disable_auto_compactions", {"100", "200", "300"}}, - {"soft_rate_limit", {"0", "0.5", "0.9"}}, - {"hard_rate_limit", {"0", "1.1", "2.0"}}, - {"level0_file_num_compaction_trigger", - { - ToString(FLAGS_level0_file_num_compaction_trigger), - ToString(FLAGS_level0_file_num_compaction_trigger + 2), - ToString(FLAGS_level0_file_num_compaction_trigger + 4), - } - }, - {"level0_slowdown_writes_trigger", - { - ToString(FLAGS_level0_slowdown_writes_trigger), - ToString(FLAGS_level0_slowdown_writes_trigger + 2), - ToString(FLAGS_level0_slowdown_writes_trigger + 4), - } - }, - {"level0_stop_writes_trigger", - { - ToString(FLAGS_level0_stop_writes_trigger), - ToString(FLAGS_level0_stop_writes_trigger + 2), - ToString(FLAGS_level0_stop_writes_trigger + 4), - } - }, - {"max_grandparent_overlap_factor", - { - ToString(Options().max_grandparent_overlap_factor - 5), - ToString(Options().max_grandparent_overlap_factor), - ToString(Options().max_grandparent_overlap_factor + 5), - } - }, - {"expanded_compaction_factor", - { - ToString(Options().expanded_compaction_factor - 5), - ToString(Options().expanded_compaction_factor), - ToString(Options().expanded_compaction_factor + 5), - } - }, - {"source_compaction_factor", - { - ToString(Options().source_compaction_factor), - ToString(Options().source_compaction_factor * 2), - ToString(Options().source_compaction_factor * 4), - } - }, - {"target_file_size_base", - { - ToString(FLAGS_target_file_size_base), - ToString(FLAGS_target_file_size_base * 2), - ToString(FLAGS_target_file_size_base * 4), - } - }, - {"target_file_size_multiplier", - { - ToString(FLAGS_target_file_size_multiplier), - "1", - "2", - } - }, - {"max_bytes_for_level_base", - { - ToString(FLAGS_max_bytes_for_level_base / 2), - ToString(FLAGS_max_bytes_for_level_base), - ToString(FLAGS_max_bytes_for_level_base * 2), - } - }, - {"max_bytes_for_level_multiplier", - { - ToString(FLAGS_max_bytes_for_level_multiplier), - "1", - "2", - } - }, - {"max_mem_compaction_level", {"0", "1", "2"}}, - {"max_sequential_skip_in_iterations", {"4", "8", "12"}}, + ToString(FLAGS_max_write_buffer_number * 4)}}, + {"arena_block_size", + { + ToString(Options().arena_block_size), + ToString(FLAGS_write_buffer_size / 4), + ToString(FLAGS_write_buffer_size / 8), + }}, + {"memtable_prefix_bloom_bits", {"0", "8", "10"}}, + {"memtable_prefix_bloom_probes", {"4", "5", "6"}}, + {"memtable_prefix_bloom_huge_page_tlb_size", + {"0", ToString(2 * 1024 * 1024)}}, + {"max_successive_merges", {"0", "2", "4"}}, + {"filter_deletes", {"0", "1"}}, + {"inplace_update_num_locks", {"100", "200", "300"}}, + // TODO(ljin): enable test for this option + // {"disable_auto_compactions", {"100", "200", "300"}}, + {"soft_rate_limit", {"0", "0.5", "0.9"}}, + {"hard_rate_limit", {"0", "1.1", "2.0"}}, + {"level0_file_num_compaction_trigger", + { + ToString(FLAGS_level0_file_num_compaction_trigger), + ToString(FLAGS_level0_file_num_compaction_trigger + 2), + ToString(FLAGS_level0_file_num_compaction_trigger + 4), + }}, + {"level0_slowdown_writes_trigger", + { + ToString(FLAGS_level0_slowdown_writes_trigger), + ToString(FLAGS_level0_slowdown_writes_trigger + 2), + ToString(FLAGS_level0_slowdown_writes_trigger + 4), + }}, + {"level0_stop_writes_trigger", + { + ToString(FLAGS_level0_stop_writes_trigger), + ToString(FLAGS_level0_stop_writes_trigger + 2), + ToString(FLAGS_level0_stop_writes_trigger + 4), + }}, + {"max_grandparent_overlap_factor", + { + ToString(Options().max_grandparent_overlap_factor - 5), + ToString(Options().max_grandparent_overlap_factor), + ToString(Options().max_grandparent_overlap_factor + 5), + }}, + {"expanded_compaction_factor", + { + ToString(Options().expanded_compaction_factor - 5), + ToString(Options().expanded_compaction_factor), + ToString(Options().expanded_compaction_factor + 5), + }}, + {"source_compaction_factor", + { + ToString(Options().source_compaction_factor), + ToString(Options().source_compaction_factor * 2), + ToString(Options().source_compaction_factor * 4), + }}, + {"target_file_size_base", + { + ToString(FLAGS_target_file_size_base), + ToString(FLAGS_target_file_size_base * 2), + ToString(FLAGS_target_file_size_base * 4), + }}, + {"target_file_size_multiplier", + { + ToString(FLAGS_target_file_size_multiplier), "1", "2", + }}, + {"max_bytes_for_level_base", + { + ToString(FLAGS_max_bytes_for_level_base / 2), + ToString(FLAGS_max_bytes_for_level_base), + ToString(FLAGS_max_bytes_for_level_base * 2), + }}, + {"max_bytes_for_level_multiplier", + { + ToString(FLAGS_max_bytes_for_level_multiplier), "1", "2", + }}, + {"max_mem_compaction_level", {"0", "1", "2"}}, + {"max_sequential_skip_in_iterations", {"4", "8", "12"}}, }; options_table_ = std::move(options_tbl); diff --git a/util/auto_roll_logger_test.cc b/util/auto_roll_logger_test.cc index cd116958f..1e46594df 100644 --- a/util/auto_roll_logger_test.cc +++ b/util/auto_roll_logger_test.cc @@ -205,7 +205,8 @@ TEST_F(AutoRollLoggerTest, CompositeRollByTimeAndSizeLogger) { } #ifndef OS_WIN -//TODO: does not build for Windows because of PosixLogger use below. Need to port +// TODO: does not build for Windows because of PosixLogger use below. Need to +// port TEST_F(AutoRollLoggerTest, CreateLoggerFromOptions) { DBOptions options; shared_ptr logger; diff --git a/util/autovector.h b/util/autovector.h index 11fc4667b..266a53a56 100644 --- a/util/autovector.h +++ b/util/autovector.h @@ -242,8 +242,7 @@ class autovector { void push_back(const T& item) { if (num_stack_items_ < kSize) { values_[num_stack_items_++] = item; - } - else { + } else { vect_.push_back(item); } } diff --git a/util/env_posix.cc b/util/env_posix.cc index bb14c5af5..9b7f13fe1 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -1827,7 +1827,8 @@ class PosixEnv : public Env { #if defined(_GNU_SOURCE) && defined(__GLIBC_PREREQ) #if __GLIBC_PREREQ(2, 12) char name_buf[16]; - snprintf(name_buf, sizeof name_buf, "rocksdb:bg%" ROCKSDB_PRIszt, bgthreads_.size()); + snprintf(name_buf, sizeof name_buf, "rocksdb:bg%" ROCKSDB_PRIszt, + bgthreads_.size()); name_buf[sizeof name_buf - 1] = '\0'; pthread_setname_np(t, name_buf); #endif diff --git a/util/env_test.cc b/util/env_test.cc index 931c95215..baeab1df0 100644 --- a/util/env_test.cc +++ b/util/env_test.cc @@ -7,11 +7,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. See the AUTHORS file for names of contributors. -#include #ifndef OS_WIN -# include +#include #endif - +#include #include #include @@ -860,7 +859,7 @@ class TestLogger : public Logger { int n = vsnprintf(new_format, sizeof(new_format) - 1, format, backup_ap); // 48 bytes for extra information + bytes allocated - // When we have n == -1 there is not a terminating zero expected +// When we have n == -1 there is not a terminating zero expected #ifdef OS_WIN if (n < 0) { char_0_count++; diff --git a/util/hash_cuckoo_rep.cc b/util/hash_cuckoo_rep.cc index 55a4b80ba..e632b2fa3 100644 --- a/util/hash_cuckoo_rep.cc +++ b/util/hash_cuckoo_rep.cc @@ -40,17 +40,13 @@ struct CuckooStep { CuckooStep() : bucket_id_(-1), prev_step_id_(kNullStep), depth_(1) {} // MSVC does not support = default yet - CuckooStep(CuckooStep&& o) - { - *this = std::move(o); - } - - CuckooStep& operator=(CuckooStep&& rhs) - { - bucket_id_ = std::move(rhs.bucket_id_); - prev_step_id_ = std::move(rhs.prev_step_id_); - depth_ = std::move(rhs.depth_); - return *this; + CuckooStep(CuckooStep&& o) { *this = std::move(o); } + + CuckooStep& operator=(CuckooStep&& rhs) { + bucket_id_ = std::move(rhs.bucket_id_); + prev_step_id_ = std::move(rhs.prev_step_id_); + depth_ = std::move(rhs.depth_); + return *this; } CuckooStep(const CuckooStep&) = delete; @@ -411,8 +407,8 @@ bool HashCuckooRep::QuickInsert(const char* internal_key, const Slice& user_key, } if (cuckoo_bucket_id != -1) { - cuckoo_array_[cuckoo_bucket_id] - .store(const_cast(internal_key), std::memory_order_release); + cuckoo_array_[cuckoo_bucket_id].store(const_cast(internal_key), + std::memory_order_release); return true; } diff --git a/util/hash_linklist_rep.cc b/util/hash_linklist_rep.cc index a2ab637da..1e6eadfe6 100644 --- a/util/hash_linklist_rep.cc +++ b/util/hash_linklist_rep.cc @@ -594,9 +594,9 @@ void HashLinkListRep::Insert(KeyHandle handle) { if (bucket_entries_logging_threshold_ > 0 && header->GetNumEntries() == static_cast(bucket_entries_logging_threshold_)) { - Info(logger_, - "HashLinkedList bucket %" ROCKSDB_PRIszt " has more than %d " - "entries. Key to insert: %s", + Info(logger_, "HashLinkedList bucket %" ROCKSDB_PRIszt + " has more than %d " + "entries. Key to insert: %s", GetHash(transformed), header->GetNumEntries(), GetLengthPrefixedSlice(x->key).ToString(true).c_str()); } diff --git a/util/histogram.h b/util/histogram.h index 0cd11cac7..5f73bf3cd 100644 --- a/util/histogram.h +++ b/util/histogram.h @@ -54,9 +54,7 @@ class HistogramBucketMapper { class HistogramImpl { public: - HistogramImpl() { - memset(buckets_, 0, sizeof(buckets_)); - } + HistogramImpl() { memset(buckets_, 0, sizeof(buckets_)); } virtual void Clear(); virtual bool Empty(); virtual void Add(uint64_t value); diff --git a/util/ldb_cmd.cc b/util/ldb_cmd.cc index d2e19954e..f80b1fb68 100644 --- a/util/ldb_cmd.cc +++ b/util/ldb_cmd.cc @@ -590,7 +590,8 @@ void ManifestDumpCommand::DoCommand() { // containing the db for files of the form MANIFEST_[0-9]+ auto CloseDir = [](DIR* p) { closedir(p); }; - std::unique_ptr d(opendir(db_path_.c_str()), CloseDir); + std::unique_ptr d(opendir(db_path_.c_str()), + CloseDir); if (d == nullptr) { exec_state_ = diff --git a/util/ldb_cmd.h b/util/ldb_cmd.h index 2157c1cce..3e61eb894 100644 --- a/util/ldb_cmd.h +++ b/util/ldb_cmd.h @@ -357,13 +357,9 @@ private: * Otherwise an exception is thrown. */ bool StringToBool(string val) { - std::transform(val.begin(), val.end(), val.begin(), - [](char ch) -> char - { - return ::tolower(ch); - }); - + [](char ch) -> char { return ::tolower(ch); }); + if (val == "true") { return true; } else if (val == "false") { diff --git a/util/mutable_cf_options.cc b/util/mutable_cf_options.cc index 887db4001..aaf41a147 100644 --- a/util/mutable_cf_options.cc +++ b/util/mutable_cf_options.cc @@ -63,10 +63,12 @@ uint64_t MutableCFOptions::ExpandedCompactionByteSizeLimit(int level) const { void MutableCFOptions::Dump(Logger* log) const { // Memtable related options - Log(log, " write_buffer_size: %" ROCKSDB_PRIszt, write_buffer_size); + Log(log, " write_buffer_size: %" ROCKSDB_PRIszt, + write_buffer_size); Log(log, " max_write_buffer_number: %d", max_write_buffer_number); - Log(log, " arena_block_size: %" ROCKSDB_PRIszt, arena_block_size); + Log(log, " arena_block_size: %" ROCKSDB_PRIszt, + arena_block_size); Log(log, " memtable_prefix_bloom_bits: %" PRIu32, memtable_prefix_bloom_bits); Log(log, " memtable_prefix_bloom_probes: %" PRIu32, diff --git a/util/options.cc b/util/options.cc index b4e488106..ce0f7572b 100644 --- a/util/options.cc +++ b/util/options.cc @@ -307,11 +307,14 @@ void DBOptions::Dump(Logger* log) const { Warn(log, " Options.max_total_wal_size: %" PRIu64, max_total_wal_size); Warn(log, " Options.disableDataSync: %d", disableDataSync); Warn(log, " Options.use_fsync: %d", use_fsync); - Warn(log, " Options.max_log_file_size: %" ROCKSDB_PRIszt, max_log_file_size); - Warn(log, "Options.max_manifest_file_size: %lu", - (unsigned long)max_manifest_file_size); - Warn(log, " Options.log_file_time_to_roll: %" ROCKSDB_PRIszt, log_file_time_to_roll); - Warn(log, " Options.keep_log_file_num: %" ROCKSDB_PRIszt, keep_log_file_num); + Warn(log, " Options.max_log_file_size: %" ROCKSDB_PRIszt, + max_log_file_size); + Warn(log, "Options.max_manifest_file_size: %" PRIu64, + max_manifest_file_size); + Warn(log, " Options.log_file_time_to_roll: %" ROCKSDB_PRIszt, + log_file_time_to_roll); + Warn(log, " Options.keep_log_file_num: %" ROCKSDB_PRIszt, + keep_log_file_num); Warn(log, " Options.allow_os_buffer: %d", allow_os_buffer); Warn(log, " Options.allow_mmap_reads: %d", allow_mmap_reads); Warn(log, " Options.allow_mmap_writes: %d", allow_mmap_writes); @@ -333,8 +336,9 @@ void DBOptions::Dump(Logger* log) const { WAL_ttl_seconds); Warn(log, " Options.WAL_size_limit_MB: %" PRIu64, WAL_size_limit_MB); - Warn(log, " Options.manifest_preallocation_size: %" ROCKSDB_PRIszt, - manifest_preallocation_size); + Warn(log, + " Options.manifest_preallocation_size: %" ROCKSDB_PRIszt, + manifest_preallocation_size); Warn(log, " Options.allow_os_buffer: %d", allow_os_buffer); Warn(log, " Options.allow_mmap_reads: %d", @@ -347,8 +351,10 @@ void DBOptions::Dump(Logger* log) const { stats_dump_period_sec); Warn(log, " Options.advise_random_on_open: %d", advise_random_on_open); - Warn(log, " Options.db_write_buffer_size: %" ROCKSDB_PRIszt "d", - db_write_buffer_size); + Warn(log, + " Options.db_write_buffer_size: %" ROCKSDB_PRIszt + "d", + db_write_buffer_size); Warn(log, " Options.access_hint_on_compaction_start: %s", access_hints[access_hint_on_compaction_start]); Warn(log, " Options.use_adaptive_mutex: %d", @@ -384,7 +390,8 @@ void ColumnFamilyOptions::Dump(Logger* log) const { Warn(log, " Options.table_factory: %s", table_factory->Name()); Warn(log, " table_factory options: %s", table_factory->GetPrintableTableOptions().c_str()); - Warn(log, " Options.write_buffer_size: %" ROCKSDB_PRIszt, write_buffer_size); + Warn(log, " Options.write_buffer_size: %" ROCKSDB_PRIszt, + write_buffer_size); Warn(log, " Options.max_write_buffer_number: %d", max_write_buffer_number); if (!compression_per_level.empty()) { for (unsigned int i = 0; i < compression_per_level.size(); i++) { @@ -430,8 +437,9 @@ void ColumnFamilyOptions::Dump(Logger* log) const { max_bytes_for_level_multiplier); for (size_t i = 0; i < max_bytes_for_level_multiplier_additional.size(); i++) { - Warn(log, "Options.max_bytes_for_level_multiplier_addtl[%" ROCKSDB_PRIszt "]: %d", i, - max_bytes_for_level_multiplier_additional[i]); + Warn(log, "Options.max_bytes_for_level_multiplier_addtl[%" ROCKSDB_PRIszt + "]: %d", + i, max_bytes_for_level_multiplier_additional[i]); } Warn(log, " Options.max_sequential_skip_in_iterations: %" PRIu64, max_sequential_skip_in_iterations); @@ -442,8 +450,9 @@ void ColumnFamilyOptions::Dump(Logger* log) const { Warn(log, " Options.max_grandparent_overlap_factor: %d", max_grandparent_overlap_factor); - Warn(log, " Options.arena_block_size: %" ROCKSDB_PRIszt, - arena_block_size); + Warn(log, + " Options.arena_block_size: %" ROCKSDB_PRIszt, + arena_block_size); Warn(log, " Options.soft_rate_limit: %.2f", soft_rate_limit); Warn(log, " Options.hard_rate_limit: %.2f", @@ -483,8 +492,9 @@ void ColumnFamilyOptions::Dump(Logger* log) const { collector_names.c_str()); Warn(log, " Options.inplace_update_support: %d", inplace_update_support); - Warn(log, " Options.inplace_update_num_locks: %" ROCKSDB_PRIszt, - inplace_update_num_locks); + Warn(log, + " Options.inplace_update_num_locks: %" ROCKSDB_PRIszt, + inplace_update_num_locks); Warn(log, " Options.min_partial_merge_operands: %u", min_partial_merge_operands); // TODO: easier config for bloom (maybe based on avg key/value size) @@ -493,13 +503,15 @@ void ColumnFamilyOptions::Dump(Logger* log) const { Warn(log, " Options.memtable_prefix_bloom_probes: %d", memtable_prefix_bloom_probes); - Warn(log, " Options.memtable_prefix_bloom_huge_page_tlb_size: %" ROCKSDB_PRIszt, - memtable_prefix_bloom_huge_page_tlb_size); + Warn(log, + " Options.memtable_prefix_bloom_huge_page_tlb_size: %" ROCKSDB_PRIszt, + memtable_prefix_bloom_huge_page_tlb_size); Warn(log, " Options.bloom_locality: %d", bloom_locality); - Warn(log, " Options.max_successive_merges: %" ROCKSDB_PRIszt, - max_successive_merges); + Warn(log, + " Options.max_successive_merges: %" ROCKSDB_PRIszt, + max_successive_merges); Warn(log, " Options.optimize_fllters_for_hits: %d", optimize_filters_for_hits); } // ColumnFamilyOptions::Dump diff --git a/util/options_helper.cc b/util/options_helper.cc index 72db57dc5..d6797a7ce 100644 --- a/util/options_helper.cc +++ b/util/options_helper.cc @@ -277,8 +277,7 @@ Status GetMutableOptionsFromStrings( namespace { std::string trim(const std::string& str) { - if (str.empty()) - return std::string(); + if (str.empty()) return std::string(); size_t start = 0; size_t end = str.size() - 1; while (isspace(str[start]) != 0 && start <= end) { @@ -564,8 +563,7 @@ bool ParseDBOption(const std::string& name, const std::string& value, } else { return false; } - } - catch (const std::exception& e) { + } catch (const std::exception& e) { return false; } return true; @@ -680,7 +678,8 @@ Status GetPlainTableOptionsFromMap( } else if (o.first == "full_scan_mode") { new_table_options->full_scan_mode = ParseBoolean(o.first, o.second); } else if (o.first == "store_index_in_file") { - new_table_options->store_index_in_file = ParseBoolean(o.first, o.second); + new_table_options->store_index_in_file = + ParseBoolean(o.first, o.second); } else { return Status::InvalidArgument("Unrecognized option: " + o.first); } diff --git a/util/options_test.cc b/util/options_test.cc index 60a4bd9be..6a0e96ae6 100644 --- a/util/options_test.cc +++ b/util/options_test.cc @@ -51,12 +51,12 @@ Options PrintAndGetOptions(size_t total_write_buffer_limit, StderrLogger logger; if (FLAGS_enable_print) { - printf( - "---- total_write_buffer_limit: %" ROCKSDB_PRIszt " " - "read_amplification_threshold: %d write_amplification_threshold: %d " - "target_db_size %" PRIu64 " ----\n", - total_write_buffer_limit, read_amplification_threshold, - write_amplification_threshold, target_db_size); + printf("---- total_write_buffer_limit: %" ROCKSDB_PRIszt + " " + "read_amplification_threshold: %d write_amplification_threshold: %d " + "target_db_size %" PRIu64 " ----\n", + total_write_buffer_limit, read_amplification_threshold, + write_amplification_threshold, target_db_size); } Options options = @@ -337,14 +337,14 @@ TEST_F(OptionsTest, GetColumnFamilyOptionsFromStringTest) { ASSERT_OK(GetColumnFamilyOptionsFromString(base_cf_opt, "memtable_prefix_bloom_bits=14k;max_write_buffer_number=-15K", &new_cf_opt)); - ASSERT_EQ(new_cf_opt.memtable_prefix_bloom_bits, 14UL*kilo); - ASSERT_EQ(new_cf_opt.max_write_buffer_number, -15*kilo); + ASSERT_EQ(new_cf_opt.memtable_prefix_bloom_bits, 14UL * kilo); + ASSERT_EQ(new_cf_opt.max_write_buffer_number, -15 * kilo); // Units (m) ASSERT_OK(GetColumnFamilyOptionsFromString(base_cf_opt, "max_write_buffer_number=16m;inplace_update_num_locks=17M", &new_cf_opt)); - ASSERT_EQ(new_cf_opt.max_write_buffer_number, 16*mega); - ASSERT_EQ(new_cf_opt.inplace_update_num_locks, 17*mega); + ASSERT_EQ(new_cf_opt.max_write_buffer_number, 16 * mega); + ASSERT_EQ(new_cf_opt.inplace_update_num_locks, 17 * mega); // Units (g) ASSERT_OK(GetColumnFamilyOptionsFromString( base_cf_opt, @@ -352,8 +352,8 @@ TEST_F(OptionsTest, GetColumnFamilyOptionsFromStringTest) { "arena_block_size=19G", &new_cf_opt)); - ASSERT_EQ(new_cf_opt.write_buffer_size, 18*giga); - ASSERT_EQ(new_cf_opt.arena_block_size, 19*giga); + ASSERT_EQ(new_cf_opt.write_buffer_size, 18 * giga); + ASSERT_EQ(new_cf_opt.arena_block_size, 19 * giga); ASSERT_TRUE(new_cf_opt.prefix_extractor.get() != nullptr); std::string prefix_name(new_cf_opt.prefix_extractor->Name()); ASSERT_EQ(prefix_name, "rocksdb.CappedPrefix.8"); @@ -361,8 +361,8 @@ TEST_F(OptionsTest, GetColumnFamilyOptionsFromStringTest) { // Units (t) ASSERT_OK(GetColumnFamilyOptionsFromString(base_cf_opt, "write_buffer_size=20t;arena_block_size=21T", &new_cf_opt)); - ASSERT_EQ(new_cf_opt.write_buffer_size, 20*tera); - ASSERT_EQ(new_cf_opt.arena_block_size, 21*tera); + ASSERT_EQ(new_cf_opt.write_buffer_size, 20 * tera); + ASSERT_EQ(new_cf_opt.arena_block_size, 21 * tera); // Nested block based table options // Emtpy diff --git a/util/slice.cc b/util/slice.cc index 03d89e27f..475d0b7fc 100644 --- a/util/slice.cc +++ b/util/slice.cc @@ -96,12 +96,12 @@ class NoopTransform : public SliceTransform { // Do not want to include the whole /port/port.h here for one define #ifdef OS_WIN -# define snprintf _snprintf +#define snprintf _snprintf #endif // Return a string that contains the copy of the referenced data. std::string Slice::ToString(bool hex) const { - std::string result; // RVO/NRVO/move + std::string result; // RVO/NRVO/move if (hex) { char buf[10]; for (size_t i = 0; i < size_; i++) { @@ -115,7 +115,6 @@ std::string Slice::ToString(bool hex) const { } } - const SliceTransform* NewFixedPrefixTransform(size_t prefix_len) { return new FixedPrefixTransform(prefix_len); } diff --git a/util/thread_local.cc b/util/thread_local.cc index ab70c4a6f..69f9f6e18 100644 --- a/util/thread_local.cc +++ b/util/thread_local.cc @@ -25,19 +25,23 @@ __thread ThreadLocalPtr::ThreadData* ThreadLocalPtr::StaticMeta::tls_ = nullptr; // See http://www.codeproject.com/Articles/8113/Thread-Local-Storage-The-C-Way // and http://www.nynaeve.net/?p=183 // -// really we do this to have clear conscience since using TLS with thread-pools is iffy -// although OK within a request. But otherwise, threads have no identity in its modern use. +// really we do this to have clear conscience since using TLS with thread-pools +// is iffy +// although OK within a request. But otherwise, threads have no identity in its +// modern use. // This runs on windows only called from the System Loader #ifdef OS_WIN // Windows cleanup routine is invoked from a System Loader with a different -// signature so we can not directly hookup the original OnThreadExit which is private member -// so we make StaticMeta class share with the us the address of the function so we can invoke it. +// signature so we can not directly hookup the original OnThreadExit which is +// private member +// so we make StaticMeta class share with the us the address of the function so +// we can invoke it. namespace wintlscleanup { // This is set to OnThreadExit in StaticMeta singleton constructor -UnrefHandler thread_local_inclass_routine = nullptr; +UnrefHandler thread_local_inclass_routine = nullptr; pthread_key_t thread_local_key = -1; // Static callback function to call with each thread termination. @@ -46,26 +50,26 @@ void NTAPI WinOnThreadExit(PVOID module, DWORD reason, PVOID reserved) { if (DLL_THREAD_DETACH == reason) { if (thread_local_key != -1 && thread_local_inclass_routine != nullptr) { void* tls = pthread_getspecific(thread_local_key); - if(tls != nullptr) { + if (tls != nullptr) { thread_local_inclass_routine(tls); } } } } -} // wintlscleanup +} // wintlscleanup -# ifdef _WIN64 +#ifdef _WIN64 -# pragma comment(linker, "/include:_tls_used") -# pragma comment(linker, "/include:p_thread_callback_on_exit") +#pragma comment(linker, "/include:_tls_used") +#pragma comment(linker, "/include:p_thread_callback_on_exit") #else // _WIN64 -# pragma comment(linker, "/INCLUDE:__tls_used") -# pragma comment(linker, "/INCLUDE:_p_thread_callback_on_exit") +#pragma comment(linker, "/INCLUDE:__tls_used") +#pragma comment(linker, "/INCLUDE:_p_thread_callback_on_exit") -# endif // _WIN64 +#endif // _WIN64 // extern "C" suppresses C++ name mangling so we know the symbol name for the // linker /INCLUDE:symbol pragma above. @@ -81,7 +85,8 @@ extern "C" { // When defining a const variable, it must have external linkage to be sure the // linker doesn't discard it. extern const PIMAGE_TLS_CALLBACK p_thread_callback_on_exit; -const PIMAGE_TLS_CALLBACK p_thread_callback_on_exit = wintlscleanup::WinOnThreadExit; +const PIMAGE_TLS_CALLBACK p_thread_callback_on_exit = + wintlscleanup::WinOnThreadExit; // Reset the default section. #pragma const_seg() @@ -96,7 +101,7 @@ PIMAGE_TLS_CALLBACK p_thread_callback_on_exit = wintlscleanup::WinOnThreadExit; } // extern "C" -#endif // OS_WIN +#endif // OS_WIN ThreadLocalPtr::StaticMeta* ThreadLocalPtr::Instance() { static ThreadLocalPtr::StaticMeta inst; @@ -136,7 +141,7 @@ ThreadLocalPtr::StaticMeta::StaticMeta() : next_instance_id_(0) { head_.prev = &head_; #ifdef OS_WIN -// Share with Windows its cleanup routine and the key + // Share with Windows its cleanup routine and the key wintlscleanup::thread_local_inclass_routine = OnThreadExit; wintlscleanup::thread_local_key = pthread_key_; #endif @@ -160,8 +165,8 @@ void ThreadLocalPtr::StaticMeta::RemoveThreadData( ThreadLocalPtr::ThreadData* ThreadLocalPtr::StaticMeta::GetThreadLocal() { #if defined(OS_MACOSX) || defined(OS_WIN) -// Make this local variable name look like a member variable so that we -// can share all the code below + // Make this local variable name look like a member variable so that we + // can share all the code below ThreadData* tls_ = static_cast(pthread_getspecific(Instance()->pthread_key_)); #endif diff --git a/util/thread_local.h b/util/thread_local.h index 973f31d10..f061253eb 100644 --- a/util/thread_local.h +++ b/util/thread_local.h @@ -17,7 +17,6 @@ #include "util/autovector.h" #include "port/port.h" - namespace rocksdb { // Cleanup function that will be called for a stored thread local diff --git a/utilities/backupable/backupable_db.cc b/utilities/backupable/backupable_db.cc index 5343efc28..ee80c7043 100644 --- a/utilities/backupable/backupable_db.cc +++ b/utilities/backupable/backupable_db.cc @@ -333,9 +333,7 @@ class BackupEngineImpl : public BackupEngine { CopyWorkItem(const CopyWorkItem&) = delete; CopyWorkItem& operator=(const CopyWorkItem&) = delete; - CopyWorkItem(CopyWorkItem&& o) { - *this = std::move(o); - } + CopyWorkItem(CopyWorkItem&& o) { *this = std::move(o); } CopyWorkItem& operator=(CopyWorkItem&& o) { src_path = std::move(o.src_path); @@ -390,12 +388,9 @@ class BackupEngineImpl : public BackupEngine { return *this; } - BackupAfterCopyWorkItem(std::future&& _result, - bool _shared, - bool _needed_to_copy, - Env* _backup_env, - std::string _dst_path_tmp, - std::string _dst_path, + BackupAfterCopyWorkItem(std::future&& _result, bool _shared, + bool _needed_to_copy, Env* _backup_env, + std::string _dst_path_tmp, std::string _dst_path, std::string _dst_relative) : result(std::move(_result)), shared(_shared), @@ -412,8 +407,7 @@ class BackupEngineImpl : public BackupEngine { RestoreAfterCopyWorkItem() {} RestoreAfterCopyWorkItem(std::future&& _result, uint32_t _checksum_value) - : result(std::move(_result)), - checksum_value(_checksum_value) {} + : result(std::move(_result)), checksum_value(_checksum_value) {} RestoreAfterCopyWorkItem(RestoreAfterCopyWorkItem&& o) { *this = std::move(o); } @@ -1561,7 +1555,8 @@ Status BackupEngineImpl::BackupMeta::StoreToFile(bool sync) { len += snprintf(buf.get(), buf_size, "%" PRId64 "\n", timestamp_); len += snprintf(buf.get() + len, buf_size - len, "%" PRIu64 "\n", sequence_number_); - len += snprintf(buf.get() + len, buf_size - len, "%" ROCKSDB_PRIszt "\n", files_.size()); + len += snprintf(buf.get() + len, buf_size - len, "%" ROCKSDB_PRIszt "\n", + files_.size()); for (const auto& file : files_) { // use crc32 for now, switch to something else if needed len += snprintf(buf.get() + len, buf_size - len, "%s crc32 %u\n", diff --git a/utilities/checkpoint/checkpoint_test.cc b/utilities/checkpoint/checkpoint_test.cc index b01fe647e..0a97de429 100644 --- a/utilities/checkpoint/checkpoint_test.cc +++ b/utilities/checkpoint/checkpoint_test.cc @@ -8,10 +8,10 @@ // found in the LICENSE file. See the AUTHORS file for names of contributors. // Syncpoint prevents us building and running tests in release -#if !defined(NDEBUG) || !defined (OS_WIN) +#if !defined(NDEBUG) || !defined(OS_WIN) #ifndef OS_WIN -# include +#include #endif #include #include @@ -351,7 +351,7 @@ TEST_F(DBTest, CheckpointCF) { #endif int main(int argc, char** argv) { -#if !defined(NDEBUG) || !defined (OS_WIN) +#if !defined(NDEBUG) || !defined(OS_WIN) rocksdb::port::InstallStackTraceHandler(); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/utilities/geodb/geodb_impl.cc b/utilities/geodb/geodb_impl.cc index ce16e80c7..afa2f4c91 100644 --- a/utilities/geodb/geodb_impl.cc +++ b/utilities/geodb/geodb_impl.cc @@ -42,7 +42,6 @@ const double GeoDBImpl::MaxLatitude = 85.05112878; const double GeoDBImpl::MinLongitude = -180; const double GeoDBImpl::MaxLongitude = 180; - GeoDBImpl::GeoDBImpl(DB* db, const GeoDBOptions& options) : GeoDB(db, options), db_(db), options_(options) { } diff --git a/utilities/merge_operators/uint64add.cc b/utilities/merge_operators/uint64add.cc index 560cbb7a0..453b8c8ea 100644 --- a/utilities/merge_operators/uint64add.cc +++ b/utilities/merge_operators/uint64add.cc @@ -51,7 +51,8 @@ class UInt64AddOperator : public AssociativeMergeOperator { } else if (logger != nullptr) { // If value is corrupted, treat it as 0 Log(InfoLogLevel::ERROR_LEVEL, logger, - "uint64 value corruption, size: %" ROCKSDB_PRIszt " > %" ROCKSDB_PRIszt, + "uint64 value corruption, size: %" ROCKSDB_PRIszt + " > %" ROCKSDB_PRIszt, value.size(), sizeof(uint64_t)); } diff --git a/utilities/spatialdb/spatial_db.cc b/utilities/spatialdb/spatial_db.cc index 4e642c544..36c9ed188 100644 --- a/utilities/spatialdb/spatial_db.cc +++ b/utilities/spatialdb/spatial_db.cc @@ -67,27 +67,26 @@ inline bool GetSpatialIndexName(const std::string& column_family_name, void Variant::Init(const Variant& v, Data& d) { switch (v.type_) { - case kNull: - break; - case kBool: - d.b = v.data_.b; - break; - case kInt: - d.i = v.data_.i; - break; - case kDouble: - d.d = v.data_.d; - break; - case kString: - new (d.s) std::string(*GetStringPtr(v.data_)); - break; - default: - assert(false); + case kNull: + break; + case kBool: + d.b = v.data_.b; + break; + case kInt: + d.i = v.data_.i; + break; + case kDouble: + d.d = v.data_.d; + break; + case kString: + new (d.s) std::string(*GetStringPtr(v.data_)); + break; + default: + assert(false); } } Variant& Variant::operator=(const Variant& v) { - // Construct first a temp so exception from a string ctor // does not change this object Data tmp; @@ -104,7 +103,6 @@ Variant& Variant::operator=(const Variant& v) { } Variant& Variant::operator=(Variant&& rhs) { - Destroy(type_, data_); if (rhs.type_ == kString) { new (data_.s) std::string(std::move(*GetStringPtr(rhs.data_))); @@ -116,9 +114,7 @@ Variant& Variant::operator=(Variant&& rhs) { return *this; } - bool Variant::operator==(const Variant& rhs) const { - if (type_ != rhs.type_) { return false; } diff --git a/utilities/ttl/ttl_test.cc b/utilities/ttl/ttl_test.cc index 1a5726bcc..dc152fe6d 100644 --- a/utilities/ttl/ttl_test.cc +++ b/utilities/ttl/ttl_test.cc @@ -18,10 +18,7 @@ namespace { typedef std::map KVMap; -enum BatchOperation { - OP_PUT = 0, - OP_DELETE = 1 -}; +enum BatchOperation { OP_PUT = 0, OP_DELETE = 1 }; } class SpecialTimeEnv : public EnvWrapper {