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
This commit is contained in:
Wentian Guo 2023-02-13 02:21:38 -08:00 committed by Facebook GitHub Bot
parent a72f591825
commit 42d6652ba2
12 changed files with 45 additions and 20 deletions

View file

@ -9,7 +9,6 @@
#include "cache/clock_cache.h" #include "cache/clock_cache.h"
#include <cassert>
#include <functional> #include <functional>
#include <numeric> #include <numeric>
@ -18,6 +17,7 @@
#include "monitoring/perf_context_imp.h" #include "monitoring/perf_context_imp.h"
#include "monitoring/statistics.h" #include "monitoring/statistics.h"
#include "port/lang.h" #include "port/lang.h"
#include "rocksdb/env.h"
#include "util/hash.h" #include "util/hash.h"
#include "util/math.h" #include "util/math.h"
#include "util/random.h" #include "util/random.h"

View file

@ -27,6 +27,7 @@
#include "rocksdb/customizable.h" #include "rocksdb/customizable.h"
#include "rocksdb/functor_wrapper.h" #include "rocksdb/functor_wrapper.h"
#include "rocksdb/port_defs.h"
#include "rocksdb/status.h" #include "rocksdb/status.h"
#include "rocksdb/thread_status.h" #include "rocksdb/thread_status.h"
@ -69,13 +70,6 @@ struct ConfigOptions;
const size_t kDefaultPageSize = 4 * 1024; 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 // Options while opening a file to read/write
struct EnvOptions { struct EnvOptions {
// Construct with default Options // Construct with default Options

View file

@ -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

View file

@ -13,7 +13,7 @@
#include <thread> #include <thread>
#include "rocksdb/options.h" #include "rocksdb/port_defs.h"
#include "rocksdb/rocksdb_namespace.h" #include "rocksdb/rocksdb_namespace.h"
// size_t printf formatting named in the manner of C99 standard formatting // size_t printf formatting named in the manner of C99 standard formatting

View file

@ -17,21 +17,22 @@
#endif #endif
#include <windows.h> #include <windows.h>
//^^ <windows.h> should be included first before other system lib
#include <intrin.h>
#include <malloc.h>
#include <process.h>
#include <stdint.h>
#include <string.h>
#include <cassert>
#include <condition_variable>
#include <limits>
#include <mutex>
#include <string> #include <string>
#include <thread> #include <thread>
#include <string.h>
#include <mutex>
#include <limits>
#include <condition_variable>
#include <malloc.h>
#include <intrin.h>
#include <process.h>
#include <stdint.h>
#include "port/win/win_thread.h" #include "port/win/win_thread.h"
#include "rocksdb/port_defs.h"
#include "rocksdb/options.h"
#undef min #undef min
#undef max #undef max

View file

@ -12,6 +12,7 @@
#include "db/lookup_key.h" #include "db/lookup_key.h"
#include "db/merge_context.h" #include "db/merge_context.h"
#include "rocksdb/env.h" #include "rocksdb/env.h"
#include "rocksdb/options.h"
#include "rocksdb/statistics.h" #include "rocksdb/statistics.h"
#include "rocksdb/types.h" #include "rocksdb/types.h"
#include "util/async_file_reader.h" #include "util/async_file_reader.h"

View file

@ -9,6 +9,7 @@
#pragma once #pragma once
#include <algorithm> #include <algorithm>
#include <cassert>
#include "port/port.h" #include "port/port.h"

View file

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <cassert>
#include <cstddef> #include <cstddef>
#include <thread> #include <thread>
#include <utility> #include <utility>

View file

@ -36,6 +36,8 @@ using DMutexLock = std::lock_guard<folly::DistributedMutex>;
#else #else
#include <mutex>
#include "port/port.h" #include "port/port.h"
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {

View file

@ -8,6 +8,7 @@
#include <unordered_map> #include <unordered_map>
#include "port/port.h" #include "port/port.h"
#include "rocksdb/env.h"
#include "rocksdb/file_checksum.h" #include "rocksdb/file_checksum.h"
#include "rocksdb/status.h" #include "rocksdb/status.h"
#include "util/coding.h" #include "util/coding.h"

View file

@ -11,6 +11,7 @@
#include <assert.h> #include <assert.h>
#include <atomic> #include <atomic>
#include <functional>
#include <mutex> #include <mutex>
#include <thread> #include <thread>

View file

@ -6,6 +6,7 @@
#include "util/random.h" #include "util/random.h"
#include <limits.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>