Skip to content

Commit

Permalink
Merge pull request #7 from JinheLin/pr-8899-mod
Browse files Browse the repository at this point in the history
Not inline static member `global_file_cache_instance`
  • Loading branch information
Lloyd-Pottiger authored Apr 7, 2024
2 parents 93bd98a + a8bc111 commit 7b00584
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 32 deletions.
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();
GlobalFileCacheInstance::initialize(global_context->getPathCapacity(), config);
FileCache::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 (GlobalFileCacheInstance::instance() != nullptr)
if (FileCache::instance() != nullptr)
{
GlobalFileCacheInstance::instance()->updateConfig(global_context->getSettingsRef());
FileCache::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();
GlobalFileCacheInstance::shutdown();
FileCache::shutdown();
global_context->shutdown();
if (storage_config.s3_config.isS3Enabled())
{
Expand Down
2 changes: 2 additions & 0 deletions dbms/src/Storages/S3/FileCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namespace DB
{
using FileType = FileSegment::FileType;

std::unique_ptr<FileCache> FileCache::global_file_cache_instance;

FileCache::FileCache(PathCapacityMetricsPtr capacity_metrics_, const StorageRemoteCacheConfig & config_)
: capacity_metrics(capacity_metrics_)
, cache_dir(config_.getDTFileCacheDir())
Expand Down
45 changes: 18 additions & 27 deletions dbms/src/Storages/S3/FileCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ 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 @@ -213,6 +227,9 @@ class FileCache
public:
#endif

inline static std::atomic<bool> global_file_cache_initialized{false};
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 @@ -296,32 +313,6 @@ 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 All @@ -333,4 +324,4 @@ struct fmt::formatter<std::filesystem::path> : formatter<std::string_view>
{
return formatter<std::string_view>::format(path.string(), ctx);
}
};
};
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 = GlobalFileCacheInstance::instance();
auto * file_cache = FileCache::instance();
return file_cache != nullptr
? file_cache->getRandomAccessFile(S3::S3FilenameView::fromKey(remote_fname), filesize)
: nullptr;
Expand Down

0 comments on commit 7b00584

Please sign in to comment.