Skip to content

Commit

Permalink
introduce GlobalFileCacheInstance
Browse files Browse the repository at this point in the history
Signed-off-by: Lloyd-Pottiger <[email protected]>
  • Loading branch information
Lloyd-Pottiger committed Apr 3, 2024
1 parent f04b16d commit 93bd98a
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ endif ()

include (cmake/cpu_features.cmake)

set (CMAKE_CXX_STANDARD 20)
set (CMAKE_CXX_STANDARD 23)
set (CMAKE_CXX_EXTENSIONS 1) # https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html#prop_tgt:CXX_EXTENSIONS
set (CMAKE_CXX_STANDARD_REQUIRED ON)

Expand Down
4 changes: 4 additions & 0 deletions contrib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ if (USE_INTERNAL_POCO_LIBRARY)
set (ENABLE_DATA_ODBC 0 CACHE INTERNAL "") # TODO (build fail)
endif ()
add_subdirectory (poco)
target_compile_options(Net PUBLIC "-Wno-error=deprecated-declarations")
target_compile_options(Net PUBLIC "-Wno-deprecated-declarations")
target_no_warning(NetSSL deprecated-declarations)
target_no_warning(Net deprecated-enum-enum-conversion)
unset (CMAKE_DISABLE_FIND_PACKAGE_ZLIB)
set (ENABLE_TESTS ${_save})
set (CMAKE_CXX_FLAGS ${save_CMAKE_CXX_FLAGS})
Expand Down
1 change: 1 addition & 0 deletions contrib/boringssl-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ add_library(
"${BORINGSSL_SOURCE_DIR}/crypto/x509v3/v3_skey.c"
"${BORINGSSL_SOURCE_DIR}/crypto/x509v3/v3_utl.c"
)
target_compile_options(crypto PRIVATE "-Wno-unused-but-set-variable")

