diff --git a/dbms/src/Common/localBackup.cpp b/dbms/src/Common/localBackup.cpp index d7a0786e320..2e042351a90 100644 --- a/dbms/src/Common/localBackup.cpp +++ b/dbms/src/Common/localBackup.cpp @@ -1,7 +1,9 @@ -#include +#include "localBackup.h" + #include #include #include +#include #include #include #include diff --git a/dbms/src/Common/localBackup.h b/dbms/src/Common/localBackup.h index 604c323ba48..e3ea32614ee 100644 --- a/dbms/src/Common/localBackup.h +++ b/dbms/src/Common/localBackup.h @@ -1,8 +1,8 @@ #pragma once -#include #include +namespace Poco { class Path; } namespace DB { diff --git a/dbms/src/Storages/MergeTree/MergeTreeData.cpp b/dbms/src/Storages/MergeTree/MergeTreeData.cpp index d9313ac8442..07b95dbb91a 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeData.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeData.cpp @@ -2829,6 +2829,7 @@ void MergeTreeData::freezePartitionsByMatcher(MatcherFn matcher, const String & String backup_part_absolute_path = part_absolute_path; backup_part_absolute_path.replace(0, clickhouse_path.size(), backup_path); localBackup(part_absolute_path, backup_part_absolute_path); + part->is_frozen = true; ++parts_processed; } diff --git a/dbms/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp b/dbms/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp index a510a087d1d..9ec234de4e4 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp @@ -1,4 +1,5 @@ -#include +#include "MergeTreeDataMergerMutator.h" + #include #include #include @@ -25,12 +26,9 @@ #include #include #include -#include #include - #include #include - #include #include #include diff --git a/dbms/src/Storages/MergeTree/MergeTreeDataPart.cpp b/dbms/src/Storages/MergeTree/MergeTreeDataPart.cpp index b0979795650..0b3062b077e 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeDataPart.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeDataPart.cpp @@ -1,5 +1,6 @@ -#include +#include "MergeTreeDataPart.h" +#include #include #include #include @@ -14,13 +15,10 @@ #include #include #include -#include #include - #include #include #include - #include #include @@ -728,7 +726,8 @@ void MergeTreeDataPart::accumulateColumnSizes(ColumnToSize & column_to_size) con void MergeTreeDataPart::loadColumns(bool require) { String path = getFullPath() + "columns.txt"; - if (!Poco::File(path).exists()) + Poco::File poco_file_path{path}; + if (!poco_file_path.exists()) { if (require) throw Exception("No columns.txt in part " + name, ErrorCodes::NO_FILE_IN_DATA_PART); @@ -750,6 +749,8 @@ void MergeTreeDataPart::loadColumns(bool require) return; } + is_frozen = !poco_file_path.canWrite(); + ReadBufferFromFile file = openForReading(path); columns.readText(file); } diff --git a/dbms/src/Storages/MergeTree/MergeTreeDataPart.h b/dbms/src/Storages/MergeTree/MergeTreeDataPart.h index 93b8117bd90..8ca5907c487 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeDataPart.h +++ b/dbms/src/Storages/MergeTree/MergeTreeDataPart.h @@ -106,6 +106,9 @@ struct MergeTreeDataPart /// If true it means that there are no ZooKeeper node for this part, so it should be deleted only from filesystem bool is_duplicate = false; + /// Frozen by ALTER TABLE ... FREEZE ... + mutable bool is_frozen = false; + /** * Part state is a stage of its lifetime. States are ordered and state of a part could be increased only. * Part state should be modified under data_parts mutex. diff --git a/dbms/src/Storages/StorageMergeTree.cpp b/dbms/src/Storages/StorageMergeTree.cpp index 8feb2d1fe81..575aee9b497 100644 --- a/dbms/src/Storages/StorageMergeTree.cpp +++ b/dbms/src/Storages/StorageMergeTree.cpp @@ -1,30 +1,24 @@ -#include +#include "StorageMergeTree.h" +#include #include #include #include #include -#include - #include #include - #include #include #include - #include #include #include #include -#include #include #include #include - #include #include - #include diff --git a/dbms/src/Storages/System/StorageSystemParts.cpp b/dbms/src/Storages/System/StorageSystemParts.cpp index 491e6157fdf..0240baf9604 100644 --- a/dbms/src/Storages/System/StorageSystemParts.cpp +++ b/dbms/src/Storages/System/StorageSystemParts.cpp @@ -1,3 +1,5 @@ +#include "StorageSystemParts.h" + #include #include #include @@ -5,7 +7,6 @@ #include #include #include -#include #include #include @@ -38,6 +39,7 @@ StorageSystemParts::StorageSystemParts(const std::string & name) {"data_version", std::make_shared()}, {"primary_key_bytes_in_memory", std::make_shared()}, {"primary_key_bytes_in_memory_allocated", std::make_shared()}, + {"is_frozen", std::make_shared()}, {"database", std::make_shared()}, {"table", std::make_shared()}, @@ -96,6 +98,7 @@ void StorageSystemParts::processNextStorage(MutableColumns & columns, const Stor columns[i++]->insert(static_cast(part->info.getDataVersion())); columns[i++]->insert(part->getIndexSizeInBytes()); columns[i++]->insert(part->getIndexSizeInAllocatedBytes()); + columns[i++]->insert(part->is_frozen); columns[i++]->insert(info.database); columns[i++]->insert(info.table); diff --git a/dbms/src/Storages/System/StorageSystemPartsColumns.cpp b/dbms/src/Storages/System/StorageSystemPartsColumns.cpp index 2a206dbcd0a..5d20e5797f4 100644 --- a/dbms/src/Storages/System/StorageSystemPartsColumns.cpp +++ b/dbms/src/Storages/System/StorageSystemPartsColumns.cpp @@ -1,3 +1,5 @@ +#include "StorageSystemPartsColumns.h" + #include #include #include @@ -5,7 +7,6 @@ #include #include #include -#include #include #include #include diff --git a/dbms/src/Storages/tests/transform_part_zk_nodes.cpp b/dbms/src/Storages/tests/transform_part_zk_nodes.cpp index 237f7681455..2a03e9b9746 100644 --- a/dbms/src/Storages/tests/transform_part_zk_nodes.cpp +++ b/dbms/src/Storages/tests/transform_part_zk_nodes.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include diff --git a/dbms/tests/queries/0_stateless/00428_partition.reference b/dbms/tests/queries/0_stateless/00428_partition.reference index 241048131f7..07ae09cf47d 100644 --- a/dbms/tests/queries/0_stateless/00428_partition.reference +++ b/dbms/tests/queries/0_stateless/00428_partition.reference @@ -15,7 +15,6 @@ 88cdc31ded355e7572d68d8cde525d3a shadow/1/data/test/partition_428/19700201_19700201_1_1_0/p.bin 9e688c58a5487b8eaf69c9e1005ad0bf shadow/1/data/test/partition_428/19700102_19700102_2_2_0/primary.idx b01e3d4df40467db3f1c2d029f59f6a2 shadow/1/data/test/partition_428/19700201_19700201_1_1_0/checksums.txt -b026324c6904b2a9cb4b88d6d61c81d1 shadow/increment.txt cfcb770c3ecd0990dcceb1bde129e6c6 shadow/1/data/test/partition_428/19700102_19700102_2_2_0/p.bin e2af3bef1fd129aea73a890ede1e7a30 shadow/1/data/test/partition_428/19700201_19700201_1_1_0/k.bin e6654eba9e88b001280d3bdd21ccc417 shadow/1/data/test/partition_428/19700102_19700102_2_2_0/checksums.txt @@ -36,7 +35,6 @@ e6654eba9e88b001280d3bdd21ccc417 shadow/1/data/test/partition_428/19700102_1970 88cdc31ded355e7572d68d8cde525d3a shadow/1/data/test/partition_428/19700201_19700201_1_1_0/p.bin 9e688c58a5487b8eaf69c9e1005ad0bf shadow/1/data/test/partition_428/19700102_19700102_2_2_0/primary.idx b01e3d4df40467db3f1c2d029f59f6a2 shadow/1/data/test/partition_428/19700201_19700201_1_1_0/checksums.txt -b026324c6904b2a9cb4b88d6d61c81d1 shadow/increment.txt cfcb770c3ecd0990dcceb1bde129e6c6 shadow/1/data/test/partition_428/19700102_19700102_2_2_0/p.bin e2af3bef1fd129aea73a890ede1e7a30 shadow/1/data/test/partition_428/19700201_19700201_1_1_0/k.bin e6654eba9e88b001280d3bdd21ccc417 shadow/1/data/test/partition_428/19700102_19700102_2_2_0/checksums.txt diff --git a/dbms/tests/queries/0_stateless/00428_partition.sh b/dbms/tests/queries/0_stateless/00428_partition.sh index 27cb94c1d4d..b45e978d755 100755 --- a/dbms/tests/queries/0_stateless/00428_partition.sh +++ b/dbms/tests/queries/0_stateless/00428_partition.sh @@ -26,7 +26,8 @@ done $chl "ALTER TABLE test.partition_428 FREEZE" # Do `cd` for consistent output for reference -cd $ch_dir && find shadow -type f -exec md5sum {} \; | sort +# Do not check increment.txt - it can be changed by other tests with FREEZE +cd $ch_dir && find shadow -type f -exec md5sum {} \; | grep "partition_428" | sed 's!shadow/[0-9]*/data/[a-z0-9_-]*/!shadow/1/data/test/!g' | sort | uniq $chl "ALTER TABLE test.partition_428 DETACH PARTITION 197001" $chl "ALTER TABLE test.partition_428 ATTACH PARTITION 197001" @@ -40,7 +41,7 @@ done $chl "ALTER TABLE test.partition_428 MODIFY COLUMN v1 Int8" # Check the backup hasn't changed -cd $ch_dir && find shadow -type f -exec md5sum {} \; | sort +cd $ch_dir && find shadow -type f -exec md5sum {} \; | grep "partition_428" | sed 's!shadow/[0-9]*/data/[a-z0-9_-]*/!shadow/1/data/test/!g' | sort | uniq $chl "OPTIMIZE TABLE test.partition_428" diff --git a/dbms/tests/queries/0_stateless/00952_part_frozen_info.reference b/dbms/tests/queries/0_stateless/00952_part_frozen_info.reference new file mode 100644 index 00000000000..99b7e2d3fbf --- /dev/null +++ b/dbms/tests/queries/0_stateless/00952_part_frozen_info.reference @@ -0,0 +1,19 @@ +19701001_1_1_0 0 +19701002_2_2_0 0 +19701003_3_3_0 0 +freeze one +19701001_1_1_0 0 +19701002_2_2_0 1 +19701003_3_3_0 0 +freeze all +19701001_1_1_0 1 +19701002_2_2_0 1 +19701003_3_3_0 1 +1970-10-01 00:00:01 +1970-10-02 00:00:01 +1970-10-02 00:00:02 +1970-10-03 00:00:01 +19701001_1_1_0 1 +19701002_2_2_0 1 +19701002_4_4_0 0 +19701003_3_3_0 1 diff --git a/dbms/tests/queries/0_stateless/00952_part_frozen_info.sql b/dbms/tests/queries/0_stateless/00952_part_frozen_info.sql new file mode 100644 index 00000000000..52fc95a9fba --- /dev/null +++ b/dbms/tests/queries/0_stateless/00952_part_frozen_info.sql @@ -0,0 +1,14 @@ +DROP TABLE IF EXISTS part_info; +CREATE TABLE part_info (t DateTime) ENGINE = MergeTree PARTITION BY toDate(t) ORDER BY (t); +INSERT INTO part_info VALUES (toDateTime('1970-10-01 00:00:01')), (toDateTime('1970-10-02 00:00:01')), (toDateTime('1970-10-03 00:00:01')); +SELECT name, is_frozen FROM system.parts WHERE `database` = currentDatabase() AND `table` = 'part_info'; +SELECT 'freeze one'; +ALTER TABLE part_info FREEZE PARTITION toDate('1970-10-02'); +SELECT name, is_frozen FROM system.parts WHERE `database` = currentDatabase() AND `table` = 'part_info'; +SELECT 'freeze all'; +ALTER TABLE part_info FREEZE; +SELECT name, is_frozen FROM system.parts WHERE `database` = currentDatabase() AND `table` = 'part_info'; +INSERT INTO part_info VALUES (toDateTime('1970-10-02 00:00:02')); +select * from part_info order by t; +SELECT name, is_frozen FROM system.parts WHERE `database` = currentDatabase() AND `table` = 'part_info'; +DROP TABLE part_info;