Skip to content

Commit

Permalink
restore global storage pool in test cases (#4878)
Browse files Browse the repository at this point in the history
close #4872
  • Loading branch information
hehechen authored May 12, 2022
1 parent efc93ad commit cdaea05
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
6 changes: 2 additions & 4 deletions dbms/src/Interpreters/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,10 +1649,8 @@ bool Context::initializeGlobalStoragePoolIfNeed(const PathPool & path_pool)
auto lock = getLock();
if (shared->global_storage_pool)
{
// Can't init GlobalStoragePool twice.
// Because we won't remove the gc task in BackGroundPool
// Also won't remove it from ~GlobalStoragePool()
throw Exception("GlobalStoragePool has already been initialized.", ErrorCodes::LOGICAL_ERROR);
// GlobalStoragePool may be initialized many times in some test cases for restore.
LOG_WARNING(shared->log, "GlobalStoragePool has already been initialized.");
}

if (shared->storage_run_mode == PageStorageRunMode::MIX_MODE || shared->storage_run_mode == PageStorageRunMode::ONLY_V3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ class PageStorageMixedTest : public DB::base::TiFlashStorageTestBasic
storage_path_pool_v3 = std::make_unique<PathPool>(Strings{path}, Strings{path}, Strings{}, std::make_shared<PathCapacityMetrics>(0, paths, caps, Strings{}, caps), global_context.getFileProvider(), true);

global_context.setPageStorageRunMode(PageStorageRunMode::MIX_MODE);
if (!global_context.getGlobalStoragePool())
global_context.initializeGlobalStoragePoolIfNeed(*storage_path_pool_v3);
}

void SetUp() override
{
auto & global_context = DB::tests::TiFlashTestEnv::getGlobalContext();
global_context.setPageStorageRunMode(PageStorageRunMode::MIX_MODE);
TiFlashStorageTestBasic::SetUp();
const auto & path = getTemporaryPath();
createIfNotExist(path);

auto & global_context = DB::tests::TiFlashTestEnv::getGlobalContext();

std::vector<size_t> caps = {};
Strings paths = {path};
Expand All @@ -75,7 +74,7 @@ class PageStorageMixedTest : public DB::base::TiFlashStorageTestBasic

PageStorageRunMode reloadMixedStoragePool()
{
DB::tests::TiFlashTestEnv::getContext().setPageStorageRunMode(PageStorageRunMode::MIX_MODE);
db_context->setPageStorageRunMode(PageStorageRunMode::MIX_MODE);
PageStorageRunMode run_mode = storage_pool_mix->restore();
page_writer_mix = storage_pool_mix->logWriter();
page_reader_mix = storage_pool_mix->logReader();
Expand All @@ -84,7 +83,7 @@ class PageStorageMixedTest : public DB::base::TiFlashStorageTestBasic

void reloadV2StoragePool()
{
DB::tests::TiFlashTestEnv::getContext().setPageStorageRunMode(PageStorageRunMode::ONLY_V2);
db_context->setPageStorageRunMode(PageStorageRunMode::ONLY_V2);
storage_pool_v2->restore();
page_writer_v2 = storage_pool_v2->logWriter();
page_reader_v2 = storage_pool_v2->logReader();
Expand Down
1 change: 1 addition & 0 deletions dbms/src/TestUtils/TiFlashTestEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Context TiFlashTestEnv::getContext(const DB::Settings & settings, Strings testda
context.setPath(root_path);
auto paths = getPathPool(testdata_path);
context.setPathPool(paths.first, paths.second, Strings{}, true, context.getPathCapacity(), context.getFileProvider());
global_context->initializeGlobalStoragePoolIfNeed(context.getPathPool());
context.getSettingsRef() = settings;
return context;
}
Expand Down

0 comments on commit cdaea05

Please sign in to comment.