diff --git a/src/Common/DirectorySyncGuard.cpp b/src/Common/DirectorySyncGuard.cpp deleted file mode 100644 index f279a0d25d53c1df1de09a11bde720ff0d59060a..0000000000000000000000000000000000000000 --- a/src/Common/DirectorySyncGuard.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -#include // O_RDWR - -/// OSX does not have O_DIRECTORY -#ifndef O_DIRECTORY -#define O_DIRECTORY O_RDWR -#endif - -namespace DB -{ - -namespace ErrorCodes -{ - extern const int CANNOT_FSYNC; -} - -DirectorySyncGuard::DirectorySyncGuard(const DiskPtr & disk_, const String & path) - : disk(disk_) - , fd(disk_->open(path, O_DIRECTORY)) -{} - -DirectorySyncGuard::~DirectorySyncGuard() -{ - try - { -#if defined(OS_DARWIN) - if (fcntl(fd, F_FULLFSYNC, 0)) - throwFromErrno("Cannot fcntl(F_FULLFSYNC)", ErrorCodes::CANNOT_FSYNC); -#endif - disk->sync(fd); - disk->close(fd); - } - catch (...) - { - tryLogCurrentException(__PRETTY_FUNCTION__); - } -} - -} diff --git a/src/Common/ya.make b/src/Common/ya.make index 4f2f1892a88c63c42bfc19c7eb1b1e717350349e..a8cac313a7692d18e7f3f7176df4defa072c7f12 100644 --- a/src/Common/ya.make +++ b/src/Common/ya.make @@ -37,7 +37,6 @@ SRCS( CurrentMetrics.cpp CurrentThread.cpp DNSResolver.cpp - DirectorySyncGuard.cpp Dwarf.cpp Elf.cpp ErrorCodes.cpp diff --git a/src/Disks/DiskDecorator.cpp b/src/Disks/DiskDecorator.cpp index 6e8a2798212eb51c141521ccd73f1d80ac171d58..0c052ce8e9131ada2b20f6452496eb195e456611 100644 --- a/src/Disks/DiskDecorator.cpp +++ b/src/Disks/DiskDecorator.cpp @@ -175,24 +175,14 @@ void DiskDecorator::truncateFile(const String & path, size_t size) delegate->truncateFile(path, size); } -int DiskDecorator::open(const String & path, int flags) const -{ - return delegate->open(path, flags); -} - -void DiskDecorator::close(int fd) const -{ - delegate->close(fd); -} - -void DiskDecorator::sync(int fd) const +Executor & DiskDecorator::getExecutor() { - delegate->sync(fd); + return delegate->getExecutor(); } -Executor & DiskDecorator::getExecutor() +SyncGuardPtr DiskDecorator::getDirectorySyncGuard(const String & path) const { - return delegate->getExecutor(); + return delegate->getDirectorySyncGuard(path); } } diff --git a/src/Disks/DiskDecorator.h b/src/Disks/DiskDecorator.h index 4414959cca3afd557862a1e57dfe610cadc454d4..b50252c2c97c10d62b157301a10be0a0f9d05b9b 100644 --- a/src/Disks/DiskDecorator.h +++ b/src/Disks/DiskDecorator.h @@ -48,11 +48,9 @@ public: void setReadOnly(const String & path) override; void createHardLink(const String & src_path, const String & dst_path) override; void truncateFile(const String & path, size_t size) override; - int open(const String & path, int flags) const override; - void close(int fd) const override; - void sync(int fd) const override; const String getType() const override { return delegate->getType(); } Executor & getExecutor() override; + SyncGuardPtr getDirectorySyncGuard(const String & path) const override; protected: DiskPtr delegate; diff --git a/src/Disks/DiskLocal.cpp b/src/Disks/DiskLocal.cpp index ed6b82fa73de1fad2b6bae7c30452d71d97a73f6..8787f613bf7cee5ea1d71299a9e090eb84c0dab2 100644 --- a/src/Disks/DiskLocal.cpp +++ b/src/Disks/DiskLocal.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -20,10 +21,6 @@ namespace ErrorCodes extern const int EXCESSIVE_ELEMENT_IN_CONFIG; extern const int PATH_ACCESS_DENIED; extern const int INCORRECT_DISK_INDEX; - extern const int FILE_DOESNT_EXIST; - extern const int CANNOT_OPEN_FILE; - extern const int CANNOT_FSYNC; - extern const int CANNOT_CLOSE_FILE; extern const int CANNOT_TRUNCATE_FILE; extern const int CANNOT_UNLINK; extern const int CANNOT_RMDIR; @@ -315,26 +312,9 @@ void DiskLocal::copy(const String & from_path, const std::shared_ptr & to IDisk::copy(from_path, to_disk, to_path); /// Copy files through buffers. } -int DiskLocal::open(const String & path, int flags) const +SyncGuardPtr DiskLocal::getDirectorySyncGuard(const String & path) const { - String full_path = disk_path + path; - int fd = ::open(full_path.c_str(), flags); - if (-1 == fd) - throwFromErrnoWithPath("Cannot open file " + full_path, full_path, - errno == ENOENT ? ErrorCodes::FILE_DOESNT_EXIST : ErrorCodes::CANNOT_OPEN_FILE); - return fd; -} - -void DiskLocal::close(int fd) const -{ - if (-1 == ::close(fd)) - throw Exception("Cannot close file", ErrorCodes::CANNOT_CLOSE_FILE); -} - -void DiskLocal::sync(int fd) const -{ - if (-1 == ::fsync(fd)) - throw Exception("Cannot fsync", ErrorCodes::CANNOT_FSYNC); + return std::make_unique(disk_path + path); } DiskPtr DiskLocalReservation::getDisk(size_t i) const diff --git a/src/Disks/DiskLocal.h b/src/Disks/DiskLocal.h index 09f08a01d27bc756f303c7a161ad928abe83af3d..d8d45290986a0d4f6a8ea083dd8bcbff1f375f8c 100644 --- a/src/Disks/DiskLocal.h +++ b/src/Disks/DiskLocal.h @@ -98,14 +98,12 @@ public: void createHardLink(const String & src_path, const String & dst_path) override; - int open(const String & path, int flags) const override; - void close(int fd) const override; - void sync(int fd) const override; - void truncateFile(const String & path, size_t size) override; const String getType() const override { return "local"; } + SyncGuardPtr getDirectorySyncGuard(const String & path) const override; + private: bool tryReserve(UInt64 bytes); diff --git a/src/Disks/DiskMemory.cpp b/src/Disks/DiskMemory.cpp index 7317d8a75be5e9489a2e8ed52b7b357861c54ebf..d2ed91a8263d6636edbf69e8ecb55dc1a983c055 100644 --- a/src/Disks/DiskMemory.cpp +++ b/src/Disks/DiskMemory.cpp @@ -436,21 +436,6 @@ void DiskMemory::setReadOnly(const String &) throw Exception("Method setReadOnly is not implemented for memory disks", ErrorCodes::NOT_IMPLEMENTED); } -int DiskMemory::open(const String & /*path*/, int /*flags*/) const -{ - throw Exception("Method open is not implemented for memory disks", ErrorCodes::NOT_IMPLEMENTED); -} - -void DiskMemory::close(int /*fd*/) const -{ - throw Exception("Method close is not implemented for memory disks", ErrorCodes::NOT_IMPLEMENTED); -} - -void DiskMemory::sync(int /*fd*/) const -{ - throw Exception("Method sync is not implemented for memory disks", ErrorCodes::NOT_IMPLEMENTED); -} - void DiskMemory::truncateFile(const String & path, size_t size) { std::lock_guard lock(mutex); diff --git a/src/Disks/DiskMemory.h b/src/Disks/DiskMemory.h index 10d1dc670afcd7eb7b012539314cf1237193bf1a..3ebc76661d42e80d3c7d639d6806b8a1571477a2 100644 --- a/src/Disks/DiskMemory.h +++ b/src/Disks/DiskMemory.h @@ -89,10 +89,6 @@ public: void createHardLink(const String & src_path, const String & dst_path) override; - int open(const String & path, int flags) const override; - void close(int fd) const override; - void sync(int fd) const override; - void truncateFile(const String & path, size_t size) override; const String getType() const override { return "memory"; } diff --git a/src/Disks/IDisk.cpp b/src/Disks/IDisk.cpp index 8f11d6549e9a2c718fb5eef280b94b0775b2df4a..ee7f57af7718651b8d5e0cdece1e76cb7f978b31 100644 --- a/src/Disks/IDisk.cpp +++ b/src/Disks/IDisk.cpp @@ -76,4 +76,9 @@ void IDisk::truncateFile(const String &, size_t) throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Truncate operation is not implemented for disk of type {}", getType()); } +SyncGuardPtr IDisk::getDirectorySyncGuard(const String & /* path */) const +{ + return nullptr; +} + } diff --git a/src/Disks/IDisk.h b/src/Disks/IDisk.h index b68bca07de18400d04c0b49697791ff296c94ea1..f41490a0807b0dccbe1e40391675072306a206d8 100644 --- a/src/Disks/IDisk.h +++ b/src/Disks/IDisk.h @@ -57,6 +57,19 @@ public: using SpacePtr = std::shared_ptr; +/** + * A guard, that should synchronize file's or directory's state + * with storage device (e.g. fsync in POSIX) in its destructor. + */ +class ISyncGuard +{ +public: + ISyncGuard() = default; + virtual ~ISyncGuard() = default; +}; + +using SyncGuardPtr = std::unique_ptr; + /** * A unit of storage persisting data and metadata. * Abstract underlying storage technology. @@ -174,15 +187,6 @@ public: /// Create hardlink from `src_path` to `dst_path`. virtual void createHardLink(const String & src_path, const String & dst_path) = 0; - /// Wrapper for POSIX open - virtual int open(const String & path, int flags) const = 0; - - /// Wrapper for POSIX close - virtual void close(int fd) const = 0; - - /// Wrapper for POSIX fsync - virtual void sync(int fd) const = 0; - /// Truncate file to specified size. virtual void truncateFile(const String & path, size_t size); @@ -195,6 +199,9 @@ public: /// Returns executor to perform asynchronous operations. virtual Executor & getExecutor() { return *executor; } + /// Returns guard, that insures synchronization of directory metadata with storage device. + virtual SyncGuardPtr getDirectorySyncGuard(const String & path) const; + private: std::unique_ptr executor; }; diff --git a/src/Disks/LocalDirectorySyncGuard.cpp b/src/Disks/LocalDirectorySyncGuard.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ad66cdab6826874238158ee269e325fe71d062e1 --- /dev/null +++ b/src/Disks/LocalDirectorySyncGuard.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include // O_RDWR + +/// OSX does not have O_DIRECTORY +#ifndef O_DIRECTORY +#define O_DIRECTORY O_RDWR +#endif + +namespace DB +{ + +namespace ErrorCodes +{ + extern const int CANNOT_FSYNC; + extern const int FILE_DOESNT_EXIST; + extern const int CANNOT_OPEN_FILE; + extern const int CANNOT_CLOSE_FILE; +} + +LocalDirectorySyncGuard::LocalDirectorySyncGuard(const String & full_path) + : fd(::open(full_path.c_str(), O_DIRECTORY)) +{ + if (-1 == fd) + throwFromErrnoWithPath("Cannot open file " + full_path, full_path, + errno == ENOENT ? ErrorCodes::FILE_DOESNT_EXIST : ErrorCodes::CANNOT_OPEN_FILE); +} + +LocalDirectorySyncGuard::~LocalDirectorySyncGuard() +{ + try + { +#if defined(OS_DARWIN) + if (fcntl(fd, F_FULLFSYNC, 0)) + throwFromErrno("Cannot fcntl(F_FULLFSYNC)", ErrorCodes::CANNOT_FSYNC); +#endif + if (-1 == ::fsync(fd)) + throw Exception("Cannot fsync", ErrorCodes::CANNOT_FSYNC); + + if (-1 == ::close(fd)) + throw Exception("Cannot close file", ErrorCodes::CANNOT_CLOSE_FILE); + } + catch (...) + { + tryLogCurrentException(__PRETTY_FUNCTION__); + } +} + +} diff --git a/src/Common/DirectorySyncGuard.h b/src/Disks/LocalDirectorySyncGuard.h similarity index 70% rename from src/Common/DirectorySyncGuard.h rename to src/Disks/LocalDirectorySyncGuard.h index 062d20324ed9b8b46c0680d2283a293eb4244713..34e4cb9e65799a4f0eb312f6f157517865b66d0d 100644 --- a/src/Common/DirectorySyncGuard.h +++ b/src/Disks/LocalDirectorySyncGuard.h @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include namespace DB { @@ -13,17 +12,16 @@ using DiskPtr = std::shared_ptr; /// It's used to keep descriptor open, while doing some operations with it, and do fsync at the end. /// Guaranties of sequence 'close-reopen-fsync' may depend on kernel version. /// Source: linux-fsdevel mailing-list https://marc.info/?l=linux-fsdevel&m=152535409207496 -class DirectorySyncGuard +class LocalDirectorySyncGuard final : public ISyncGuard { public: /// NOTE: If you have already opened descriptor, it's preferred to use /// this constructor instead of constructor with path. - DirectorySyncGuard(const DiskPtr & disk_, int fd_) : disk(disk_), fd(fd_) {} - DirectorySyncGuard(const DiskPtr & disk_, const std::string & path); - ~DirectorySyncGuard(); + LocalDirectorySyncGuard(int fd_) : fd(fd_) {} + LocalDirectorySyncGuard(const String & full_path); + ~LocalDirectorySyncGuard() override; private: - DiskPtr disk; int fd = -1; }; diff --git a/src/Disks/S3/DiskS3.cpp b/src/Disks/S3/DiskS3.cpp index 081c62bd047e0a26388b8f4a8de66d31a3f65e2d..238db98c9ccbc41cac456bc2cf092b3fced3e335 100644 --- a/src/Disks/S3/DiskS3.cpp +++ b/src/Disks/S3/DiskS3.cpp @@ -36,7 +36,6 @@ namespace ErrorCodes extern const int CANNOT_SEEK_THROUGH_FILE; extern const int UNKNOWN_FORMAT; extern const int INCORRECT_DISK_INDEX; - extern const int NOT_IMPLEMENTED; extern const int PATH_ACCESS_DENIED; extern const int CANNOT_DELETE_DIRECTORY; } @@ -878,21 +877,6 @@ void DiskS3::setReadOnly(const String & path) metadata.save(); } -int DiskS3::open(const String & /*path*/, int /*flags*/) const -{ - throw Exception("Method open is not implemented for S3 disks", ErrorCodes::NOT_IMPLEMENTED); -} - -void DiskS3::close(int /*fd*/) const -{ - throw Exception("Method close is not implemented for S3 disks", ErrorCodes::NOT_IMPLEMENTED); -} - -void DiskS3::sync(int /*fd*/) const -{ - throw Exception("Method sync is not implemented for S3 disks", ErrorCodes::NOT_IMPLEMENTED); -} - void DiskS3::shutdown() { /// This call stops any next retry attempts for ongoing S3 requests. diff --git a/src/Disks/S3/DiskS3.h b/src/Disks/S3/DiskS3.h index 7f742368d19f7f3e4e53a7d4918cdd7a765a9d73..3dbd9029fb250936bb1fa4889302887eebde3072 100644 --- a/src/Disks/S3/DiskS3.h +++ b/src/Disks/S3/DiskS3.h @@ -105,10 +105,6 @@ public: void setReadOnly(const String & path) override; - int open(const String & path, int flags) const override; - void close(int fd) const override; - void sync(int fd) const override; - const String getType() const override { return "s3"; } void shutdown() override; diff --git a/src/Disks/ya.make b/src/Disks/ya.make index 5b3e4f951dce1271ca1d688c442797016e9ce1d1..53dc9fd75c4f32d2affc0557377a00de5a6b1602 100644 --- a/src/Disks/ya.make +++ b/src/Disks/ya.make @@ -17,6 +17,7 @@ SRCS( DiskSelector.cpp IDisk.cpp IVolume.cpp + LocalDirectorySyncGuard.cpp SingleDiskVolume.cpp StoragePolicy.cpp VolumeJBOD.cpp diff --git a/src/Storages/Distributed/DirectoryMonitor.cpp b/src/Storages/Distributed/DirectoryMonitor.cpp index f54a19c4d15d7afa0e28f296c481fa15f92a0bb8..8d1b9103357d5c26385d9ee0f672706145472eb8 100644 --- a/src/Storages/Distributed/DirectoryMonitor.cpp +++ b/src/Storages/Distributed/DirectoryMonitor.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -178,6 +177,13 @@ namespace || code == ErrorCodes::CANNOT_DECOMPRESS || (!remote_error && code == ErrorCodes::ATTEMPT_TO_READ_AFTER_EOF); } + + SyncGuardPtr getDirectorySyncGuard(bool dir_fsync, const DiskPtr & disk, const String & path) + { + if (dir_fsync) + return disk->getDirectorySyncGuard(path); + return nullptr; + } } @@ -244,10 +250,7 @@ void StorageDistributedDirectoryMonitor::shutdownAndDropAllData() task_handle->deactivate(); } - std::optional dir_sync_guard; - if (dir_fsync) - dir_sync_guard.emplace(disk, relative_path); - + auto dir_sync_guard = getDirectorySyncGuard(dir_fsync, disk, relative_path); Poco::File(path).remove(true); } @@ -448,10 +451,7 @@ void StorageDistributedDirectoryMonitor::processFile(const std::string & file_pa throw; } - std::optional dir_sync_guard; - if (dir_fsync) - dir_sync_guard.emplace(disk, relative_path); - + auto dir_sync_guard = getDirectorySyncGuard(dir_fsync, disk, relative_path); Poco::File{file_path}.remove(); metric_pending_files.sub(); @@ -537,9 +537,7 @@ struct StorageDistributedDirectoryMonitor::Batch /// Temporary file is required for atomicity. String tmp_file{parent.current_batch_file_path + ".tmp"}; - std::optional dir_sync_guard; - if (dir_fsync) - dir_sync_guard.emplace(parent.disk, parent.relative_path); + auto dir_sync_guard = getDirectorySyncGuard(dir_fsync, parent.disk, parent.relative_path); if (Poco::File{tmp_file}.exists()) LOG_ERROR(parent.log, "Temporary file {} exists. Unclean shutdown?", backQuote(tmp_file)); @@ -607,10 +605,7 @@ struct StorageDistributedDirectoryMonitor::Batch { LOG_TRACE(parent.log, "Sent a batch of {} files.", file_indices.size()); - std::optional dir_sync_guard; - if (dir_fsync) - dir_sync_guard.emplace(parent.disk, parent.relative_path); - + auto dir_sync_guard = getDirectorySyncGuard(dir_fsync, parent.disk, parent.relative_path); for (UInt64 file_index : file_indices) Poco::File{file_index_to_path.at(file_index)}.remove(); } @@ -813,9 +808,7 @@ void StorageDistributedDirectoryMonitor::processFilesWithBatching(const std::map } { - std::optional dir_sync_guard; - if (dir_fsync) - dir_sync_guard.emplace(disk, relative_path); + auto dir_sync_guard = getDirectorySyncGuard(dir_fsync, disk, relative_path); /// current_batch.txt will not exist if there was no send /// (this is the case when all batches that was pending has been marked as pending) @@ -834,13 +827,8 @@ void StorageDistributedDirectoryMonitor::markAsBroken(const std::string & file_p Poco::File{broken_path}.createDirectory(); - std::optional dir_sync_guard; - std::optional broken_dir_sync_guard; - if (dir_fsync) - { - broken_dir_sync_guard.emplace(disk, relative_path + "/broken/"); - dir_sync_guard.emplace(disk, relative_path); - } + auto dir_sync_guard = getDirectorySyncGuard(dir_fsync, disk, relative_path); + auto broken_dir_sync_guard = getDirectorySyncGuard(dir_fsync, disk, relative_path + "/broken/"); Poco::File{file_path}.renameTo(broken_file_path); diff --git a/src/Storages/Distributed/DistributedBlockOutputStream.cpp b/src/Storages/Distributed/DistributedBlockOutputStream.cpp index f4711399400f8045cc86a456f7630214142b1528..d21764bbb7deabf94f1ccb2caf264e19b58ca0da 100644 --- a/src/Storages/Distributed/DistributedBlockOutputStream.cpp +++ b/src/Storages/Distributed/DistributedBlockOutputStream.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -623,11 +622,11 @@ void DistributedBlockOutputStream::writeToShard(const Block & block, const std:: auto make_directory_sync_guard = [&](const std::string & current_path) { - std::unique_ptr guard; + SyncGuardPtr guard; if (dir_fsync) { const std::string relative_path(data_path + current_path); - guard = std::make_unique(disk, relative_path); + guard = disk->getDirectorySyncGuard(relative_path); } return guard; }; diff --git a/src/Storages/MergeTree/DataPartsExchange.cpp b/src/Storages/MergeTree/DataPartsExchange.cpp index 5d50f29756c1062aa74b50714337fe4b488a68d9..e01e7793dd36e00423c04d1c4dc54df31cad1917 100644 --- a/src/Storages/MergeTree/DataPartsExchange.cpp +++ b/src/Storages/MergeTree/DataPartsExchange.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -398,9 +397,9 @@ MergeTreeData::MutableDataPartPtr Fetcher::downloadPartToDisk( disk->createDirectories(part_download_path); - std::optional sync_guard; + SyncGuardPtr sync_guard; if (data.getSettings()->fsync_part_directory) - sync_guard.emplace(disk, part_download_path); + sync_guard = disk->getDirectorySyncGuard(part_download_path); MergeTreeData::DataPart::Checksums checksums; for (size_t i = 0; i < files; ++i) diff --git a/src/Storages/MergeTree/IMergeTreeDataPart.cpp b/src/Storages/MergeTree/IMergeTreeDataPart.cpp index 0544f280e2552f6893eb081f95f699ef9978e43f..7c37a067360890821f3a02b4e3fad912aadca27e 100644 --- a/src/Storages/MergeTree/IMergeTreeDataPart.cpp +++ b/src/Storages/MergeTree/IMergeTreeDataPart.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -1002,9 +1001,9 @@ void IMergeTreeDataPart::renameTo(const String & new_relative_path, bool remove_ volume->getDisk()->moveFile(from, to); relative_path = new_relative_path; - std::optional sync_guard; + SyncGuardPtr sync_guard; if (storage.getSettings()->fsync_part_directory) - sync_guard.emplace(volume->getDisk(), to); + sync_guard = volume->getDisk()->getDirectorySyncGuard(to); } diff --git a/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp b/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp index f999aa67bbe860bd9e4ae78e7f322a48fd868b90..f6581574ede8149be951ff083376ce1f921e1872 100644 --- a/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp +++ b/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -780,9 +779,9 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mergePartsToTempor gathering_column_names.clear(); } - std::optional sync_guard; + SyncGuardPtr sync_guard; if (data.getSettings()->fsync_part_directory) - sync_guard.emplace(disk, new_part_tmp_path); + sync_guard = disk->getDirectorySyncGuard(new_part_tmp_path); /** Read from all parts, merge and write into a new one. * In passing, we calculate expression for sorting. @@ -1182,9 +1181,9 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mutatePartToTempor disk->createDirectories(new_part_tmp_path); - std::optional sync_guard; + SyncGuardPtr sync_guard; if (data.getSettings()->fsync_part_directory) - sync_guard.emplace(disk, new_part_tmp_path); + sync_guard = disk->getDirectorySyncGuard(new_part_tmp_path); /// Don't change granularity type while mutating subset of columns auto mrk_extension = source_part->index_granularity_info.is_adaptive ? getAdaptiveMrkExtension(new_data_part->getType()) diff --git a/src/Storages/MergeTree/MergeTreeDataWriter.cpp b/src/Storages/MergeTree/MergeTreeDataWriter.cpp index de4d70d5e3e7a22b2c2d6d962b27bd7f0486d369..b49c07bc918b168dbe41c0e7467f22522a908175 100644 --- a/src/Storages/MergeTree/MergeTreeDataWriter.cpp +++ b/src/Storages/MergeTree/MergeTreeDataWriter.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include @@ -362,7 +361,7 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataWriter::writeTempPart(BlockWithPa new_data_part->minmax_idx = std::move(minmax_idx); new_data_part->is_temp = true; - std::optional sync_guard; + SyncGuardPtr sync_guard; if (new_data_part->isStoredOnDisk()) { /// The name could be non-unique in case of stale files from previous runs. @@ -378,7 +377,7 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataWriter::writeTempPart(BlockWithPa disk->createDirectories(full_path); if (data.getSettings()->fsync_part_directory) - sync_guard.emplace(disk, full_path); + sync_guard = disk->getDirectorySyncGuard(full_path); } if (metadata_snapshot->hasRowsTTL())