From a3b4762cdea8106e55b9fef7211b44896f9c07e8 Mon Sep 17 00:00:00 2001 From: Alexander Tokmakov Date: Wed, 30 Oct 2019 15:17:52 +0300 Subject: [PATCH] fixes --- dbms/src/Databases/DatabaseAtomic.cpp | 7 +++++++ dbms/src/Databases/DatabaseAtomic.h | 6 ++++++ dbms/src/Databases/DatabaseOnDisk.cpp | 5 +++-- dbms/src/Databases/DatabaseOnDisk.h | 2 +- dbms/src/Interpreters/loadMetadata.cpp | 5 +++-- dbms/src/Storages/MergeTree/MergeTreeData.cpp | 4 +--- dbms/src/Storages/tests/storage_log.cpp | 7 ++++--- 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/dbms/src/Databases/DatabaseAtomic.cpp b/dbms/src/Databases/DatabaseAtomic.cpp index cc67b45f8a1..dfbb6d1057e 100644 --- a/dbms/src/Databases/DatabaseAtomic.cpp +++ b/dbms/src/Databases/DatabaseAtomic.cpp @@ -1,4 +1,5 @@ #include +#include namespace DB @@ -9,6 +10,12 @@ DatabaseAtomic::DatabaseAtomic(String name_, String metadata_path_, const Contex { } +void DatabaseAtomic::renameTable(const Context & context, const String & table_name, IDatabase & to_database, + const String & to_table_name, TableStructureWriteLockHolder & lock) +{ + //TODO + DatabaseOnDisk::renameTable(*this, context, table_name, to_database, to_table_name, lock); +} } diff --git a/dbms/src/Databases/DatabaseAtomic.h b/dbms/src/Databases/DatabaseAtomic.h index fa1e3573a8a..9bd1b1184c5 100644 --- a/dbms/src/Databases/DatabaseAtomic.h +++ b/dbms/src/Databases/DatabaseAtomic.h @@ -15,6 +15,12 @@ public: String getEngineName() const override { return "Atomic"; } + void renameTable(const Context & context, + const String & table_name, + IDatabase & to_database, + const String & to_table_name, + TableStructureWriteLockHolder &) override; + }; diff --git a/dbms/src/Databases/DatabaseOnDisk.cpp b/dbms/src/Databases/DatabaseOnDisk.cpp index 9a281d5d745..f9acc47e5b0 100644 --- a/dbms/src/Databases/DatabaseOnDisk.cpp +++ b/dbms/src/Databases/DatabaseOnDisk.cpp @@ -126,7 +126,7 @@ ASTPtr parseCreateQueryFromMetadataFile(const String & filepath, Poco::Logger * std::pair createTableFromAST( ASTCreateQuery ast_create_query, const String & database_name, - const String & database_data_path, + const String & database_data_path_relative, Context & context, bool has_force_restore_data_flag) { @@ -149,12 +149,13 @@ std::pair createTableFromAST( ColumnsDescription columns = InterpreterCreateQuery::getColumnsDescription(*ast_create_query.columns_list->columns, context); ConstraintsDescription constraints = InterpreterCreateQuery::getConstraintsDescription(ast_create_query.columns_list->constraints); + String table_data_path_relative = database_data_path_relative + escapeForFileName(ast_create_query.table) + '/'; return { ast_create_query.table, StorageFactory::instance().get( ast_create_query, - database_data_path, ast_create_query.table, database_name, context, context.getGlobalContext(), + table_data_path_relative, ast_create_query.table, database_name, context, context.getGlobalContext(), columns, constraints, true, has_force_restore_data_flag) }; diff --git a/dbms/src/Databases/DatabaseOnDisk.h b/dbms/src/Databases/DatabaseOnDisk.h index 92a6f48959a..cc7c7ef3f1e 100644 --- a/dbms/src/Databases/DatabaseOnDisk.h +++ b/dbms/src/Databases/DatabaseOnDisk.h @@ -24,7 +24,7 @@ ASTPtr parseCreateQueryFromMetadataFile(const String & filepath, Poco::Logger * std::pair createTableFromAST( ASTCreateQuery ast_create_query, const String & database_name, - const String & database_data_path, + const String & database_data_path_relative, Context & context, bool has_force_restore_data_flag); diff --git a/dbms/src/Interpreters/loadMetadata.cpp b/dbms/src/Interpreters/loadMetadata.cpp index 00090d1d309..2a1563b7819 100644 --- a/dbms/src/Interpreters/loadMetadata.cpp +++ b/dbms/src/Interpreters/loadMetadata.cpp @@ -56,7 +56,7 @@ static void loadDatabase( bool force_restore_data) { /// There may exist .sql file with database creation statement. - /// Or, if it is absent, then database with default engine is created. + /// Or, if it is absent, then database with Ordinary engine is created. String database_attach_query; String database_metadata_file = database_path + ".sql"; @@ -67,7 +67,8 @@ static void loadDatabase( readStringUntilEOF(database_attach_query, in); } else - database_attach_query = "ATTACH DATABASE " + backQuoteIfNeed(database); + //FIXME + database_attach_query = "ATTACH DATABASE " + backQuoteIfNeed(database) + " ENGINE = Atomic"; executeCreateQuery(database_attach_query, context, database, database_metadata_file, force_restore_data); diff --git a/dbms/src/Storages/MergeTree/MergeTreeData.cpp b/dbms/src/Storages/MergeTree/MergeTreeData.cpp index 6c9fc5514b1..4d9a5762659 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeData.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeData.cpp @@ -1180,9 +1180,7 @@ void MergeTreeData::rename( const String & /*new_path_to_db*/, const String & new_database_name, const String & new_table_name, TableStructureWriteLockHolder &) { - auto old_file_db_name = escapeForFileName(database_name); auto new_file_db_name = escapeForFileName(new_database_name); - auto old_file_table_name = escapeForFileName(table_name); auto new_file_table_name = escapeForFileName(new_table_name); auto disks = storage_policy->getDisks(); @@ -1212,7 +1210,7 @@ void MergeTreeData::rename( database_name = new_database_name; table_name = new_table_name; - relative_data_path = "data/" + old_file_db_name + '/' + old_file_table_name + '/'; + relative_data_path = "data/" + new_file_db_name + '/' + new_file_table_name + '/'; } void MergeTreeData::dropAllData() diff --git a/dbms/src/Storages/tests/storage_log.cpp b/dbms/src/Storages/tests/storage_log.cpp index 02a845cf61c..f06988504f7 100644 --- a/dbms/src/Storages/tests/storage_log.cpp +++ b/dbms/src/Storages/tests/storage_log.cpp @@ -25,11 +25,12 @@ try names_and_types.emplace_back("a", std::make_shared()); names_and_types.emplace_back("b", std::make_shared()); - StoragePtr table = StorageLog::create("./", "test", "test", ColumnsDescription{names_and_types}, ConstraintsDescription{}, 1048576); - table->startup(); - auto context = Context::createGlobal(); context.makeGlobalContext(); + context.setPath("./"); + + StoragePtr table = StorageLog::create("./", "test", "test", ColumnsDescription{names_and_types}, ConstraintsDescription{}, 1048576, context); + table->startup(); /// write into it {