diff --git a/dbms/include/DB/Storages/MergeTree/MergeTreeData.h b/dbms/include/DB/Storages/MergeTree/MergeTreeData.h index 66a515d7a5e..343de9ee815 100644 --- a/dbms/include/DB/Storages/MergeTree/MergeTreeData.h +++ b/dbms/include/DB/Storages/MergeTree/MergeTreeData.h @@ -594,6 +594,10 @@ public: /// Если не был вызван commit(), удаляет временные файлы, отменяя ALTER куска. ~AlterDataPartTransaction(); + /// Посмотреть изменения перед коммитом. + const NamesAndTypesList & getNewColumns() const { return new_columns; } + const DataPart::Checksums & getNewChecksums() const { return new_checksums; } + private: friend class MergeTreeData; diff --git a/dbms/src/Storages/StorageReplicatedMergeTree.cpp b/dbms/src/Storages/StorageReplicatedMergeTree.cpp index 715aabf6011..3aa1b52b29b 100644 --- a/dbms/src/Storages/StorageReplicatedMergeTree.cpp +++ b/dbms/src/Storages/StorageReplicatedMergeTree.cpp @@ -1571,8 +1571,10 @@ void StorageReplicatedMergeTree::alterThread() /// Обновим метаданные куска в ZooKeeper. zkutil::Ops ops; - ops.push_back(new zkutil::Op::SetData(replica_path + "/parts/" + part->name + "/columns", part->columns.toString(), -1)); - ops.push_back(new zkutil::Op::SetData(replica_path + "/parts/" + part->name + "/checksums", part->checksums.toString(), -1)); + ops.push_back(new zkutil::Op::SetData( + replica_path + "/parts/" + part->name + "/columns", transaction->getNewColumns().toString(), -1)); + ops.push_back(new zkutil::Op::SetData( + replica_path + "/parts/" + part->name + "/checksums", transaction->getNewChecksums().toString(), -1)); zookeeper->multi(ops); /// Применим изменения файлов. diff --git a/dbms/tests/queries/0_stateless/00121_drop_column_zookeeper.reference b/dbms/tests/queries/0_stateless/00121_drop_column_zookeeper.reference new file mode 100644 index 00000000000..db5cdb698b3 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00121_drop_column_zookeeper.reference @@ -0,0 +1,13 @@ +columns format version: 1 +1 columns: +`d` Date + +2014-01-01 +2014-01-01 0 +2014-02-01 1 +2014-01-01 +2014-02-01 +columns format version: 1 +1 columns: +`d` Date + diff --git a/dbms/tests/queries/0_stateless/00121_drop_column_zookeeper.sql b/dbms/tests/queries/0_stateless/00121_drop_column_zookeeper.sql new file mode 100644 index 00000000000..867441cbae8 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00121_drop_column_zookeeper.sql @@ -0,0 +1,27 @@ +DROP TABLE IF EXISTS test.alter; +CREATE TABLE test.alter (d Date, x UInt8) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/alter', 'r1', d, (d), 8192); + +INSERT INTO test.alter VALUES ('2014-01-01', 1); +ALTER TABLE test.alter DROP COLUMN x; + +SELECT value FROM system.zookeeper WHERE path = '/clickhouse/tables/test/alter/replicas/r1/parts/20140101_20140101_200_200_0' AND name = 'columns' FORMAT TabSeparatedRaw; + +DROP TABLE test.alter; + + +CREATE TABLE test.alter (d Date) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test/alter', 'r1', d, (d), 8192); + +INSERT INTO test.alter VALUES ('2014-01-01'); +SELECT * FROM test.alter ORDER BY d; + +ALTER TABLE test.alter ADD COLUMN x UInt8; + +INSERT INTO test.alter VALUES ('2014-02-01', 1); +SELECT * FROM test.alter ORDER BY d; + +ALTER TABLE test.alter DROP COLUMN x; +SELECT * FROM test.alter ORDER BY d; + +SELECT value FROM system.zookeeper WHERE path = '/clickhouse/tables/test/alter/replicas/r1/parts/20140201_20140201_200_200_0' AND name = 'columns' FORMAT TabSeparatedRaw; + +DROP TABLE test.alter;