From 99041b3173619c775cc7ea0ecb87e3f7c403c8ee Mon Sep 17 00:00:00 2001 From: Michael Kolupaev Date: Fri, 25 Oct 2013 12:15:12 +0000 Subject: [PATCH] Merge --- .../MergeTree/MergeTreeBlockOutputStream.h | 2 +- dbms/src/Storages/StorageMergeTree.cpp | 7 +++++ .../Storages/tests/broken_increment_test.sh | 30 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 dbms/src/Storages/tests/broken_increment_test.sh diff --git a/dbms/include/DB/Storages/MergeTree/MergeTreeBlockOutputStream.h b/dbms/include/DB/Storages/MergeTree/MergeTreeBlockOutputStream.h index f301c0ade2a..9905a8dd852 100644 --- a/dbms/include/DB/Storages/MergeTree/MergeTreeBlockOutputStream.h +++ b/dbms/include/DB/Storages/MergeTree/MergeTreeBlockOutputStream.h @@ -103,7 +103,7 @@ private: size_t rows = block.rows(); size_t columns = block.columns(); - UInt64 part_id = storage.increment.get(true); + UInt64 part_id = storage.increment.get(false); String part_name = storage.getPartName( DayNum_t(min_date), DayNum_t(max_date), diff --git a/dbms/src/Storages/StorageMergeTree.cpp b/dbms/src/Storages/StorageMergeTree.cpp index 7bcf628f6ae..4b18bcec96c 100644 --- a/dbms/src/Storages/StorageMergeTree.cpp +++ b/dbms/src/Storages/StorageMergeTree.cpp @@ -99,6 +99,13 @@ StorageMergeTree::StorageMergeTree( merge_threads = new boost::threadpool::pool(settings.merging_threads); loadDataParts(); + + UInt64 max_part_id = 0; + for (DataParts::iterator it = data_parts.begin(); it != data_parts.end(); ++it) + { + max_part_id = std::max(max_part_id, (*it)->right); + } + increment.fixIfBroken(max_part_id); } StoragePtr StorageMergeTree::create( diff --git a/dbms/src/Storages/tests/broken_increment_test.sh b/dbms/src/Storages/tests/broken_increment_test.sh new file mode 100755 index 00000000000..5e8b03de42e --- /dev/null +++ b/dbms/src/Storages/tests/broken_increment_test.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# См. таску METR-9006 +# Удалим increment.txt из StorageMergeTree таблицы и попробуем сделать INSERT в нее. Перезапустим сервер и попробуем сделать INSERT снова. + +echo 'Droping database' +echo 'DROP DATABASE IF EXISTS increment' | clickhouse-client || exit 1 +echo 'Creating database' +echo 'CREATE DATABASE increment' | clickhouse-client || exit 2 +echo 'Creating table' +echo 'CREATE TABLE increment.a (d Date, v UInt64) ENGINE=MergeTree(d, tuple(v), 8192)' | clickhouse-client || exit 3 +echo 'Inserting' +echo "2014-01-01 42" | clickhouse-client --query="INSERT INTO increment.a FORMAT TabSeparated" || exit 4 +ls /opt/clickhouse/data/increment/a/ +cat /opt/clickhouse/data/increment/a/increment.txt +rm /opt/clickhouse/data/increment/a/increment.txt +echo 'Inserting without increment.txt' +echo "2014-01-01 41" | clickhouse-client --query="INSERT INTO increment.a FORMAT TabSeparated" +ls /opt/clickhouse/data/increment/a/ +cat /opt/clickhouse/data/increment/a/increment.txt +sudo /etc/init.d/clickhouse-server-metrika-yandex stop +sudo /etc/init.d/clickhouse-server-metrika-yandex start +sleep 10s +ls /opt/clickhouse/data/increment/a/ +cat /opt/clickhouse/data/increment/a/increment.txt +echo 'Inserting after restart without increment.txt' +echo "2014-01-01 43" | clickhouse-client --query="INSERT INTO increment.a FORMAT TabSeparated" +ls /opt/clickhouse/data/increment/a/ +cat /opt/clickhouse/data/increment/a/increment.txt +echo "SELECT * FROM increment.a" | clickhouse-client