mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-02 20:42:04 +00:00
refine codes and fix test cases
This commit is contained in:
parent
cbe7b4e21b
commit
eecccac2de
15
src/Storages/StorageMergeTree.cpp
Normal file → Executable file
15
src/Storages/StorageMergeTree.cpp
Normal file → Executable file
@ -781,17 +781,8 @@ std::shared_ptr<MergeMutateSelectedEntry> StorageMergeTree::selectOnePartitionTo
|
||||
if (part->modification_time < base)
|
||||
partition_parts_sum_diff[part->info.partition_id] += (base - part->modification_time);
|
||||
}
|
||||
String best_partition_id;
|
||||
Int32 max_diff = 0;
|
||||
for (auto [partition_id, diff] : partition_parts_sum_diff)
|
||||
{
|
||||
if (diff > max_diff)
|
||||
{
|
||||
best_partition_id = partition_id;
|
||||
max_diff = diff;
|
||||
}
|
||||
}
|
||||
if (best_partition_id.empty())
|
||||
auto best_partition_it = std::max_element(partition_parts_sum_diff.begin(), partition_parts_sum_diff.end(), [](const auto & e1, const auto & e2) { return e1.second < e2.second; });
|
||||
if (best_partition_it == partition_parts_sum_diff.end())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
@ -801,7 +792,7 @@ std::shared_ptr<MergeMutateSelectedEntry> StorageMergeTree::selectOnePartitionTo
|
||||
auto merge_entry = selectPartsToMerge(
|
||||
metadata_snapshot,
|
||||
true,
|
||||
best_partition_id,
|
||||
best_partition_it->first,
|
||||
true,
|
||||
&disable_reason,
|
||||
table_lock_holder,
|
||||
|
@ -21,6 +21,20 @@ def start_cluster():
|
||||
finally:
|
||||
cluster.shutdown()
|
||||
|
||||
def check_expected_result_or_fail(seconds, expected):
|
||||
ok = False
|
||||
for i in range(int(seconds) * 2):
|
||||
result = TSV(
|
||||
node.query(
|
||||
"SELECT count(*) FROM system.parts where table='test' and active=1"
|
||||
)
|
||||
)
|
||||
if result == expected:
|
||||
ok = True
|
||||
break
|
||||
else:
|
||||
time.sleep(0.5)
|
||||
assert(ok)
|
||||
|
||||
def test_without_auto_optimize_merge_tree(start_cluster):
|
||||
node.query("CREATE TABLE test (i Int64) ENGINE = MergeTree ORDER BY i;")
|
||||
@ -28,17 +42,9 @@ def test_without_auto_optimize_merge_tree(start_cluster):
|
||||
node.query("INSERT INTO test SELECT 2")
|
||||
node.query("INSERT INTO test SELECT 3")
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
expected = TSV("""3\n""")
|
||||
assert (
|
||||
TSV(
|
||||
node.query(
|
||||
"SELECT count(*) FROM system.parts where table='test' and active=1"
|
||||
)
|
||||
)
|
||||
== expected
|
||||
)
|
||||
check_expected_result_or_fail(5, expected)
|
||||
|
||||
node.query("DROP TABLE test;")
|
||||
|
||||
@ -51,17 +57,8 @@ def test_auto_optimize_merge_tree(start_cluster):
|
||||
node.query("INSERT INTO test SELECT 2")
|
||||
node.query("INSERT INTO test SELECT 3")
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
expected = TSV("""1\n""")
|
||||
assert (
|
||||
TSV(
|
||||
node.query(
|
||||
"SELECT count(*) FROM system.parts where table='test' and active=1"
|
||||
)
|
||||
)
|
||||
== expected
|
||||
)
|
||||
check_expected_result_or_fail(10, expected)
|
||||
|
||||
node.query("DROP TABLE test;")
|
||||
|
||||
@ -74,16 +71,7 @@ def test_auto_optimize_replicated_merge_tree(start_cluster):
|
||||
node.query("INSERT INTO test SELECT 2")
|
||||
node.query("INSERT INTO test SELECT 3")
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
expected = TSV("""1\n""")
|
||||
assert (
|
||||
TSV(
|
||||
node.query(
|
||||
"SELECT count(*) FROM system.parts where table='test' and active=1"
|
||||
)
|
||||
)
|
||||
== expected
|
||||
)
|
||||
check_expected_result_or_fail(10, expected)
|
||||
|
||||
node.query("DROP TABLE test;")
|
||||
|
Loading…
Reference in New Issue
Block a user