From 42d6652ba237310792b1f5ef99178fd5c9020808 Mon Sep 17 00:00:00 2001 From: Wentian Guo Date: Mon, 13 Feb 2023 02:21:38 -0800 Subject: [PATCH] remove dependency on options.h for port_posix.h andport_win.h (#11214) Summary: The files in `port/`, such as `port_posix.h`, are layering over the system libraries, so shouldn't include the DB-specific files like `options.h`. This PR remove this dependency. # How The reason that `port_posix.h` (or `port_win.h`) include `options.h` is to use `CpuPriority`, as there is a method `SetCpuPriority()` in `port_posix.h` that uses `CpuPriority.` - I think `SetCpuPriority()` make sense to exist in `port_posix.h` as it provides has platform-dependent implementation - `CpuPriority` enum is defined in `env.h`, but used in `rocksdb/include` and `port/`. Hence, let us define `CpuPriority` enum in a common file, say `port_defs.h`, such that both directories `rocksdb/include` and `port/` can include. When we remove this dependency, some other files have compile errors because they can't find definitions, so add header files to resolve # Test make all check -j Pull Request resolved: https://github.com/facebook/rocksdb/pull/11214 Reviewed By: pdillinger Differential Revision: D43196910 Pulled By: guowentian fbshipit-source-id: 70deccb72844cfb08fcc994f76c6ef6df5d55ab9 --- cache/clock_cache.cc | 2 +- include/rocksdb/env.h | 8 +------- include/rocksdb/port_defs.h | 22 ++++++++++++++++++++++ port/port_posix.h | 2 +- port/win/port_win.h | 21 +++++++++++---------- table/multiget_context.h | 1 + util/aligned_buffer.h | 1 + util/core_local.h | 1 + util/distributed_mutex.h | 2 ++ util/file_checksum_helper.h | 1 + util/mutexlock.h | 1 + util/random.cc | 1 + 12 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 include/rocksdb/port_defs.h diff --git a/cache/clock_cache.cc b/cache/clock_cache.cc index 9476dba7a..9582910ba 100644 --- a/cache/clock_cache.cc +++ b/cache/clock_cache.cc @@ -9,7 +9,6 @@ #include "cache/clock_cache.h" -#include #include #include @@ -18,6 +17,7 @@ #include "monitoring/perf_context_imp.h" #include "monitoring/statistics.h" #include "port/lang.h" +#include "rocksdb/env.h" #include "util/hash.h" #include "util/math.h" #include "util/random.h" diff --git a/include/rocksdb/env.h b/include/rocksdb/env.h index 1b6273d77..62af602c6 100644 --- a/include/rocksdb/env.h +++ b/include/rocksdb/env.h @@ -27,6 +27,7 @@ #include "rocksdb/customizable.h" #include "rocksdb/functor_wrapper.h" +#include "rocksdb/port_defs.h" #include "rocksdb/status.h" #include "rocksdb/thread_status.h" @@ -69,13 +70,6 @@ struct ConfigOptions; const size_t kDefaultPageSize = 4 * 1024; -enum class CpuPriority { - kIdle = 0, - kLow = 1, - kNormal = 2, - kHigh = 3, -}; - // Options while opening a file to read/write struct EnvOptions { // Construct with default Options diff --git a/include/rocksdb/port_defs.h b/include/rocksdb/port_defs.h new file mode 100644 index 000000000..9771aacb9 --- /dev/null +++ b/include/rocksdb/port_defs.h @@ -0,0 +1,22 @@ +// Copyright (c) Meta Platforms, Inc. and affiliates. +// This source code is licensed under both the GPLv2 (found in the +// COPYING file in the root directory) and Apache 2.0 License +// (found in the LICENSE.Apache file in the root directory). +// +// This file includes the common definitions used in the port/, +// the public API (this directory), and other directories + +#pragma once + +#include "rocksdb/rocksdb_namespace.h" + +namespace ROCKSDB_NAMESPACE { + +enum class CpuPriority { + kIdle = 0, + kLow = 1, + kNormal = 2, + kHigh = 3, +}; + +} // namespace ROCKSDB_NAMESPACE diff --git a/port/port_posix.h b/port/port_posix.h index 417fbf4f6..cdb256a6d 100644 --- a/port/port_posix.h +++ b/port/port_posix.h @@ -13,7 +13,7 @@ #include -#include "rocksdb/options.h" +#include "rocksdb/port_defs.h" #include "rocksdb/rocksdb_namespace.h" // size_t printf formatting named in the manner of C99 standard formatting diff --git a/port/win/port_win.h b/port/win/port_win.h index 989b5620b..4d9883b63 100644 --- a/port/win/port_win.h +++ b/port/win/port_win.h @@ -17,21 +17,22 @@ #endif #include -#include -#include -#include -#include -#include -#include -#include +//^^ should be included first before other system lib #include +#include #include - #include +#include -#include "port/win/win_thread.h" +#include +#include +#include +#include +#include +#include -#include "rocksdb/options.h" +#include "port/win/win_thread.h" +#include "rocksdb/port_defs.h" #undef min #undef max diff --git a/table/multiget_context.h b/table/multiget_context.h index 76027a952..ca369dcb2 100644 --- a/table/multiget_context.h +++ b/table/multiget_context.h @@ -12,6 +12,7 @@ #include "db/lookup_key.h" #include "db/merge_context.h" #include "rocksdb/env.h" +#include "rocksdb/options.h" #include "rocksdb/statistics.h" #include "rocksdb/types.h" #include "util/async_file_reader.h" diff --git a/util/aligned_buffer.h b/util/aligned_buffer.h index 95ee5dfe8..acab56c21 100644 --- a/util/aligned_buffer.h +++ b/util/aligned_buffer.h @@ -9,6 +9,7 @@ #pragma once #include +#include #include "port/port.h" diff --git a/util/core_local.h b/util/core_local.h index b444a1152..25174aef8 100644 --- a/util/core_local.h +++ b/util/core_local.h @@ -5,6 +5,7 @@ #pragma once +#include #include #include #include diff --git a/util/distributed_mutex.h b/util/distributed_mutex.h index 9675a1e2d..1734269cc 100644 --- a/util/distributed_mutex.h +++ b/util/distributed_mutex.h @@ -36,6 +36,8 @@ using DMutexLock = std::lock_guard; #else +#include + #include "port/port.h" namespace ROCKSDB_NAMESPACE { diff --git a/util/file_checksum_helper.h b/util/file_checksum_helper.h index d622e9bba..52469cf9f 100644 --- a/util/file_checksum_helper.h +++ b/util/file_checksum_helper.h @@ -8,6 +8,7 @@ #include #include "port/port.h" +#include "rocksdb/env.h" #include "rocksdb/file_checksum.h" #include "rocksdb/status.h" #include "util/coding.h" diff --git a/util/mutexlock.h b/util/mutexlock.h index 94066b29e..a5b758153 100644 --- a/util/mutexlock.h +++ b/util/mutexlock.h @@ -11,6 +11,7 @@ #include #include +#include #include #include diff --git a/util/random.cc b/util/random.cc index c94c28dfb..7ac6ee19a 100644 --- a/util/random.cc +++ b/util/random.cc @@ -6,6 +6,7 @@ #include "util/random.h" +#include #include #include -- GitLab