2020-01-20 17:54:52 +00:00
|
|
|
# pylint: disable=unused-argument
|
|
|
|
# pylint: disable=redefined-outer-name
|
|
|
|
# pylint: disable=line-too-long
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
|
|
|
|
node = cluster.add_instance('node',
|
2020-09-16 04:26:10 +00:00
|
|
|
main_configs=["configs/config.d/storage_configuration.xml"],
|
|
|
|
tmpfs=['/disk1:size=100M', '/disk2:size=100M'])
|
|
|
|
|
2020-01-20 17:54:52 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
2020-09-22 11:56:40 +00:00
|
|
|
node.query('CREATE DATABASE test ENGINE=Ordinary') # Different paths with Atomic
|
2020-01-20 17:54:52 +00:00
|
|
|
yield cluster
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2020-01-20 17:54:52 +00:00
|
|
|
def _files_in_dist_mon(node, root, table):
|
|
|
|
return int(node.exec_in_container([
|
|
|
|
'bash',
|
|
|
|
'-c',
|
|
|
|
# `-maxdepth 1` to avoid /tmp/ subdirectory
|
2020-09-16 04:26:10 +00:00
|
|
|
'find /{root}/data/test/{table}/default@127%2E0%2E0%2E2:9000 -maxdepth 1 -type f 2>/dev/null | wc -l'.format(
|
|
|
|
root=root, table=table)
|
2020-01-20 17:54:52 +00:00
|
|
|
]).split('\n')[0])
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2020-07-16 20:35:23 +00:00
|
|
|
def test_insert(start_cluster):
|
2020-01-28 19:39:52 +00:00
|
|
|
node.query('CREATE TABLE test.foo (key Int) Engine=Memory()')
|
2020-01-20 17:54:52 +00:00
|
|
|
node.query("""
|
2020-01-28 19:39:52 +00:00
|
|
|
CREATE TABLE test.dist_foo (key Int)
|
2020-01-20 17:54:52 +00:00
|
|
|
Engine=Distributed(
|
|
|
|
test_cluster_two_shards,
|
2020-01-28 19:39:52 +00:00
|
|
|
test,
|
2020-01-20 17:54:52 +00:00
|
|
|
foo,
|
|
|
|
key%2,
|
|
|
|
'default'
|
|
|
|
)
|
|
|
|
""")
|
2020-04-26 10:34:20 +00:00
|
|
|
# manual only (but only for remote node)
|
2020-01-28 19:39:52 +00:00
|
|
|
node.query('SYSTEM STOP DISTRIBUTED SENDS test.dist_foo')
|
2020-01-20 17:54:52 +00:00
|
|
|
|
2020-11-06 05:34:37 +00:00
|
|
|
node.query('INSERT INTO test.dist_foo SELECT * FROM numbers(100)', settings={
|
|
|
|
'use_compact_format_in_distributed_parts_names': '0',
|
|
|
|
})
|
2020-01-20 17:54:52 +00:00
|
|
|
assert _files_in_dist_mon(node, 'disk1', 'dist_foo') == 1
|
|
|
|
assert _files_in_dist_mon(node, 'disk2', 'dist_foo') == 0
|
|
|
|
|
2020-01-28 19:39:52 +00:00
|
|
|
assert node.query('SELECT count() FROM test.dist_foo') == '100\n'
|
|
|
|
node.query('SYSTEM FLUSH DISTRIBUTED test.dist_foo')
|
|
|
|
assert node.query('SELECT count() FROM test.dist_foo') == '200\n'
|
2020-01-20 17:54:52 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# RENAME
|
|
|
|
#
|
2020-01-28 19:39:52 +00:00
|
|
|
node.query('RENAME TABLE test.dist_foo TO test.dist2_foo')
|
2020-01-20 17:54:52 +00:00
|
|
|
|
2020-11-06 05:34:37 +00:00
|
|
|
node.query('INSERT INTO test.dist2_foo SELECT * FROM numbers(100)', settings={
|
|
|
|
'use_compact_format_in_distributed_parts_names': '0',
|
|
|
|
})
|
2020-01-20 17:54:52 +00:00
|
|
|
assert _files_in_dist_mon(node, 'disk1', 'dist2_foo') == 0
|
|
|
|
assert _files_in_dist_mon(node, 'disk2', 'dist2_foo') == 1
|
|
|
|
|
2020-01-28 19:39:52 +00:00
|
|
|
assert node.query('SELECT count() FROM test.dist2_foo') == '300\n'
|
|
|
|
node.query('SYSTEM FLUSH DISTRIBUTED test.dist2_foo')
|
|
|
|
assert node.query('SELECT count() FROM test.dist2_foo') == '400\n'
|
2020-07-16 20:35:23 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# DROP
|
|
|
|
#
|
|
|
|
node.query('DROP TABLE test.dist2_foo')
|
|
|
|
for disk in ['disk1', 'disk2']:
|
|
|
|
node.exec_in_container([
|
|
|
|
'bash', '-c',
|
|
|
|
'test ! -e /{}/data/test/dist2_foo'.format(disk)
|
|
|
|
])
|