Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: add new module schema #4932

Merged
merged 19 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dbms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ add_headers_and_sources(dbms src/Storages/Page/V2/mvcc)
add_headers_and_sources(dbms src/Storages/Page/V2/VersionSet)
add_headers_and_sources(dbms src/Storages/Page/V2/gc)
add_headers_and_sources(dbms src/WindowFunctions)
add_headers_and_sources(dbms src/TiDB/Schema)
if (ENABLE_V3_PAGESTORAGE)
add_headers_and_sources(dbms src/Storages/Page/V3)
add_headers_and_sources(dbms src/Storages/Page/V3/LogFile)
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Databases/test/gtest_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
#include <Storages/IManageableStorage.h>
#include <Storages/IStorage.h>
#include <Storages/MutableSupport.h>
#include <Storages/Transaction/SchemaNameMapper.h>
#include <Storages/Transaction/TMTContext.h>
#include <Storages/Transaction/TMTStorages.h>
#include <Storages/registerStorages.h>
#include <TestUtils/TiFlashTestBasic.h>
#include <TiDB/Schema/SchemaNameMapper.h>
#include <common/ThreadPool.h>
#include <common/logger_useful.h>

Expand Down
3 changes: 1 addition & 2 deletions dbms/src/Debug/MockSchemaGetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
#pragma once

#include <Debug/MockTiDB.h>
#include <Storages/Transaction/SchemaGetter.h>
#include <TiDB/Schema/SchemaGetter.h>

namespace DB
{

struct MockSchemaGetter
{

TiDB::DBInfoPtr getDatabase(DatabaseID db_id) { return MockTiDB::instance().getDBInfoByID(db_id); }

Int64 getVersion() { return MockTiDB::instance().getVersion(); }
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Debug/MockSchemaNameMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#pragma once

#include <Storages/Transaction/SchemaNameMapper.h>
#include <TiDB/Schema/SchemaNameMapper.h>

namespace DB
{
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Debug/MockTiDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#pragma once

#include <Storages/ColumnsDescription.h>
#include <Storages/Transaction/SchemaGetter.h>
#include <Storages/Transaction/SchemaSyncer.h>
#include <Storages/Transaction/TiDB.h>
#include <Storages/Transaction/Types.h>
#include <TiDB/Schema/SchemaGetter.h>
#include <TiDB/Schema/SchemaSyncer.h>

#include <atomic>

Expand Down
20 changes: 10 additions & 10 deletions dbms/src/Debug/dbgFuncCoprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ void dbgFuncTiDBQueryFromNaturalDag(Context & context, const ASTs & args, DBGInv
if (args.size() != 1)
throw Exception("Args not matched, should be: json_dag_path", ErrorCodes::BAD_ARGUMENTS);

String json_dag_path = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[0]).value);
auto json_dag_path = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[0]).value);
auto dag = NaturalDag(json_dag_path, &Poco::Logger::get("MockDAG"));
dag.init();
dag.build(context);
Expand Down Expand Up @@ -431,7 +431,7 @@ BlockInputStreamPtr dbgFuncTiDBQuery(Context & context, const ASTs & args)
if (args.empty() || args.size() > 3)
throw Exception("Args not matched, should be: query[, region-id, dag_prop_string]", ErrorCodes::BAD_ARGUMENTS);

String query = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[0]).value);
auto query = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[0]).value);
RegionID region_id = InvalidRegionID;
if (args.size() >= 2)
region_id = safeGet<RegionID>(typeid_cast<const ASTLiteral &>(*args[1]).value);
Expand Down Expand Up @@ -464,8 +464,8 @@ BlockInputStreamPtr dbgFuncMockTiDBQuery(Context & context, const ASTs & args)
if (args.size() < 2 || args.size() > 4)
throw Exception("Args not matched, should be: query, region-id[, start-ts, dag_prop_string]", ErrorCodes::BAD_ARGUMENTS);

