diff --git a/src/Storages/StorageReplicatedMergeTree.cpp b/src/Storages/StorageReplicatedMergeTree.cpp index 02b5f4c238f..fc89deceb6b 100644 --- a/src/Storages/StorageReplicatedMergeTree.cpp +++ b/src/Storages/StorageReplicatedMergeTree.cpp @@ -7196,9 +7196,19 @@ bool StorageReplicatedMergeTree::unlockSharedData(const IMergeTreeDataPart & par if (!disk || !disk->supportZeroCopyReplication()) return true; - auto ref_count = disk->getRefCount(fs::path(part.getFullRelativePath()) / IMergeTreeDataPart::FILE_FOR_REFERENCES_CHECK); - if (ref_count > 0) /// Keep part shard info for frozen backups - return false; + /// If part is temporary refcount file may be absent + auto ref_count_path = fs::path(part.getFullRelativePath()) / IMergeTreeDataPart::FILE_FOR_REFERENCES_CHECK; + if (disk->exists(ref_count_path)) + { + auto ref_count = disk->getRefCount(ref_count_path); + if (ref_count > 0) /// Keep part shard info for frozen backups + return false; + } + else + { + /// Temporary part with some absent file cannot be locked in shared mode + return true; + } return unlockSharedDataByID(part.getUniqueId(), getTableSharedID(), name, replica_name, disk, getZooKeeper(), *getSettings(), log, zookeeper_path);