提交 bc9ee549 编写于 作者: V Vitaliy Lyudvichenko 提交者: alexey-milovidov

Don't throw exception in case of clearing empty part. [#CLICKHOUSE-2896]

上级 8763567e
......@@ -2617,11 +2617,11 @@ String StorageReplicatedMergeTree::getFakePartNameCoveringAllPartsInPartition(co
block_number_lock.unlock();
}
/// This should never happen.
/// Empty partition.
if (right == 0)
throw Exception("Logical error: newly allocated block number is zero", ErrorCodes::LOGICAL_ERROR);
--right;
return {};
--right;
return getFakePartNameCoveringPartRange(month_name, left, right);
}
......@@ -2636,6 +2636,12 @@ void StorageReplicatedMergeTree::clearColumnInPartition(
String month_name = MergeTreeData::getMonthName(partition);
String fake_part_name = getFakePartNameCoveringAllPartsInPartition(month_name);
if (fake_part_name.empty())
{
LOG_INFO(log, "Will not clear partition " << month_name << ", it is empty.");
return;
}
/// We allocated new block number for this part, so new merges can't merge clearing parts with new ones
LogEntry entry;
......@@ -2670,6 +2676,12 @@ void StorageReplicatedMergeTree::dropPartition(const ASTPtr & query, const Field
String month_name = MergeTreeData::getMonthName(partition);
String fake_part_name = getFakePartNameCoveringAllPartsInPartition(month_name);
if (fake_part_name.empty())
{
LOG_INFO(log, "Will not drop partition " << month_name << ", it is empty.");
return;
}
/** Forbid to choose the parts to be deleted for merging.
* Invariant: after the `DROP_RANGE` entry appears in the log, merge of deleted parts will not appear in the log.
*/
......
......@@ -468,6 +468,7 @@ private:
void assertNotReadonly() const;
/// The name of an imaginary part covering all parts in the specified partition (at the call moment).
/// Returns empty string if partition is empy.
String getFakePartNameCoveringAllPartsInPartition(const String & month_name);
/// Check for a node in ZK. If it is, remember this information, and then immediately answer true.
......
......@@ -49,6 +49,12 @@ SELECT sum(data_uncompressed_bytes) FROM system.columns WHERE database='test' AN
ALTER TABLE test.clear_column1 CLEAR COLUMN s IN PARTITION '200001';
ALTER TABLE test.clear_column1 CLEAR COLUMN s IN PARTITION '200002';
-- clear column in empty partition should be Ok
ALTER TABLE test.clear_column1 CLEAR COLUMN s IN PARTITION '200012', CLEAR COLUMN i IN PARTITION '200012';
-- Drop empty partition also Ok
ALTER TABLE test.clear_column1 DROP PARTITION '200012', DROP PARTITION '200011';
-- check optimize for non-leader replica (it is not related with CLEAR COLUMN)
OPTIMIZE TABLE test.clear_column1;
OPTIMIZE TABLE test.clear_column2;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册