diff --git a/dbms/src/Storages/StorageFile.cpp b/dbms/src/Storages/StorageFile.cpp index 95f38862d9b..8fac03c72a3 100644 --- a/dbms/src/Storages/StorageFile.cpp +++ b/dbms/src/Storages/StorageFile.cpp @@ -121,7 +121,7 @@ public: { if (storage.use_table_fd) { - storage.rwlock.lock(); + unique_lock = std::unique_lock(storage.rwlock); /// We could use common ReadBuffer and WriteBuffer in storage to leverage cache /// and add ability to seek unseekable files, but cache sync isn't supported. @@ -141,7 +141,7 @@ public: } else { - storage.rwlock.lock_shared(); + shared_lock = std::shared_lock(storage.rwlock); read_buf = std::make_unique(storage.path); } @@ -149,14 +149,6 @@ public: reader = FormatFactory::instance().getInput(storage.format_name, *read_buf, storage.getSampleBlock(), context, max_block_size); } - ~StorageFileBlockInputStream() override - { - if (storage.use_table_fd) - storage.rwlock.unlock(); - else - storage.rwlock.unlock_shared(); - } - String getName() const override { return storage.getName(); @@ -184,6 +176,9 @@ private: Block sample_block; std::unique_ptr read_buf; BlockInputStreamPtr reader; + + std::shared_lock shared_lock; + std::unique_lock unique_lock; };