Merge pull request #4684 from amosbird/fixempty2

Refinement
This commit is contained in:
alexey-milovidov 2019-03-14 06:12:39 +03:00 committed by GitHub
commit bdc7614c77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

View File

@ -3014,7 +3014,7 @@ bool StorageReplicatedMergeTree::optimize(const ASTPtr & query, const ASTPtr & p
return true; return true;
} }
ReplicatedMergeTreeLogEntryData merge_entry; std::vector<ReplicatedMergeTreeLogEntryData> merge_entries;
{ {
/// We must select parts for merge under merge_selecting_mutex because other threads /// We must select parts for merge under merge_selecting_mutex because other threads
/// (merge_selecting_thread or OPTIMIZE queries) could assign new merges. /// (merge_selecting_thread or OPTIMIZE queries) could assign new merges.
@ -3045,9 +3045,12 @@ bool StorageReplicatedMergeTree::optimize(const ASTPtr & query, const ASTPtr & p
FutureMergedMutatedPart future_merged_part; FutureMergedMutatedPart future_merged_part;
bool selected = merger_mutator.selectAllPartsToMergeWithinPartition( bool selected = merger_mutator.selectAllPartsToMergeWithinPartition(
future_merged_part, disk_space, can_merge, partition_id, true, nullptr); future_merged_part, disk_space, can_merge, partition_id, true, nullptr);
ReplicatedMergeTreeLogEntryData merge_entry;
if (selected && if (selected &&
!createLogEntryToMergeParts(zookeeper, future_merged_part.parts, future_merged_part.name, deduplicate, &merge_entry)) !createLogEntryToMergeParts(zookeeper, future_merged_part.parts, future_merged_part.name, deduplicate, &merge_entry))
return handle_noop("Can't create merge queue node in ZooKeeper"); return handle_noop("Can't create merge queue node in ZooKeeper");
if (merge_entry.type != ReplicatedMergeTreeLogEntryData::Type::EMPTY)
merge_entries.push_back(std::move(merge_entry));
} }
} }
else else
@ -3074,15 +3077,20 @@ bool StorageReplicatedMergeTree::optimize(const ASTPtr & query, const ASTPtr & p
return handle_noop(disable_reason); return handle_noop(disable_reason);
} }
ReplicatedMergeTreeLogEntryData merge_entry;
if (!createLogEntryToMergeParts(zookeeper, future_merged_part.parts, future_merged_part.name, deduplicate, &merge_entry)) if (!createLogEntryToMergeParts(zookeeper, future_merged_part.parts, future_merged_part.name, deduplicate, &merge_entry))
return handle_noop("Can't create merge queue node in ZooKeeper"); return handle_noop("Can't create merge queue node in ZooKeeper");
if (merge_entry.type != ReplicatedMergeTreeLogEntryData::Type::EMPTY)
merge_entries.push_back(std::move(merge_entry));
} }
} }
/// TODO: Bad setting name for such purpose /// TODO: Bad setting name for such purpose
if (merge_entry.type != ReplicatedMergeTreeLogEntryData::Type::EMPTY if (query_context.getSettingsRef().replication_alter_partitions_sync != 0)
&& query_context.getSettingsRef().replication_alter_partitions_sync != 0) {
waitForAllReplicasToProcessLogEntry(merge_entry); for (auto & merge_entry : merge_entries)
waitForAllReplicasToProcessLogEntry(merge_entry);
}
return true; return true;
} }

View File

@ -0,0 +1,9 @@
DROP TABLE IF EXISTS test.replicated_optimize1;
DROP TABLE IF EXISTS test.replicated_optimize2;
CREATE TABLE test.replicated_optimize1 (d Date, k UInt64, i32 Int32) ENGINE=ReplicatedMergeTree('/clickhouse/tables/test/optimize', 'r1', d, k, 8192);
CREATE TABLE test.replicated_optimize2 (d Date, k UInt64, i32 Int32) ENGINE=ReplicatedMergeTree('/clickhouse/tables/test/optimize', 'r2', d, k, 8192);
OPTIMIZE TABLE test.replicated_optimize1 FINAL;
DROP TABLE test.replicated_optimize1;
DROP TABLE test.replicated_optimize2;