Skip to content

Commit

Permalink
Merge pull request ClickHouse#4684 from amosbird/fixempty2
Browse files Browse the repository at this point in the history
Refinement
  • Loading branch information
alexey-milovidov authored Mar 14, 2019
2 parents cc947da + b405c74 commit bdc7614
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
16 changes: 12 additions & 4 deletions dbms/src/Storages/StorageReplicatedMergeTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3014,7 +3014,7 @@ bool StorageReplicatedMergeTree::optimize(const ASTPtr & query, const ASTPtr & p
return true;
}

ReplicatedMergeTreeLogEntryData merge_entry;
std::vector<ReplicatedMergeTreeLogEntryData> merge_entries;
{
/// We must select parts for merge under merge_selecting_mutex because other threads
/// (merge_selecting_thread or OPTIMIZE queries) could assign new merges.
Expand Down Expand Up @@ -3045,9 +3045,12 @@ bool StorageReplicatedMergeTree::optimize(const ASTPtr & query, const ASTPtr & p
FutureMergedMutatedPart future_merged_part;
bool selected = merger_mutator.selectAllPartsToMergeWithinPartition(
future_merged_part, disk_space, can_merge, partition_id, true, nullptr);
ReplicatedMergeTreeLogEntryData merge_entry;
if (selected &&
!createLogEntryToMergeParts(zookeeper, future_merged_part.parts, future_merged_part.name, deduplicate, &merge_entry))
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
Expand All @@ -3074,15 +3077,20 @@ bool StorageReplicatedMergeTree::optimize(const ASTPtr & query, const ASTPtr & p
return handle_noop(disable_reason);
}

ReplicatedMergeTreeLogEntryData 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");
if (merge_entry.type != ReplicatedMergeTreeLogEntryData::Type::EMPTY)
merge_entries.push_back(std::move(merge_entry));
}
}

/// TODO: Bad setting name for such purpose
if (merge_entry.type != ReplicatedMergeTreeLogEntryData::Type::EMPTY
&& query_context.getSettingsRef().replication_alter_partitions_sync != 0)
waitForAllReplicasToProcessLogEntry(merge_entry);
if (query_context.getSettingsRef().replication_alter_partitions_sync != 0)
{
for (auto & merge_entry : merge_entries)
waitForAllReplicasToProcessLogEntry(merge_entry);
}

return true;
}
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit bdc7614

Please sign in to comment.