forked from pingcap/tiflash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Storage: Refactor for fixing recreate Storage instance (pingcap#8701)
ref pingcap#8695
- Loading branch information
1 parent
bdc1e9d
commit 707537a
Showing
36 changed files
with
322 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
dbms/src/Storages/DeltaMerge/StoragePool/GlobalStoragePool.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <Interpreters/Context.h> | ||
#include <Storages/DeltaMerge/StoragePool/GlobalStoragePool.h> | ||
#include <Storages/DeltaMerge/StoragePool/StoragePoolConfig.h> | ||
#include <Storages/Page/Page.h> | ||
#include <Storages/Page/PageStorage.h> | ||
#include <Storages/PathPool.h> | ||
|
||
namespace DB::DM | ||
{ | ||
|
||
GlobalStoragePool::GlobalStoragePool(const PathPool & path_pool, Context & global_ctx, const Settings & settings) | ||
: log_storage(PageStorage::create( | ||
"__global__.log", | ||
path_pool.getPSDiskDelegatorGlobalMulti(PathPool::log_path_prefix), | ||
extractConfig(settings, StorageType::Log), | ||
global_ctx.getFileProvider(), | ||
global_ctx, | ||
true)) | ||
, data_storage(PageStorage::create( | ||
"__global__.data", | ||
path_pool.getPSDiskDelegatorGlobalMulti(PathPool::data_path_prefix), | ||
extractConfig(settings, StorageType::Data), | ||
global_ctx.getFileProvider(), | ||
global_ctx, | ||
true)) | ||
, meta_storage(PageStorage::create( | ||
"__global__.meta", | ||
path_pool.getPSDiskDelegatorGlobalMulti(PathPool::meta_path_prefix), | ||
extractConfig(settings, StorageType::Meta), | ||
global_ctx.getFileProvider(), | ||
global_ctx, | ||
true)) | ||
, global_context(global_ctx) | ||
{} | ||
|
||
|
||
GlobalStoragePool::~GlobalStoragePool() | ||
{ | ||
shutdown(); | ||
} | ||
|
||
void GlobalStoragePool::restore() | ||
{ | ||
log_storage->restore(); | ||
data_storage->restore(); | ||
meta_storage->restore(); | ||
|
||
gc_handle = global_context.getBackgroundPool().addTask( | ||
[this] { return this->gc(global_context.getSettingsRef()); }, | ||
false); | ||
} | ||
|
||
void GlobalStoragePool::shutdown() | ||
{ | ||
if (gc_handle) | ||
{ | ||
global_context.getBackgroundPool().removeTask(gc_handle); | ||
gc_handle = {}; | ||
} | ||
} | ||
|
||
FileUsageStatistics GlobalStoragePool::getLogFileUsage() const | ||
{ | ||
return log_storage->getFileUsageStatistics(); | ||
} | ||
|
||
bool GlobalStoragePool::gc() | ||
{ | ||
return gc(global_context.getSettingsRef(), /*immediately=*/true, DELTA_MERGE_GC_PERIOD); | ||
} | ||
|
||
bool GlobalStoragePool::gc(const Settings & settings, bool immediately, const Seconds & try_gc_period) | ||
{ | ||
Timepoint now = Clock::now(); | ||
if (!immediately) | ||
{ | ||
// No need lock | ||
if (now < (last_try_gc_time.load() + try_gc_period)) | ||
return false; | ||
} | ||
|
||
last_try_gc_time = now; | ||
|
||
bool done_anything = false; | ||
auto write_limiter = global_context.getWriteLimiter(); | ||
auto read_limiter = global_context.getReadLimiter(); | ||
auto config = extractConfig(settings, StorageType::Meta); | ||
meta_storage->reloadSettings(config); | ||
done_anything |= meta_storage->gc(/*not_skip*/ false, write_limiter, read_limiter); | ||
|
||
config = extractConfig(settings, StorageType::Data); | ||
data_storage->reloadSettings(config); | ||
done_anything |= data_storage->gc(/*not_skip*/ false, write_limiter, read_limiter); | ||
|
||
config = extractConfig(settings, StorageType::Log); | ||
log_storage->reloadSettings(config); | ||
done_anything |= log_storage->gc(/*not_skip*/ false, write_limiter, read_limiter); | ||
|
||
return done_anything; | ||
} | ||
|
||
} // namespace DB::DM |
82 changes: 82 additions & 0 deletions
82
dbms/src/Storages/DeltaMerge/StoragePool/GlobalStoragePool.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <Common/Logger.h> | ||
#include <Interpreters/Context_fwd.h> | ||
#include <Storages/BackgroundProcessingPool.h> | ||
#include <Storages/DeltaMerge/StoragePool/StoragePool_fwd.h> | ||
#include <Storages/KVStore/Types.h> | ||
#include <Storages/Page/FileUsage.h> | ||
#include <Storages/Page/PageStorage_fwd.h> | ||
|
||
#include <atomic> | ||
#include <chrono> | ||
|
||
namespace DB | ||
{ | ||
class WriteLimiter; | ||
using WriteLimiterPtr = std::shared_ptr<WriteLimiter>; | ||
class ReadLimiter; | ||
using ReadLimiterPtr = std::shared_ptr<ReadLimiter>; | ||
|
||
struct Settings; | ||
class PathPool; | ||
class StableDiskDelegator; | ||
class AsynchronousMetrics; | ||
} // namespace DB | ||
|
||
namespace DB::DM | ||
{ | ||
|
||
class GlobalStoragePool : private boost::noncopyable | ||
{ | ||
public: | ||
using Clock = std::chrono::system_clock; | ||
using Timepoint = Clock::time_point; | ||
using Seconds = std::chrono::seconds; | ||
|
||
GlobalStoragePool(const PathPool & path_pool, Context & global_ctx, const Settings & settings); | ||
|
||
~GlobalStoragePool(); | ||
|
||
void restore(); | ||
|
||
void shutdown(); | ||
|
||
friend class StoragePool; | ||
friend class ::DB::AsynchronousMetrics; | ||
|
||
// GC immediately | ||
// Only used on dbgFuncMisc | ||
bool gc(); | ||
|
||
FileUsageStatistics getLogFileUsage() const; | ||
|
||
private: | ||
bool gc(const Settings & settings, bool immediately = false, const Seconds & try_gc_period = DELTA_MERGE_GC_PERIOD); | ||
|
||
private: | ||
PageStoragePtr log_storage; | ||
PageStoragePtr data_storage; | ||
PageStoragePtr meta_storage; | ||
|
||
std::atomic<Timepoint> last_try_gc_time = Clock::now(); | ||
|
||
Context & global_context; | ||
BackgroundProcessingPool::TaskHandle gc_handle; | ||
}; | ||
|
||
} // namespace DB::DM |
Oops, something went wrong.