mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Add test stub
This commit is contained in:
parent
0a02fe913a
commit
8182482cbd
@ -1312,28 +1312,29 @@ MutableDataPartPtr StorageReplicatedMergeTree::attachPartHelperFoundValidPart(co
|
||||
MergeTreePartInfo part_iter;
|
||||
const Poco::DirectoryIterator dir_end;
|
||||
|
||||
const String detached_dir = "detached";
|
||||
|
||||
for (const String& path : getDataPaths())
|
||||
{
|
||||
for (Poco::DirectoryIterator dir_it{path + "detached/"}; dir_it != dir_end; ++dir_it)
|
||||
for (Poco::DirectoryIterator it{path + detached_dir}; it != dir_end; ++it)
|
||||
{
|
||||
if (!MergeTreePartInfo::tryParsePartName(dir_it.name(), &part_iter, format_version) || // this line is correct
|
||||
if (!MergeTreePartInfo::tryParsePartName(it.name(), &part_iter, format_version) || // this line is correct
|
||||
part_iter.partition_id != target_part.partition_id ||
|
||||
entry.new_part_name != part_iter.getPartName()) // TODO check if the last statement is valid,
|
||||
// Maybe we can't compare by names
|
||||
continue;
|
||||
|
||||
const String& part_name = part_iter.getPartName();
|
||||
const String part_dir = "detached/"; //TODO double-check
|
||||
const String part_to_path = part_dir + part_name;
|
||||
const String part_to_path = detached_dir + part_name;
|
||||
|
||||
auto single_disk_volume = std::make_shared<SingleDiskVolume>("volume_" + part_name,
|
||||
getDiskForPart(part_name, part_dir));
|
||||
getDiskForPart(part_name, detached_dir));
|
||||
|
||||
//createPart uses part name as arg 1, "detached/" as arg 2 so maybe we need "detached/" too
|
||||
MutableDataPartPtr iter_part_ptr = createPart(part_name, single_disk_volume, part_to_path);
|
||||
|
||||
if (part_checksum != iter_part_ptr->checksums.getTotalChecksumHex())
|
||||
/// the part with same partition id has different checksum, so it is corrupt.
|
||||
/// the part with same name and partition id has different checksum, so it is corrupt.
|
||||
return {};
|
||||
|
||||
return iter_part_ptr;
|
||||
|
46
tests/integration/test_attach_without_fetching/test.py
Normal file
46
tests/integration/test_attach_without_fetching/test.py
Normal file
@ -0,0 +1,46 @@
|
||||
import pytest
|
||||
from helpers.cluster import ClickHouseCluster
|
||||
|
||||
cluster = ClickHouseCluster(__file__)
|
||||
|
||||
node1 = cluster.add_instance('node1')
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def start_cluster():
|
||||
try:
|
||||
cluster.start()
|
||||
|
||||
yield cluster
|
||||
finally:
|
||||
cluster.shutdown()
|
||||
|
||||
|
||||
# Check that ALTER TABLE ATTACH PARTITION does not fetch data from other replicas if it's present in the
|
||||
# detached/ folder
|
||||
def test_attach_without_fetching(start_cluster):
|
||||
node1.query(
|
||||
"CREATE TABLE test (date Date, key Int32, value String) Engine=MergeTree ORDER BY key PARTITION by date")
|
||||
|
||||
node1.query("INSERT INTO test SELECT toDate('2019-10-01'), number, toString(number) FROM numbers(100)")
|
||||
|
||||
assert node1.query("SELECT COUNT() FROM test WHERE key % 10 == 0") == "10\n"
|
||||
|
||||
node1.query("ALTER TABLE test DETACH PARTITION '2019-10-01'")
|
||||
|
||||
assert node1.query("SELECT COUNT() FROM test WHERE key % 10 == 0") == "0\n"
|
||||
assert node1.query("SELECT COUNT() FROM test") == "0\n"
|
||||
|
||||
# to be sure output not empty
|
||||
node1.exec_in_container(
|
||||
['bash', '-c', 'find /var/lib/clickhouse/data/default/test/detached -name "checksums.txt" | grep -e ".*" '],
|
||||
privileged=True, user='root')
|
||||
|
||||
node1.exec_in_container(
|
||||
['bash', '-c', 'find /var/lib/clickhouse/data/default/test/detached -name "checksums.txt" -delete'],
|
||||
privileged=True, user='root')
|
||||
|
||||
node1.query("ALTER TABLE test ATTACH PARTITION '2019-10-01'")
|
||||
|
||||
assert node1.query("SELECT COUNT() FROM test WHERE key % 10 == 0") == "10\n"
|
||||
assert node1.query("SELECT COUNT() FROM test") == "100\n"
|
Loading…
Reference in New Issue
Block a user