Fix parts removal on drop + add unrelated test

This commit is contained in:
alesapin 2022-09-19 20:19:49 +02:00
parent f58f8104b5
commit 740b0b5cc0
3 changed files with 59 additions and 0 deletions

View File

@ -154,6 +154,7 @@ namespace ErrorCodes
extern const int TOO_MANY_SIMULTANEOUS_QUERIES;
extern const int INCORRECT_QUERY;
extern const int CANNOT_RESTORE_TABLE;
extern const int ZERO_COPY_REPLICATION_ERROR;
}
static void checkSampleExpression(const StorageInMemoryMetadata & metadata, bool allow_sampling_expression_not_in_primary_key, bool check_sample_column_is_correct)
@ -2178,6 +2179,9 @@ void MergeTreeData::dropAllData()
throw;
}
LOG_INFO(log, "dropAllData: clearing temporary directories");
clearOldTemporaryDirectories(0, {"tmp_", "delete_tmp_", "tmp-fetch_"});
column_sizes.clear();
for (const auto & disk : getDisks())
@ -2185,8 +2189,22 @@ void MergeTreeData::dropAllData()
if (disk->isBroken())
continue;
LOG_INFO(log, "dropAllData: remove format_version.txt and detached directory");
disk->removeFile(fs::path(relative_data_path) / "format_version.txt");
disk->removeRecursive(fs::path(relative_data_path) / "detached");
try
{
if (!disk->isDirectoryEmpty(relative_data_path) && disk->supportZeroCopyReplication() && settings_ptr->allow_remote_fs_zero_copy_replication)
{
std::vector<std::string> files_left;
disk->listFiles(relative_data_path, files_left);
throw Exception(
ErrorCodes::ZERO_COPY_REPLICATION_ERROR, "Directory {} with table {} not empty (files [{}]) after drop. Will not drop.",
relative_data_path, getStorageID().getNameForLogs(), fmt::join(files_left, ", "));
}
LOG_INFO(log, "dropAllData: removing table directory recursive to cleanup garbage");
disk->removeRecursive(relative_data_path);
}

View File

@ -0,0 +1,40 @@
DROP TABLE IF EXISTS mutate_and_zero_copy_replication1;
DROP TABLE IF EXISTS mutate_and_zero_copy_replication2;
CREATE TABLE mutate_and_zero_copy_replication1
(
a UInt64,
b String,
c Float64
)
ENGINE ReplicatedMergeTree('/clickhouse/tables/{database}/test_02427_mutate_and_zero_copy_replication/alter', '1')
ORDER BY tuple()
SETTINGS old_parts_lifetime=0, cleanup_delay_period=300, cleanup_delay_period_random_add=300, min_bytes_for_wide_part = 0;
CREATE TABLE mutate_and_zero_copy_replication2
(
a UInt64,
b String,
c Float64
)
ENGINE ReplicatedMergeTree('/clickhouse/tables/{database}/test_02427_mutate_and_zero_copy_replication/alter', '2')
ORDER BY tuple()
SETTINGS old_parts_lifetime=0, cleanup_delay_period=300, cleanup_delay_period_random_add=300;
INSERT INTO mutate_and_zero_copy_replication1 VALUES (1, '1', 1.0);
SYSTEM SYNC REPLICA mutate_and_zero_copy_replication2;
SET mutations_sync=2;
ALTER TABLE mutate_and_zero_copy_replication1 UPDATE a = 2 WHERE 1;
DROP TABLE mutate_and_zero_copy_replication1 SYNC;
DETACH TABLE mutate_and_zero_copy_replication2;
ATTACH TABLE mutate_and_zero_copy_replication2;
SELECT * FROM mutate_and_zero_copy_replication2 WHERE NOT ignore(*);
DROP TABLE IF EXISTS mutate_and_zero_copy_replication1;
DROP TABLE IF EXISTS mutate_and_zero_copy_replication2;