String query = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[0]).value);
RegionID region_id = safeGet<RegionID>(typeid_cast<const ASTLiteral &>(*args[1]).value);
auto query = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[0]).value);
auto region_id = safeGet<RegionID>(typeid_cast<const ASTLiteral &>(*args[1]).value);
Timestamp start_ts = DEFAULT_MAX_READ_TSO;
if (args.size() >= 3)
start_ts = safeGet<Timestamp>(typeid_cast<const ASTLiteral &>(*args[2]).value);
Expand Down Expand Up @@ -671,14 +671,14 @@ const ASTTablesInSelectQueryElement * getJoin(ASTSelectQuery & ast_query)
if (!ast_query.tables)
return nullptr;

const ASTTablesInSelectQuery & tables_in_select_query = static_cast<const ASTTablesInSelectQuery &>(*ast_query.tables);
const auto & tables_in_select_query = static_cast<const ASTTablesInSelectQuery &>(*ast_query.tables);
if (tables_in_select_query.children.empty())
return nullptr;

const ASTTablesInSelectQueryElement * joined_table = nullptr;
for (const auto & child : tables_in_select_query.children)
{
const ASTTablesInSelectQueryElement & tables_element = static_cast<const ASTTablesInSelectQueryElement &>(*child);
const auto & tables_element = static_cast<const ASTTablesInSelectQueryElement &>(*child);
if (tables_element.table_join)
{
if (!joined_table)
Expand Down Expand Up @@ -737,7 +737,7 @@ std::pair<ExecutorPtr, bool> compileQueryBlock(
bool append_pk_column = false;
for (const auto & expr : ast_query.select_expression_list->children)
{
if (ASTIdentifier * identifier = typeid_cast<ASTIdentifier *>(expr.get()))
if (auto * identifier = typeid_cast<ASTIdentifier *>(expr.get()))
{
if (identifier->getColumnName() == MutableSupport::tidb_pk_column_name)
{
Expand All @@ -756,7 +756,7 @@ std::pair<ExecutorPtr, bool> compileQueryBlock(
String right_table_alias;
{
String database_name, table_name;
const ASTTableExpression & table_to_join = static_cast<const ASTTableExpression &>(*joined_table->table_expression);
const auto & table_to_join = static_cast<const ASTTableExpression &>(*joined_table->table_expression);
if (table_to_join.database_and_table_name)
{
auto identifier = static_cast<const ASTIdentifier &>(*table_to_join.database_and_table_name);
Expand Down Expand Up @@ -788,7 +788,7 @@ std::pair<ExecutorPtr, bool> compileQueryBlock(
bool right_append_pk_column = false;
for (const auto & expr : ast_query.select_expression_list->children)
{
if (ASTIdentifier * identifier = typeid_cast<ASTIdentifier *>(expr.get()))
if (auto * identifier = typeid_cast<ASTIdentifier *>(expr.get()))
{
auto names = splitQualifiedName(identifier->getColumnName());
if (names.second == MutableSupport::tidb_pk_column_name)
Expand Down Expand Up @@ -831,7 +831,7 @@ std::pair<ExecutorPtr, bool> compileQueryBlock(
bool has_agg_func = false;
for (const auto & child : ast_query.select_expression_list->children)
{
const ASTFunction * func = typeid_cast<const ASTFunction *>(child.get());
const auto * func = typeid_cast<const ASTFunction *>(child.get());
if (func && AggregateFunctionFactory::instance().isAggregateFunctionName(func->name))
{
has_agg_func = true;
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Debug/dbgFuncMockTiDBTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <Parsers/ParserRenameQuery.h>
#include <Parsers/parseQuery.h>
#include <Storages/Transaction/KVStore.h>
#include <Storages/Transaction/SchemaSyncer.h>
#include <Storages/Transaction/TMTContext.h>
#include <TiDB/Schema/SchemaSyncer.h>
#include <fmt/core.h>

namespace DB
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Debug/dbgFuncSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#include <Parsers/ASTLiteral.h>
#include <Parsers/ParserCreateQuery.h>
#include <Storages/IManageableStorage.h>
#include <Storages/Transaction/SchemaSyncService.h>
#include <Storages/Transaction/SchemaSyncer.h>
#include <Storages/Transaction/TMTContext.h>
#include <Storages/Transaction/TiDB.h>
#include <TiDB/Schema/SchemaSyncService.h>
#include <TiDB/Schema/SchemaSyncer.h>
#include <fmt/core.h>

#include <ext/singleton.h>
Expand Down
6 changes: 3 additions & 3 deletions dbms/src/Debug/dbgFuncSchemaName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTLiteral.h>
#include <Storages/IManageableStorage.h>
#include <Storages/Transaction/SchemaNameMapper.h>
#include <Storages/Transaction/SchemaSyncer.h>
#include <Storages/Transaction/TMTContext.h>
#include <TiDB/Schema/SchemaNameMapper.h>
#include <TiDB/Schema/SchemaSyncer.h>
#include <fmt/core.h>

#include <boost/algorithm/string/replace.hpp>
Expand Down Expand Up @@ -97,7 +97,7 @@ BlockInputStreamPtr dbgFuncQueryMapped(Context & context, const ASTs & args)
if (args.size() < 2 || args.size() > 3)
throw Exception("Args not matched, should be: query, database-name[, table-name]", ErrorCodes::BAD_ARGUMENTS);

String query = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[0]).value);
auto query = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[0]).value);
const String & database_name = typeid_cast<const ASTIdentifier &>(*args[1]).name;

if (args.size() == 3)
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Flash/BatchCoprocessorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <Flash/Coprocessor/InterpreterDAG.h>
#include <Flash/ServiceUtils.h>
#include <Storages/IStorage.h>
#include <Storages/Transaction/SchemaSyncer.h>
#include <Storages/Transaction/TMTContext.h>
#include <TiDB/Schema/SchemaSyncer.h>

#include <ext/scope_guard.h>

Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <Storages/MutableSupport.h>
#include <Storages/Transaction/KVStore.h>
#include <Storages/Transaction/LockException.h>
#include <Storages/Transaction/SchemaSyncer.h>
#include <TiDB/Schema/SchemaSyncer.h>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
Expand Down Expand Up @@ -186,7 +186,7 @@ void setQuotaAndLimitsOnTableScan(Context & context, DAGPipeline & pipeline)
QuotaForIntervals & quota = context.getQuota();

pipeline.transform([&](auto & stream) {
if (IProfilingBlockInputStream * p_stream = dynamic_cast<IProfilingBlockInputStream *>(stream.get()))
if (auto * p_stream = dynamic_cast<IProfilingBlockInputStream *>(stream.get()))
{
p_stream->setLimits(limits);
p_stream->setQuota(quota);
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Flash/CoprocessorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <Storages/IStorage.h>
#include <Storages/Transaction/LockException.h>
#include <Storages/Transaction/RegionException.h>
#include <Storages/Transaction/SchemaSyncer.h>
#include <Storages/Transaction/TMTContext.h>
#include <TiDB/Schema/SchemaSyncer.h>

#include <ext/scope_guard.h>

Expand Down
23 changes: 12 additions & 11 deletions dbms/src/Interpreters/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
#include <Storages/PathCapacityMetrics.h>
#include <Storages/PathPool.h>
#include <Storages/Transaction/BackgroundService.h>
#include <Storages/Transaction/SchemaSyncService.h>
#include <Storages/Transaction/TMTContext.h>
#include <TableFunctions/TableFunctionFactory.h>
#include <TiDB/Schema/SchemaSyncService.h>
#include <common/logger_useful.h>
#include <fiu.h>
#include <fmt/core.h>
Expand Down Expand Up @@ -207,6 +207,7 @@ struct ContextShared

explicit ContextShared(std::shared_ptr<IRuntimeComponentsFactory> runtime_components_factory_)
: runtime_components_factory(std::move(runtime_components_factory_))
, storage_run_mode(PageStorageRunMode::MIX_MODE)
hzh0425 marked this conversation as resolved.
Show resolved Hide resolved
{
/// TODO: make it singleton (?)
static std::atomic<size_t> num_calls{0};
Expand Down Expand Up @@ -714,7 +715,7 @@ Dependencies Context::getDependencies(const String & database_name, const String
checkDatabaseAccessRightsImpl(db);
}

ViewDependencies::const_iterator iter = shared->view_dependencies.find(DatabaseAndTableName(db, table_name));
auto iter = shared->view_dependencies.find(DatabaseAndTableName(db, table_name));
if (iter == shared->view_dependencies.end())
return {};

Expand All @@ -728,7 +729,7 @@ bool Context::isTableExist(const String & database_name, const String & table_na
String db = resolveDatabase(database_name, current_database);
checkDatabaseAccessRightsImpl(db);

Databases::const_iterator it = shared->databases.find(db);
auto it = shared->databases.find(db);
return shared->databases.end() != it
&& it->second->isTableExist(*this, table_name);
}
Expand All @@ -754,7 +755,7 @@ void Context::assertTableExists(const String & database_name, const String & tab
String db = resolveDatabase(database_name, current_database);
checkDatabaseAccessRightsImpl(db);

Databases::const_iterator it = shared->databases.find(db);
auto it = shared->databases.find(db);
if (shared->databases.end() == it)
throw Exception(fmt::format("Database {} doesn't exist", backQuoteIfNeed(db)), ErrorCodes::UNKNOWN_DATABASE);

Expand All @@ -771,7 +772,7 @@ void Context::assertTableDoesntExist(const String & database_name, const String
if (check_database_access_rights)
checkDatabaseAccessRightsImpl(db);

Databases::const_iterator it = shared->databases.find(db);
auto it = shared->databases.find(db);
if (shared->databases.end() != it && it->second->isTableExist(*this, table_name))
throw Exception(fmt::format("Table {}.{} already exists.", backQuoteIfNeed(db), backQuoteIfNeed(table_name)), ErrorCodes::TABLE_ALREADY_EXISTS);
}
Expand Down Expand Up @@ -826,7 +827,7 @@ Tables Context::getExternalTables() const

StoragePtr Context::tryGetExternalTable(const String & table_name) const
{
TableAndCreateASTs::const_iterator jt = external_tables.find(table_name);
auto jt = external_tables.find(table_name);
if (external_tables.end() == jt)
return StoragePtr();

Expand Down Expand Up @@ -864,7 +865,7 @@ StoragePtr Context::getTableImpl(const String & database_name, const String & ta
String db = resolveDatabase(database_name, current_database);
checkDatabaseAccessRightsImpl(db);

Databases::const_iterator it = shared->databases.find(db);
auto it = shared->databases.find(db);
if (shared->databases.end() == it)
{
if (exception)
Expand Down Expand Up @@ -894,7 +895,7 @@ void Context::addExternalTable(const String & table_name, const StoragePtr & sto

StoragePtr Context::tryRemoveExternalTable(const String & table_name)
{
TableAndCreateASTs::const_iterator it = external_tables.find(table_name);
auto it = external_tables.find(table_name);

if (external_tables.end() == it)
return StoragePtr();
Expand Down Expand Up @@ -954,7 +955,7 @@ std::unique_ptr<DDLGuard> Context::getDDLGuardIfTableDoesntExist(const String &
{
auto lock = getLock();

Databases::const_iterator it = shared->databases.find(database);
auto it = shared->databases.find(database);
if (shared->databases.end() != it && it->second->isTableExist(*this, table))
return {};

Expand Down Expand Up @@ -993,7 +994,7 @@ ASTPtr Context::getCreateTableQuery(const String & database_name, const String &

ASTPtr Context::getCreateExternalTableQuery(const String & table_name) const
{
TableAndCreateASTs::const_iterator jt = external_tables.find(table_name);
auto jt = external_tables.find(table_name);
if (external_tables.end() == jt)
throw Exception(fmt::format("Temporary table {} doesn't exist", backQuoteIfNeed(table_name)), ErrorCodes::UNKNOWN_TABLE);

Expand Down Expand Up @@ -1088,7 +1089,7 @@ void Context::setCurrentQueryId(const String & query_id)
UInt64 a;
UInt64 b;
};
} random;
} random{};

{
auto lock = getLock();
Expand Down
Loading