Skip to content

Commit

Permalink
ddl: Refactor for fixing unstable drop table (pingcap#8421)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang committed Nov 30, 2023
1 parent fe6621b commit 9423b9c
Show file tree
Hide file tree
Showing 20 changed files with 506 additions and 727 deletions.
2 changes: 1 addition & 1 deletion dbms/src/Storages/DeltaMerge/StoragePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ PageStorageRunMode StoragePool::restore()
logger,
"Finished StoragePool restore. [current_run_mode={}] [ns_id={}]"
" [max_log_page_id={}] [max_data_page_id={}] [max_meta_page_id={}]",
static_cast<UInt8>(run_mode),
magic_enum::enum_name(run_mode),
ns_id,
max_log_page_id,
max_data_page_id,
Expand Down
1 change: 0 additions & 1 deletion dbms/src/Storages/tests/gtest_filter_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <Storages/DeltaMerge/Index/RSResult.h>
#include <Storages/KVStore/TMTContext.h>
#include <TestUtils/TiFlashTestBasic.h>
#include <TiDB/Schema/SchemaBuilder-internal.h>
#include <TiDB/Schema/SchemaNameMapper.h>
#include <common/logger_useful.h>

Expand Down
1 change: 0 additions & 1 deletion dbms/src/Storages/tests/gtests_parse_push_down_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <Storages/StorageDeltaMerge.h>
#include <TestUtils/FunctionTestUtils.h>
#include <TestUtils/TiFlashTestBasic.h>
#include <TiDB/Schema/SchemaBuilder-internal.h>
#include <common/logger_useful.h>

#include <regex>
Expand Down
79 changes: 79 additions & 0 deletions dbms/src/TiDB/Schema/DatabaseInfoCache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2023 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 <Storages/KVStore/Types.h>
#include <TiDB/Schema/TiDB.h>

#include <shared_mutex>
#include <unordered_map>

namespace DB
{

class DatabaseInfoCache
{
public:
TiDB::DBInfoPtr getDBInfoByName(const String & database_name) const
{
std::shared_lock lock(mtx_databases);

auto it = std::find_if(databases.begin(), databases.end(), [&](const auto & pair) {
return pair.second->name == database_name;
});
if (it == databases.end())
return nullptr;
return it->second;
}

void addDatabaseInfo(const TiDB::DBInfoPtr & db_info)
{
std::unique_lock lock(mtx_databases);
databases.emplace(db_info->id, db_info);
}

TiDB::DBInfoPtr getDBInfo(DatabaseID database_id) const
{
std::shared_lock shared_lock(mtx_databases);
if (auto it = databases.find(database_id); likely(it != databases.end()))
{
return it->second;
}
return nullptr;
}

bool exists(DatabaseID database_id) const
{
std::shared_lock shared_lock(mtx_databases);
return databases.contains(database_id);
}

void eraseDBInfo(DatabaseID database_id)
{
std::unique_lock shared_lock(mtx_databases);
databases.erase(database_id);
}

void clear()
{
std::unique_lock lock(mtx_databases);
databases.clear();
}

private:
mutable std::shared_mutex mtx_databases;
std::unordered_map<DB::DatabaseID, TiDB::DBInfoPtr> databases;
};
} // namespace DB
152 changes: 0 additions & 152 deletions dbms/src/TiDB/Schema/SchemaBuilder-internal.h

This file was deleted.

0 comments on commit 9423b9c

Please sign in to comment.