diff --git a/dbms/src/Storages/MergeTree/MergeTreeData.cpp b/dbms/src/Storages/MergeTree/MergeTreeData.cpp index af985c02927..8c8e76c3e7e 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeData.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeData.cpp @@ -99,6 +99,7 @@ namespace ErrorCodes MergeTreeData::MergeTreeData( const String & database_, const String & table_, + const String & relative_data_path_, const ColumnsDescription & columns_, const IndicesDescription & indices_, const ConstraintsDescription & constraints_, @@ -122,6 +123,7 @@ MergeTreeData::MergeTreeData( , require_part_metadata(require_part_metadata_) , database_name(database_) , table_name(table_) + , relative_data_path(relative_data_path_) , broken_part_callback(broken_part_callback_) , log_name(database_name + "." + table_name) , log(&Logger::get(log_name)) @@ -1195,7 +1197,7 @@ void MergeTreeData::rename( for (const auto & disk : disks) { - auto full_path = disk->getClickHouseDataPath() + old_file_db_name + '/' + old_file_table_name + '/'; + auto full_path = disk->getPath() + relative_data_path; auto new_db_path = disk->getClickHouseDataPath() + new_file_db_name + '/'; Poco::File db_file{new_db_path}; @@ -1210,6 +1212,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 + '/'; } void MergeTreeData::dropAllData() @@ -3250,7 +3253,7 @@ MergeTreeData::MutableDataPartPtr MergeTreeData::cloneAndLoadDataPart(const Merg String MergeTreeData::getFullPathOnDisk(const DiskSpace::DiskPtr & disk) const { - return disk->getClickHouseDataPath() + escapeForFileName(database_name) + '/' + escapeForFileName(table_name) + '/'; + return disk->getPath() + relative_data_path; } diff --git a/dbms/src/Storages/MergeTree/MergeTreeData.h b/dbms/src/Storages/MergeTree/MergeTreeData.h index a8bd661fafa..dd33cd472ac 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeData.h +++ b/dbms/src/Storages/MergeTree/MergeTreeData.h @@ -332,6 +332,7 @@ public: /// require_part_metadata - should checksums.txt and columns.txt exist in the part directory. /// attach - whether the existing table is attached or the new table is created. MergeTreeData(const String & database_, const String & table_, + const String & relative_data_path_, const ColumnsDescription & columns_, const IndicesDescription & indices_, const ConstraintsDescription & constraints_, @@ -760,6 +761,7 @@ protected: String database_name; String table_name; + String relative_data_path; /// Current column sizes in compressed and uncompressed form. diff --git a/dbms/src/Storages/MergeTree/registerStorageMergeTree.cpp b/dbms/src/Storages/MergeTree/registerStorageMergeTree.cpp index 5458f3f7d9b..633699d1529 100644 --- a/dbms/src/Storages/MergeTree/registerStorageMergeTree.cpp +++ b/dbms/src/Storages/MergeTree/registerStorageMergeTree.cpp @@ -639,14 +639,14 @@ static StoragePtr create(const StorageFactory::Arguments & args) if (replicated) return StorageReplicatedMergeTree::create( - zookeeper_path, replica_name, args.attach, args.database_name, args.table_name, + zookeeper_path, replica_name, args.attach, args.database_name, args.table_name, args.relative_data_path, args.columns, indices_description, args.constraints, args.context, date_column_name, partition_by_ast, order_by_ast, primary_key_ast, sample_by_ast, ttl_table_ast, merging_params, std::move(storage_settings), args.has_force_restore_data_flag); else return StorageMergeTree::create( - args.database_name, args.table_name, args.columns, indices_description, + args.database_name, args.table_name, args.relative_data_path, args.columns, indices_description, args.constraints, args.attach, args.context, date_column_name, partition_by_ast, order_by_ast, primary_key_ast, sample_by_ast, ttl_table_ast, merging_params, std::move(storage_settings), args.has_force_restore_data_flag); diff --git a/dbms/src/Storages/StorageMergeTree.cpp b/dbms/src/Storages/StorageMergeTree.cpp index c752109e328..0a6f162f625 100644 --- a/dbms/src/Storages/StorageMergeTree.cpp +++ b/dbms/src/Storages/StorageMergeTree.cpp @@ -54,6 +54,7 @@ namespace ActionLocks StorageMergeTree::StorageMergeTree( const String & database_name_, const String & table_name_, + const String & relative_data_path_, const ColumnsDescription & columns_, const IndicesDescription & indices_, const ConstraintsDescription & constraints_, @@ -68,7 +69,7 @@ StorageMergeTree::StorageMergeTree( const MergingParams & merging_params_, std::unique_ptr storage_settings_, bool has_force_restore_data_flag) - : MergeTreeData(database_name_, table_name_, + : MergeTreeData(database_name_, table_name_, relative_data_path_, columns_, indices_, constraints_, context_, date_column_name, partition_by_ast_, order_by_ast_, primary_key_ast_, sample_by_ast_, ttl_table_ast_, merging_params_, diff --git a/dbms/src/Storages/StorageMergeTree.h b/dbms/src/Storages/StorageMergeTree.h index 15080cfcbf8..6b84e1bea4e 100644 --- a/dbms/src/Storages/StorageMergeTree.h +++ b/dbms/src/Storages/StorageMergeTree.h @@ -147,6 +147,7 @@ protected: StorageMergeTree( const String & database_name_, const String & table_name_, + const String & relative_data_path_, const ColumnsDescription & columns_, const IndicesDescription & indices_, const ConstraintsDescription & constraints_, diff --git a/dbms/src/Storages/StorageReplicatedMergeTree.cpp b/dbms/src/Storages/StorageReplicatedMergeTree.cpp index c55378d8526..ff85cecad61 100644 --- a/dbms/src/Storages/StorageReplicatedMergeTree.cpp +++ b/dbms/src/Storages/StorageReplicatedMergeTree.cpp @@ -192,6 +192,7 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree( bool attach, const String & database_name_, const String & table_name_, + const String & relative_data_path_, const ColumnsDescription & columns_, const IndicesDescription & indices_, const ConstraintsDescription & constraints_, @@ -205,7 +206,7 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree( const MergingParams & merging_params_, std::unique_ptr settings_, bool has_force_restore_data_flag) - : MergeTreeData(database_name_, table_name_, + : MergeTreeData(database_name_, table_name_, relative_data_path_, columns_, indices_, constraints_, context_, date_column_name, partition_by_ast_, order_by_ast_, primary_key_ast_, sample_by_ast_, ttl_table_ast_, merging_params_, diff --git a/dbms/src/Storages/StorageReplicatedMergeTree.h b/dbms/src/Storages/StorageReplicatedMergeTree.h index facdb1660f0..f5e384f058d 100644 --- a/dbms/src/Storages/StorageReplicatedMergeTree.h +++ b/dbms/src/Storages/StorageReplicatedMergeTree.h @@ -531,6 +531,7 @@ protected: const String & replica_name_, bool attach, const String & database_name_, const String & name_, + const String & relative_data_path_, const ColumnsDescription & columns_, const IndicesDescription & indices_, const ConstraintsDescription & constraints_,