add_library(
ssl
Expand Down
4 changes: 4 additions & 0 deletions contrib/grpc-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# We want to use C++23, but GRPC is not ready
set (CMAKE_CXX_STANDARD 20)

set(_gRPC_SOURCE_DIR "${TiFlash_SOURCE_DIR}/contrib/grpc")
set(_gRPC_BINARY_DIR "${TiFlash_BINARY_DIR}/contrib/grpc")

Expand Down Expand Up @@ -65,6 +68,7 @@ endif ()
# reject to start w/o it. While this is completelly different library.
#
# [3]: https://packages.debian.org/bullseye/libnsl2

if (NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS")
set(HAVE_LIBNSL OFF CACHE BOOL "" FORCE)
endif()
Expand Down
1 change: 1 addition & 0 deletions contrib/libunwind-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,4 @@ target_include_directories (unwind PUBLIC ${LIBUNWIND_SOURCE_DIR}/include)
target_include_directories (unwind PRIVATE ${LIBUNWIND_SOURCE_DIR}/include/tdep)
target_include_directories (unwind PRIVATE ${LIBUNWIND_SOURCE_DIR}/src)
target_include_directories (unwind PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include)
target_compile_options (unwind PRIVATE "-Wno-single-bit-bitfield-constant-conversion")
1 change: 1 addition & 0 deletions contrib/protobuf-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ set(libprotoc_files

add_library(libprotoc ${libprotoc_files})
target_link_libraries(libprotoc libprotobuf)
target_compile_options(libprotoc PRIVATE "-Wno-deprecated-pragma")
add_library(protobuf::libprotoc ALIAS libprotoc)

set(protoc_files ${protobuf_source_dir}/src/google/protobuf/compiler/main.cc)
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Common/RemoteHostFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <common/defines.h>

#include <atomic>
#include <mutex>
#include <string>
#include <unordered_set>
Expand Down
8 changes: 4 additions & 4 deletions dbms/src/Server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
if (const auto & config = storage_config.remote_cache_config; config.isCacheEnabled() && is_compute_mode)
{
config.initCacheDir();
FileCache::initialize(global_context->getPathCapacity(), config);
GlobalFileCacheInstance::initialize(global_context->getPathCapacity(), config);
}

/// Determining PageStorage run mode based on current files on disk and storage config.
Expand Down Expand Up @@ -1387,9 +1387,9 @@ int Server::main(const std::vector<std::string> & /*args*/)
global_context->getIORateLimiter().updateConfig(*config);
global_context->reloadDeltaTreeConfig(*config);
DM::SegmentReadTaskScheduler::instance().updateConfig(global_context->getSettingsRef());
if (FileCache::instance() != nullptr)
if (GlobalFileCacheInstance::instance() != nullptr)
{
FileCache::instance()->updateConfig(global_context->getSettingsRef());
GlobalFileCacheInstance::instance()->updateConfig(global_context->getSettingsRef());
}
{
// update TiFlashSecurity and related config in client for ssl certificate reload.
Expand Down Expand Up @@ -1536,7 +1536,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
// `Context::shutdown()` will destroy `DeltaIndexManager`.
// So, stop threads explicitly before `TiFlashTestEnv::shutdown()`.
DB::DM::SegmentReaderPoolManager::instance().stop();
FileCache::shutdown();
GlobalFileCacheInstance::shutdown();
global_context->shutdown();
if (storage_config.s3_config.isS3Enabled())
{
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Storages/DeltaMerge/StoragePool/StoragePool_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include <chrono>
#include <memory>

namespace DB::DM
Expand Down
1 change: 0 additions & 1 deletion dbms/src/Storages/S3/FileCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <chrono>
#include <cmath>
#include <filesystem>
#include <fstream>

namespace ProfileEvents
{
Expand Down
43 changes: 26 additions & 17 deletions dbms/src/Storages/S3/FileCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,6 @@ class LRUFileTable
class FileCache
{
public:
static void initialize(PathCapacityMetricsPtr capacity_metrics_, const StorageRemoteCacheConfig & config_)
{
global_file_cache_instance = std::make_unique<FileCache>(capacity_metrics_, config_);
global_file_cache_initialized.store(true, std::memory_order_release);
}

static FileCache * instance()
{
return global_file_cache_initialized.load(std::memory_order_acquire) ? global_file_cache_instance.get()
: nullptr;
}

static void shutdown() { global_file_cache_instance = nullptr; }

FileCache(PathCapacityMetricsPtr capacity_metrics_, const StorageRemoteCacheConfig & config_);

RandomAccessFilePtr getRandomAccessFile(
Expand All @@ -227,9 +213,6 @@ class FileCache
public:
#endif

inline static std::atomic<bool> global_file_cache_initialized{false};
inline static std::unique_ptr<FileCache> global_file_cache_instance;

DISALLOW_COPY_AND_MOVE(FileCache);

FileSegmentPtr get(const S3::S3FilenameView & s3_fname, const std::optional<UInt64> & filesize = std::nullopt);
Expand Down Expand Up @@ -313,6 +296,32 @@ class FileCache

DB::LoggerPtr log;
};

class GlobalFileCacheInstance
{
public:
static void initialize(PathCapacityMetricsPtr capacity_metrics_, const StorageRemoteCacheConfig & config_)
{
global_file_cache_instance = std::make_unique<FileCache>(capacity_metrics_, config_);
global_file_cache_initialized.store(true, std::memory_order_release);
}

static FileCache * instance()
{
return global_file_cache_initialized.load(std::memory_order_acquire) ? global_file_cache_instance.get()
: nullptr;
}

static void shutdown() { global_file_cache_instance = nullptr; }

private:
GlobalFileCacheInstance() = default;
~GlobalFileCacheInstance() = default;

inline static std::unique_ptr<FileCache> global_file_cache_instance;
inline static std::atomic<bool> global_file_cache_initialized{false};
};

} // namespace DB

// Make std::filesystem::path formattable.
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/S3/S3RandomAccessFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ inline static RandomAccessFilePtr tryOpenCachedFile(const String & remote_fname,
{
try
{
auto * file_cache = FileCache::instance();
auto * file_cache = GlobalFileCacheInstance::instance();
return file_cache != nullptr
? file_cache->getRandomAccessFile(S3::S3FilenameView::fromKey(remote_fname), filesize)
: nullptr;
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/TiDB/Schema/SchemaSyncService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void SchemaSyncService::addKeyspaceGCTasks()
UInt64 num_add_tasks = 0;
// Add new sync schema task for new keyspace.
std::unique_lock<std::shared_mutex> lock(keyspace_map_mutex);
for (auto const iter : keyspaces)
for (auto const & iter : keyspaces)
{
auto keyspace = iter.first;
if (keyspace_handle_map.contains(keyspace))
Expand Down
2 changes: 1 addition & 1 deletion libs/libcommon/include/common/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#pragma once

#include <condition_variable>
#include <cstdint>
#include <exception>
#include <functional>
#include <mutex>
#include <queue>
Expand Down

0 comments on commit 93bd98a

Please sign in to comment.