From d1a457181d0eedd7573d629e7acb46281a16b478 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Thu, 16 Jul 2015 12:10:16 -0700 Subject: [PATCH] Ensure Windows build w/o port/port.h in public headers - Remove make file defines from public headers and use _WIN32 because it is compiler defined - use __GNUC__ and __clang__ to guard non-portable attributes - add #include "port/port.h" to some new .cc files. - minor changes in CMakeLists to reflect recent changes --- CMakeLists.txt | 4 ++-- include/rocksdb/c.h | 2 +- include/rocksdb/db.h | 20 ++++++++++++++++-- include/rocksdb/env.h | 26 ++++-------------------- include/rocksdb/iostats_context.h | 4 ++++ include/rocksdb/perf_context.h | 2 ++ include/rocksdb/utilities/stackable_db.h | 6 ++++++ include/rocksdb/utilities/utility_db.h | 7 ++++++- include/utilities/pragma_error.h | 2 +- port/win/port_win.h | 13 ++++++++++++ table/adaptive_table_factory.cc | 1 + util/db_test_util.h | 4 +++- util/env.cc | 25 +++++++++++++++++++++++ util/iostats_context.cc | 4 ++++ util/manual_compaction_test.cc | 1 + util/perf_context.cc | 7 ++++--- utilities/backupable/backupable_db.cc | 2 ++ utilities/ttl/db_ttl_impl.h | 6 ++++++ 18 files changed, 103 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 209cc1cba..a4a50dba5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ set(SOURCES db/builder.cc db/c.cc db/column_family.cc + db/compacted_db_impl.cc db/compaction.cc db/compaction_job.cc db/compaction_picker.cc @@ -202,7 +203,6 @@ set(SOURCES util/xxhash.cc utilities/backupable/backupable_db.cc utilities/checkpoint/checkpoint.cc - utilities/compacted_db/compacted_db_impl.cc utilities/document/document_db.cc utilities/document/json_document.cc utilities/document/json_document_builder.cc @@ -215,8 +215,8 @@ set(SOURCES utilities/merge_operators/uint64add.cc utilities/redis/redis_lists.cc utilities/spatialdb/spatial_db.cc + utilities/transactions/optimistic_transaction_impl.cc utilities/transactions/optimistic_transaction_db_impl.cc - utilities/transactions/optimistic_transaction_impl.cc utilities/ttl/db_ttl_impl.cc utilities/write_batch_with_index/write_batch_with_index.cc utilities/write_batch_with_index/write_batch_with_index_internal.cc diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index cf6f9d87b..b1f694609 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -46,7 +46,7 @@ #pragma once -#ifdef OS_WIN +#ifdef _WIN32 #ifdef ROCKSDB_DLL #ifdef ROCKSDB_LIBRARY_EXPORTS #define ROCKSDB_LIBRARY_API __declspec(dllexport) diff --git a/include/rocksdb/db.h b/include/rocksdb/db.h index e006fcc52..d11e95318 100644 --- a/include/rocksdb/db.h +++ b/include/rocksdb/db.h @@ -24,6 +24,12 @@ #include "rocksdb/listener.h" #include "rocksdb/thread_status.h" +#ifdef _WIN32 +// Windows API macro interference +#undef DeleteFile +#endif + + namespace rocksdb { struct Options; @@ -431,7 +437,12 @@ class DB { return CompactRange(options, DefaultColumnFamily(), begin, end); } - __attribute__((deprecated)) virtual Status +#if defined(__GNUC__) || defined(__clang__) + __attribute__((deprecated)) +#elif _WIN32 + __declspec(deprecated) +#endif + virtual Status CompactRange(ColumnFamilyHandle* column_family, const Slice* begin, const Slice* end, bool change_level = false, int target_level = -1, uint32_t target_path_id = 0) { @@ -441,7 +452,12 @@ class DB { options.target_path_id = target_path_id; return CompactRange(options, column_family, begin, end); } - __attribute__((deprecated)) virtual Status +#if defined(__GNUC__) || defined(__clang__) + __attribute__((deprecated)) +#elif _WIN32 + __declspec(deprecated) +#endif + virtual Status CompactRange(const Slice* begin, const Slice* end, bool change_level = false, int target_level = -1, uint32_t target_path_id = 0) { diff --git a/include/rocksdb/env.h b/include/rocksdb/env.h index fedfa8b56..684448e2a 100644 --- a/include/rocksdb/env.h +++ b/include/rocksdb/env.h @@ -26,7 +26,9 @@ #include "rocksdb/status.h" #include "rocksdb/thread_status.h" -#ifdef GetCurrentTime +#ifdef _WIN32 +// Windows API macro interference +#undef DeleteFile #undef GetCurrentTime #endif @@ -163,7 +165,6 @@ class Env { virtual Status GetChildren(const std::string& dir, std::vector* result) = 0; -#undef DeleteFile // Delete the named file. virtual Status DeleteFile(const std::string& fname) = 0; @@ -650,27 +651,8 @@ class Logger { // and format. Any log with level under the internal log level // of *this (see @SetInfoLogLevel and @GetInfoLogLevel) will not be // printed. - virtual void Logv(const InfoLogLevel log_level, const char* format, va_list ap) { - static const char* kInfoLogLevelNames[5] = {"DEBUG", "INFO", "WARN", - "ERROR", "FATAL"}; - if (log_level < log_level_) { - return; - } + virtual void Logv(const InfoLogLevel log_level, const char* format, va_list ap); - if (log_level == InfoLogLevel::INFO_LEVEL) { - // Doesn't print log level if it is INFO level. - // This is to avoid unexpected performance regression after we add - // the feature of log level. All the logs before we add the feature - // are INFO level. We don't want to add extra costs to those existing - // logging. - Logv(format, ap); - } else { - char new_format[500]; - snprintf(new_format, sizeof(new_format) - 1, "[%s] %s", - kInfoLogLevelNames[log_level], format); - Logv(new_format, ap); - } - } virtual size_t GetLogFileSize() const { return kDoNotSupportGetLogFileSize; } // Flush to the OS buffers virtual void Flush() {} diff --git a/include/rocksdb/iostats_context.h b/include/rocksdb/iostats_context.h index 8bb082f55..472a68257 100644 --- a/include/rocksdb/iostats_context.h +++ b/include/rocksdb/iostats_context.h @@ -44,7 +44,11 @@ struct IOStatsContext { }; #ifndef IOS_CROSS_COMPILE +# ifdef _WIN32 +extern __declspec(thread) IOStatsContext iostats_context; +# else extern __thread IOStatsContext iostats_context; +# endif #endif // IOS_CROSS_COMPILE } // namespace rocksdb diff --git a/include/rocksdb/perf_context.h b/include/rocksdb/perf_context.h index bdef04778..150393aa6 100644 --- a/include/rocksdb/perf_context.h +++ b/include/rocksdb/perf_context.h @@ -87,6 +87,8 @@ struct PerfContext { #if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE) extern PerfContext perf_context; +#elif _WIN32 +extern __declspec(thread) PerfContext perf_context; #else extern __thread PerfContext perf_context; #endif diff --git a/include/rocksdb/utilities/stackable_db.h b/include/rocksdb/utilities/stackable_db.h index 6d39c99c5..6771d3c3c 100644 --- a/include/rocksdb/utilities/stackable_db.h +++ b/include/rocksdb/utilities/stackable_db.h @@ -6,6 +6,12 @@ #include #include "rocksdb/db.h" +#ifdef _WIN32 +// Windows API macro interference +#undef DeleteFile +#endif + + namespace rocksdb { // This class contains APIs to stack rocksdb wrappers.Eg. Stack TTL over base d diff --git a/include/rocksdb/utilities/utility_db.h b/include/rocksdb/utilities/utility_db.h index f4db66532..a34a63898 100644 --- a/include/rocksdb/utilities/utility_db.h +++ b/include/rocksdb/utilities/utility_db.h @@ -19,7 +19,12 @@ class UtilityDB { // This function is here only for backwards compatibility. Please use the // functions defined in DBWithTTl (rocksdb/utilities/db_ttl.h) // (deprecated) - __attribute__((deprecated)) static Status OpenTtlDB(const Options& options, +#if defined(__GNUC__) || defined(__clang__) + __attribute__((deprecated)) +#elif _WIN32 + __declspec(deprecated) +#endif + static Status OpenTtlDB(const Options& options, const std::string& name, StackableDB** dbptr, int32_t ttl = 0, diff --git a/include/utilities/pragma_error.h b/include/utilities/pragma_error.h index c9f1853bb..53cde1000 100644 --- a/include/utilities/pragma_error.h +++ b/include/utilities/pragma_error.h @@ -18,7 +18,7 @@ #define ROCKSDB_WARNING(x) _Pragma(RDB_STR(GCC warning x)) -#elif defined(OS_WIN) +#elif defined(_WIN32) // Wrap unportable warning macro #if defined(_MSC_VER) diff --git a/port/win/port_win.h b/port/win/port_win.h index a0086c6aa..98b15073f 100644 --- a/port/win/port_win.h +++ b/port/win/port_win.h @@ -31,6 +31,12 @@ #include "rocksdb/options.h" +#undef min +#undef max +#undef DeleteFile +#undef GetCurrentTime + + #ifndef strcasecmp #define strcasecmp _stricmp #endif @@ -40,12 +46,17 @@ #define snprintf _snprintf #endif +#undef GetCurrentTime +#undef DeleteFile + typedef SSIZE_T ssize_t; // size_t printf formatting named in the manner of C99 standard formatting // strings such as PRIu64 // in fact, we could use that one +#ifndef ROCKSDB_PRIszt #define ROCKSDB_PRIszt "Iu" +#endif #define __attribute__(A) @@ -68,7 +79,9 @@ typedef SSIZE_T ssize_t; // Thread local storage on Linux // There is thread_local in C++11 +#ifndef __thread #define __thread __declspec(thread) +#endif #ifndef PLATFORM_IS_LITTLE_ENDIAN #define PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN) diff --git a/table/adaptive_table_factory.cc b/table/adaptive_table_factory.cc index dcc84061f..e8831f757 100644 --- a/table/adaptive_table_factory.cc +++ b/table/adaptive_table_factory.cc @@ -6,6 +6,7 @@ #include "table/adaptive_table_factory.h" #include "table/format.h" +#include "port/port.h" namespace rocksdb { diff --git a/util/db_test_util.h b/util/db_test_util.h index c96d5394b..2b7dd94d0 100644 --- a/util/db_test_util.h +++ b/util/db_test_util.h @@ -14,7 +14,9 @@ #include #include +#ifndef OS_WIN #include +#endif #include #include @@ -36,7 +38,7 @@ #include "rocksdb/slice.h" #include "rocksdb/table.h" #include "rocksdb/utilities/checkpoint.h" -#include "rocksdb/utilities/convenience.h" +#include "rocksdb/convenience.h" #include "table/block_based_table_factory.h" #include "table/mock_table.h" #include "table/plain_table_factory.h" diff --git a/util/env.cc b/util/env.cc index 9da6fe1b1..be1d9cd76 100644 --- a/util/env.cc +++ b/util/env.cc @@ -10,7 +10,9 @@ #include "rocksdb/env.h" #include +#include "port/port.h" #include "port/sys_time.h" +#include "port/port.h" #include "rocksdb/options.h" #include "util/arena.h" @@ -56,6 +58,29 @@ void Log(Logger* info_log, const char* format, ...) { } } +void Logger::Logv(const InfoLogLevel log_level, const char* format, va_list ap) { + static const char* kInfoLogLevelNames[5] = { "DEBUG", "INFO", "WARN", + "ERROR", "FATAL" }; + if (log_level < log_level_) { + return; + } + + if (log_level == InfoLogLevel::INFO_LEVEL) { + // Doesn't print log level if it is INFO level. + // This is to avoid unexpected performance regression after we add + // the feature of log level. All the logs before we add the feature + // are INFO level. We don't want to add extra costs to those existing + // logging. + Logv(format, ap); + } else { + char new_format[500]; + snprintf(new_format, sizeof(new_format) - 1, "[%s] %s", + kInfoLogLevelNames[log_level], format); + Logv(new_format, ap); + } +} + + void Log(const InfoLogLevel log_level, Logger* info_log, const char* format, ...) { if (info_log && info_log->GetInfoLogLevel() <= log_level) { diff --git a/util/iostats_context.cc b/util/iostats_context.cc index 87c7a47ae..7e7c70a58 100644 --- a/util/iostats_context.cc +++ b/util/iostats_context.cc @@ -10,7 +10,11 @@ namespace rocksdb { #ifndef IOS_CROSS_COMPILE +# ifdef _WIN32 +__declspec(thread) IOStatsContext iostats_context; +# else __thread IOStatsContext iostats_context; +# endif #endif // IOS_CROSS_COMPILE void IOStatsContext::Reset() { diff --git a/util/manual_compaction_test.cc b/util/manual_compaction_test.cc index 12c7486a3..8613b7b36 100644 --- a/util/manual_compaction_test.cc +++ b/util/manual_compaction_test.cc @@ -13,6 +13,7 @@ #include "rocksdb/slice.h" #include "rocksdb/write_batch.h" #include "util/testharness.h" +#include "port/port.h" using namespace rocksdb; diff --git a/util/perf_context.cc b/util/perf_context.cc index 643b3f004..9c3fd2029 100644 --- a/util/perf_context.cc +++ b/util/perf_context.cc @@ -10,10 +10,11 @@ namespace rocksdb { #if defined(NPERF_CONTEXT) || defined(IOS_CROSS_COMPILE) -// This is a dummy variable since some place references it -PerfContext perf_context; + PerfContext perf_context; +#elif _WIN32 + __declspec(thread) PerfContext perf_context; #else -__thread PerfContext perf_context; + __thread PerfContext perf_context; #endif void PerfContext::Reset() { diff --git a/utilities/backupable/backupable_db.cc b/utilities/backupable/backupable_db.cc index e8fc0bfe9..6b8515159 100644 --- a/utilities/backupable/backupable_db.cc +++ b/utilities/backupable/backupable_db.cc @@ -35,6 +35,8 @@ #include #include #include +#include "port/port.h" + namespace rocksdb { diff --git a/utilities/ttl/db_ttl_impl.h b/utilities/ttl/db_ttl_impl.h index 84444e91c..a96123d81 100644 --- a/utilities/ttl/db_ttl_impl.h +++ b/utilities/ttl/db_ttl_impl.h @@ -17,6 +17,12 @@ #include "rocksdb/utilities/db_ttl.h" #include "db/db_impl.h" +#ifdef _WIN32 +// Windows API macro interference +#undef GetCurrentTime +#endif + + namespace rocksdb { class DBWithTTLImpl : public DBWithTTL { -- GitLab