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; }; diff --git a/dbms/tests/queries/0_stateless/00832_storage_file_lock.reference b/dbms/tests/queries/0_stateless/00832_storage_file_lock.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00832_storage_file_lock.reference @@ -0,0 +1 @@ +1 diff --git a/dbms/tests/queries/0_stateless/00832_storage_file_lock.sql b/dbms/tests/queries/0_stateless/00832_storage_file_lock.sql new file mode 100644 index 00000000000..a3aeee110b0 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00832_storage_file_lock.sql @@ -0,0 +1,6 @@ +DROP TABLE IF EXISTS test.file; +CREATE TABLE test.file (number UInt64) ENGINE = File(TSV); +SELECT * FROM test.file; -- { serverError 107 } +INSERT INTO test.file VALUES (1); +SELECT * FROM test.file; +DROP TABLE test.file;