replace every std::shared_mutex with DB::FastSharedMutex

This commit is contained in:
serxa 2023-01-06 23:35:38 +00:00
parent a6958fff45
commit 15bb127b01
28 changed files with 81 additions and 83 deletions

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <shared_mutex> #include <Common/Threading.h>
#include <Common/ProfileEvents.h> #include <Common/ProfileEvents.h>
#include <Common/Stopwatch.h> #include <Common/Stopwatch.h>
@ -12,7 +12,7 @@ class ProfilingScopedWriteRWLock
{ {
public: public:
ProfilingScopedWriteRWLock(std::shared_mutex & rwl_, ProfileEvents::Event event) : ProfilingScopedWriteRWLock(DB::FastSharedMutex & rwl_, ProfileEvents::Event event) :
scoped_write_lock(rwl_) scoped_write_lock(rwl_)
{ {
ProfileEvents::increment(event, watch.elapsed()); ProfileEvents::increment(event, watch.elapsed());
@ -20,14 +20,14 @@ public:
private: private:
Stopwatch watch; Stopwatch watch;
std::unique_lock<std::shared_mutex> scoped_write_lock; std::unique_lock<DB::FastSharedMutex> scoped_write_lock;
}; };
class ProfilingScopedReadRWLock class ProfilingScopedReadRWLock
{ {
public: public:
ProfilingScopedReadRWLock(std::shared_mutex & rwl, ProfileEvents::Event event) : ProfilingScopedReadRWLock(DB::FastSharedMutex & rwl, ProfileEvents::Event event) :
scoped_read_lock(rwl) scoped_read_lock(rwl)
{ {
ProfileEvents::increment(event, watch.elapsed()); ProfileEvents::increment(event, watch.elapsed());
@ -35,7 +35,7 @@ public:
private: private:
Stopwatch watch; Stopwatch watch;
std::shared_lock<std::shared_mutex> scoped_read_lock; std::shared_lock<DB::FastSharedMutex> scoped_read_lock;
}; };
} }

View File

@ -5,6 +5,7 @@
#include <IO/Progress.h> #include <IO/Progress.h>
#include <Common/MemoryTracker.h> #include <Common/MemoryTracker.h>
#include <Common/ProfileEvents.h> #include <Common/ProfileEvents.h>
#include <Common/Threading.h>
#include <base/StringRef.h> #include <base/StringRef.h>
#include <Common/ConcurrentBoundedQueue.h> #include <Common/ConcurrentBoundedQueue.h>
@ -14,7 +15,6 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <shared_mutex>
#include <unordered_set> #include <unordered_set>

View File

@ -3,7 +3,9 @@
#include <base/types.h> #include <base/types.h>
#include <base/defines.h> #include <base/defines.h>
#include <Common/Exception.h> #include <Common/Exception.h> // for chassert to work
#include <shared_mutex> // for std::shared_lock and std::unique_lock
#ifdef OS_LINUX /// Because of futex #ifdef OS_LINUX /// Because of futex
@ -216,8 +218,6 @@ private:
#else #else
#include <shared_mutex>
// WARNING: We support cancellable synchronization primitives only on linux for now // WARNING: We support cancellable synchronization primitives only on linux for now
namespace DB namespace DB

View File

@ -4,7 +4,6 @@
#include <chrono> #include <chrono>
#include <cmath> #include <cmath>
#include <mutex> #include <mutex>
#include <shared_mutex>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -14,6 +13,7 @@
#include <Common/randomSeed.h> #include <Common/randomSeed.h>
#include <Common/ThreadPool.h> #include <Common/ThreadPool.h>
#include <Common/Threading.h>
#include <Common/CurrentMetrics.h> #include <Common/CurrentMetrics.h>
#include <Dictionaries/IDictionary.h> #include <Dictionaries/IDictionary.h>
@ -206,7 +206,7 @@ private:
/// This lock is used for the inner cache state update function lock it for /// This lock is used for the inner cache state update function lock it for
/// write, when it need to update cache state all other functions just /// write, when it need to update cache state all other functions just
/// readers. Surprisingly this lock is also used for last_exception pointer. /// readers. Surprisingly this lock is also used for last_exception pointer.
mutable std::shared_mutex rw_lock; mutable DB::FastSharedMutex rw_lock;
mutable std::exception_ptr last_exception; mutable std::exception_ptr last_exception;
mutable std::atomic<size_t> error_count {0}; mutable std::atomic<size_t> error_count {0};

View File

@ -2,12 +2,12 @@
#include <atomic> #include <atomic>
#include <mutex> #include <mutex>
#include <shared_mutex>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <functional> #include <functional>
#include <Common/ThreadPool.h> #include <Common/ThreadPool.h>
#include <Common/Threading.h>
#include <Common/ConcurrentBoundedQueue.h> #include <Common/ConcurrentBoundedQueue.h>
#include <Common/CurrentMetrics.h> #include <Common/CurrentMetrics.h>
#include <Common/PODArray.h> #include <Common/PODArray.h>

View File

@ -15,7 +15,7 @@ class FakeMetadataStorageFromDisk final : public IMetadataStorage
private: private:
friend class FakeMetadataStorageFromDiskTransaction; friend class FakeMetadataStorageFromDiskTransaction;
mutable std::shared_mutex metadata_mutex; mutable DB::FastSharedMutex metadata_mutex;
DiskPtr disk; DiskPtr disk;
ObjectStoragePtr object_storage; ObjectStoragePtr object_storage;

View File

@ -83,7 +83,7 @@ std::string MetadataStorageFromDisk::readInlineDataToString(const std::string &
return readMetadata(path)->getInlineData(); return readMetadata(path)->getInlineData();
} }
DiskObjectStorageMetadataPtr MetadataStorageFromDisk::readMetadataUnlocked(const std::string & path, std::shared_lock<std::shared_mutex> &) const DiskObjectStorageMetadataPtr MetadataStorageFromDisk::readMetadataUnlocked(const std::string & path, std::shared_lock<DB::FastSharedMutex> &) const
{ {
auto metadata = std::make_unique<DiskObjectStorageMetadata>(disk->getPath(), object_storage_root_path, path); auto metadata = std::make_unique<DiskObjectStorageMetadata>(disk->getPath(), object_storage_root_path, path);
auto str = readFileToString(path); auto str = readFileToString(path);
@ -91,7 +91,7 @@ DiskObjectStorageMetadataPtr MetadataStorageFromDisk::readMetadataUnlocked(const
return metadata; return metadata;
} }
DiskObjectStorageMetadataPtr MetadataStorageFromDisk::readMetadataUnlocked(const std::string & path, std::unique_lock<std::shared_mutex> &) const DiskObjectStorageMetadataPtr MetadataStorageFromDisk::readMetadataUnlocked(const std::string & path, std::unique_lock<DB::FastSharedMutex> &) const
{ {
auto metadata = std::make_unique<DiskObjectStorageMetadata>(disk->getPath(), object_storage_root_path, path); auto metadata = std::make_unique<DiskObjectStorageMetadata>(disk->getPath(), object_storage_root_path, path);
auto str = readFileToString(path); auto str = readFileToString(path);

View File

@ -17,7 +17,7 @@ class MetadataStorageFromDisk final : public IMetadataStorage
private: private:
friend class MetadataStorageFromDiskTransaction; friend class MetadataStorageFromDiskTransaction;
mutable std::shared_mutex metadata_mutex; mutable DB::FastSharedMutex metadata_mutex;
DiskPtr disk; DiskPtr disk;
std::string object_storage_root_path; std::string object_storage_root_path;
@ -67,8 +67,8 @@ public:
DiskObjectStorageMetadataPtr readMetadata(const std::string & path) const; DiskObjectStorageMetadataPtr readMetadata(const std::string & path) const;
DiskObjectStorageMetadataPtr readMetadataUnlocked(const std::string & path, std::unique_lock<std::shared_mutex> & lock) const; DiskObjectStorageMetadataPtr readMetadataUnlocked(const std::string & path, std::unique_lock<DB::FastSharedMutex> & lock) const;
DiskObjectStorageMetadataPtr readMetadataUnlocked(const std::string & path, std::shared_lock<std::shared_mutex> & lock) const; DiskObjectStorageMetadataPtr readMetadataUnlocked(const std::string & path, std::shared_lock<DB::FastSharedMutex> & lock) const;
}; };
class MetadataStorageFromDiskTransaction final : public IMetadataTransaction class MetadataStorageFromDiskTransaction final : public IMetadataTransaction

View File

@ -26,7 +26,7 @@ SetLastModifiedOperation::SetLastModifiedOperation(const std::string & path_, Po
{ {
} }
void SetLastModifiedOperation::execute(std::unique_lock<std::shared_mutex> &) void SetLastModifiedOperation::execute(std::unique_lock<DB::FastSharedMutex> &)
{ {
old_timestamp = disk.getLastModified(path); old_timestamp = disk.getLastModified(path);
disk.setLastModified(path, new_timestamp); disk.setLastModified(path, new_timestamp);
@ -44,7 +44,7 @@ ChmodOperation::ChmodOperation(const std::string & path_, mode_t mode_, IDisk &
{ {
} }
void ChmodOperation::execute(std::unique_lock<std::shared_mutex> &) void ChmodOperation::execute(std::unique_lock<DB::FastSharedMutex> &)
{ {
old_mode = disk.stat(path).st_mode; old_mode = disk.stat(path).st_mode;
disk.chmod(path, mode); disk.chmod(path, mode);
@ -61,7 +61,7 @@ UnlinkFileOperation::UnlinkFileOperation(const std::string & path_, IDisk & disk
{ {
} }
void UnlinkFileOperation::execute(std::unique_lock<std::shared_mutex> &) void UnlinkFileOperation::execute(std::unique_lock<DB::FastSharedMutex> &)
{ {
auto buf = disk.readFile(path, ReadSettings{}, std::nullopt, disk.getFileSize(path)); auto buf = disk.readFile(path, ReadSettings{}, std::nullopt, disk.getFileSize(path));
readStringUntilEOF(prev_data, *buf); readStringUntilEOF(prev_data, *buf);
@ -81,7 +81,7 @@ CreateDirectoryOperation::CreateDirectoryOperation(const std::string & path_, ID
{ {
} }
void CreateDirectoryOperation::execute(std::unique_lock<std::shared_mutex> &) void CreateDirectoryOperation::execute(std::unique_lock<DB::FastSharedMutex> &)
{ {
disk.createDirectory(path); disk.createDirectory(path);
} }
@ -97,7 +97,7 @@ CreateDirectoryRecursiveOperation::CreateDirectoryRecursiveOperation(const std::
{ {
} }
void CreateDirectoryRecursiveOperation::execute(std::unique_lock<std::shared_mutex> &) void CreateDirectoryRecursiveOperation::execute(std::unique_lock<DB::FastSharedMutex> &)
{ {
namespace fs = std::filesystem; namespace fs = std::filesystem;
fs::path p(path); fs::path p(path);
@ -124,7 +124,7 @@ RemoveDirectoryOperation::RemoveDirectoryOperation(const std::string & path_, ID
{ {
} }
void RemoveDirectoryOperation::execute(std::unique_lock<std::shared_mutex> &) void RemoveDirectoryOperation::execute(std::unique_lock<DB::FastSharedMutex> &)
{ {
disk.removeDirectory(path); disk.removeDirectory(path);
} }
@ -141,7 +141,7 @@ RemoveRecursiveOperation::RemoveRecursiveOperation(const std::string & path_, ID
{ {
} }
void RemoveRecursiveOperation::execute(std::unique_lock<std::shared_mutex> &) void RemoveRecursiveOperation::execute(std::unique_lock<DB::FastSharedMutex> &)
{ {
if (disk.isFile(path)) if (disk.isFile(path))
disk.moveFile(path, temp_path); disk.moveFile(path, temp_path);
@ -174,7 +174,7 @@ CreateHardlinkOperation::CreateHardlinkOperation(const std::string & path_from_,
{ {
} }
void CreateHardlinkOperation::execute(std::unique_lock<std::shared_mutex> & lock) void CreateHardlinkOperation::execute(std::unique_lock<DB::FastSharedMutex> & lock)
{ {
auto metadata = metadata_storage.readMetadataUnlocked(path_from, lock); auto metadata = metadata_storage.readMetadataUnlocked(path_from, lock);
@ -201,7 +201,7 @@ MoveFileOperation::MoveFileOperation(const std::string & path_from_, const std::
{ {
} }
void MoveFileOperation::execute(std::unique_lock<std::shared_mutex> &) void MoveFileOperation::execute(std::unique_lock<DB::FastSharedMutex> &)
{ {
disk.moveFile(path_from, path_to); disk.moveFile(path_from, path_to);
} }
@ -218,7 +218,7 @@ MoveDirectoryOperation::MoveDirectoryOperation(const std::string & path_from_, c
{ {
} }
void MoveDirectoryOperation::execute(std::unique_lock<std::shared_mutex> &) void MoveDirectoryOperation::execute(std::unique_lock<DB::FastSharedMutex> &)
{ {
disk.moveDirectory(path_from, path_to); disk.moveDirectory(path_from, path_to);
} }
@ -236,7 +236,7 @@ ReplaceFileOperation::ReplaceFileOperation(const std::string & path_from_, const
{ {
} }
void ReplaceFileOperation::execute(std::unique_lock<std::shared_mutex> &) void ReplaceFileOperation::execute(std::unique_lock<DB::FastSharedMutex> &)
{ {
if (disk.exists(path_to)) if (disk.exists(path_to))
disk.moveFile(path_to, temp_path_to); disk.moveFile(path_to, temp_path_to);
@ -262,7 +262,7 @@ WriteFileOperation::WriteFileOperation(const std::string & path_, IDisk & disk_,
{ {
} }
void WriteFileOperation::execute(std::unique_lock<std::shared_mutex> &) void WriteFileOperation::execute(std::unique_lock<DB::FastSharedMutex> &)
{ {
if (disk.exists(path)) if (disk.exists(path))
{ {
@ -288,7 +288,7 @@ void WriteFileOperation::undo()
} }
} }
void AddBlobOperation::execute(std::unique_lock<std::shared_mutex> & metadata_lock) void AddBlobOperation::execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock)
{ {
DiskObjectStorageMetadataPtr metadata; DiskObjectStorageMetadataPtr metadata;
if (metadata_storage.exists(path)) if (metadata_storage.exists(path))
@ -309,7 +309,7 @@ void AddBlobOperation::undo()
write_operation->undo(); write_operation->undo();
} }
void UnlinkMetadataFileOperation::execute(std::unique_lock<std::shared_mutex> & metadata_lock) void UnlinkMetadataFileOperation::execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock)
{ {
auto metadata = metadata_storage.readMetadataUnlocked(path, metadata_lock); auto metadata = metadata_storage.readMetadataUnlocked(path, metadata_lock);
uint32_t ref_count = metadata->getRefCount(); uint32_t ref_count = metadata->getRefCount();
@ -336,7 +336,7 @@ void UnlinkMetadataFileOperation::undo()
write_operation->undo(); write_operation->undo();
} }
void SetReadonlyFileOperation::execute(std::unique_lock<std::shared_mutex> & metadata_lock) void SetReadonlyFileOperation::execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock)
{ {
auto metadata = metadata_storage.readMetadataUnlocked(path, metadata_lock); auto metadata = metadata_storage.readMetadataUnlocked(path, metadata_lock);
metadata->setReadOnly(); metadata->setReadOnly();

View File

@ -13,7 +13,7 @@ class IDisk;
struct IMetadataOperation struct IMetadataOperation
{ {
virtual void execute(std::unique_lock<std::shared_mutex> & metadata_lock) = 0; virtual void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) = 0;
virtual void undo() = 0; virtual void undo() = 0;
virtual void finalize() {} virtual void finalize() {}
virtual ~IMetadataOperation() = default; virtual ~IMetadataOperation() = default;
@ -26,7 +26,7 @@ struct SetLastModifiedOperation final : public IMetadataOperation
{ {
SetLastModifiedOperation(const std::string & path_, Poco::Timestamp new_timestamp_, IDisk & disk_); SetLastModifiedOperation(const std::string & path_, Poco::Timestamp new_timestamp_, IDisk & disk_);
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
@ -41,7 +41,7 @@ struct ChmodOperation final : public IMetadataOperation
{ {
ChmodOperation(const std::string & path_, mode_t mode_, IDisk & disk_); ChmodOperation(const std::string & path_, mode_t mode_, IDisk & disk_);
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
@ -57,7 +57,7 @@ struct UnlinkFileOperation final : public IMetadataOperation
{ {
UnlinkFileOperation(const std::string & path_, IDisk & disk_); UnlinkFileOperation(const std::string & path_, IDisk & disk_);
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
@ -72,7 +72,7 @@ struct CreateDirectoryOperation final : public IMetadataOperation
{ {
CreateDirectoryOperation(const std::string & path_, IDisk & disk_); CreateDirectoryOperation(const std::string & path_, IDisk & disk_);
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
@ -86,7 +86,7 @@ struct CreateDirectoryRecursiveOperation final : public IMetadataOperation
{ {
CreateDirectoryRecursiveOperation(const std::string & path_, IDisk & disk_); CreateDirectoryRecursiveOperation(const std::string & path_, IDisk & disk_);
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
@ -101,7 +101,7 @@ struct RemoveDirectoryOperation final : public IMetadataOperation
{ {
RemoveDirectoryOperation(const std::string & path_, IDisk & disk_); RemoveDirectoryOperation(const std::string & path_, IDisk & disk_);
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
@ -114,7 +114,7 @@ struct RemoveRecursiveOperation final : public IMetadataOperation
{ {
RemoveRecursiveOperation(const std::string & path_, IDisk & disk_); RemoveRecursiveOperation(const std::string & path_, IDisk & disk_);
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
@ -130,7 +130,7 @@ struct WriteFileOperation final : public IMetadataOperation
{ {
WriteFileOperation(const std::string & path_, IDisk & disk_, const std::string & data_); WriteFileOperation(const std::string & path_, IDisk & disk_, const std::string & data_);
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
private: private:
@ -149,7 +149,7 @@ struct CreateHardlinkOperation final : public IMetadataOperation
IDisk & disk_, IDisk & disk_,
const MetadataStorageFromDisk & metadata_storage_); const MetadataStorageFromDisk & metadata_storage_);
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
@ -166,7 +166,7 @@ struct MoveFileOperation final : public IMetadataOperation
{ {
MoveFileOperation(const std::string & path_from_, const std::string & path_to_, IDisk & disk_); MoveFileOperation(const std::string & path_from_, const std::string & path_to_, IDisk & disk_);
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
@ -181,7 +181,7 @@ struct MoveDirectoryOperation final : public IMetadataOperation
{ {
MoveDirectoryOperation(const std::string & path_from_, const std::string & path_to_, IDisk & disk_); MoveDirectoryOperation(const std::string & path_from_, const std::string & path_to_, IDisk & disk_);
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
@ -196,7 +196,7 @@ struct ReplaceFileOperation final : public IMetadataOperation
{ {
ReplaceFileOperation(const std::string & path_from_, const std::string & path_to_, IDisk & disk_); ReplaceFileOperation(const std::string & path_from_, const std::string & path_to_, IDisk & disk_);
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
@ -226,7 +226,7 @@ struct AddBlobOperation final : public IMetadataOperation
, metadata_storage(metadata_storage_) , metadata_storage(metadata_storage_)
{} {}
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
@ -254,7 +254,7 @@ struct UnlinkMetadataFileOperation final : public IMetadataOperation
{ {
} }
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;
@ -279,7 +279,7 @@ struct SetReadonlyFileOperation final : public IMetadataOperation
{ {
} }
void execute(std::unique_lock<std::shared_mutex> & metadata_lock) override; void execute(std::unique_lock<DB::FastSharedMutex> & metadata_lock) override;
void undo() override; void undo() override;

View File

@ -729,7 +729,7 @@ DDLGuardPtr DatabaseCatalog::getDDLGuard(const String & database, const String &
return std::make_unique<DDLGuard>(db_guard.first, db_guard.second, std::move(lock), table, database); return std::make_unique<DDLGuard>(db_guard.first, db_guard.second, std::move(lock), table, database);
} }
std::unique_lock<std::shared_mutex> DatabaseCatalog::getExclusiveDDLGuardForDatabase(const String & database) std::unique_lock<DB::FastSharedMutex> DatabaseCatalog::getExclusiveDDLGuardForDatabase(const String & database)
{ {
DDLGuards::iterator db_guard_iter; DDLGuards::iterator db_guard_iter;
{ {
@ -1282,7 +1282,7 @@ TemporaryLockForUUIDDirectory & TemporaryLockForUUIDDirectory::operator = (Tempo
} }
DDLGuard::DDLGuard(Map & map_, std::shared_mutex & db_mutex_, std::unique_lock<std::mutex> guards_lock_, const String & elem, const String & database_name) DDLGuard::DDLGuard(Map & map_, DB::FastSharedMutex & db_mutex_, std::unique_lock<std::mutex> guards_lock_, const String & elem, const String & database_name)
: map(map_), db_mutex(db_mutex_), guards_lock(std::move(guards_lock_)) : map(map_), db_mutex(db_mutex_), guards_lock(std::move(guards_lock_))
{ {
it = map.emplace(elem, Entry{std::make_unique<std::mutex>(), 0}).first; it = map.emplace(elem, Entry{std::make_unique<std::mutex>(), 0}).first;

View File

@ -6,6 +6,7 @@
#include <Databases/TablesDependencyGraph.h> #include <Databases/TablesDependencyGraph.h>
#include <Parsers/IAST_fwd.h> #include <Parsers/IAST_fwd.h>
#include <Storages/IStorage_fwd.h> #include <Storages/IStorage_fwd.h>
#include <Common/Threading.h>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <Poco/Logger.h> #include <Poco/Logger.h>
@ -17,7 +18,6 @@
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <set> #include <set>
#include <shared_mutex>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <filesystem> #include <filesystem>
@ -58,7 +58,7 @@ public:
DDLGuard( DDLGuard(
Map & map_, Map & map_,
std::shared_mutex & db_mutex_, DB::FastSharedMutex & db_mutex_,
std::unique_lock<std::mutex> guards_lock_, std::unique_lock<std::mutex> guards_lock_,
const String & elem, const String & elem,
const String & database_name); const String & database_name);
@ -69,7 +69,7 @@ public:
private: private:
Map & map; Map & map;
std::shared_mutex & db_mutex; DB::FastSharedMutex & db_mutex;
Map::iterator it; Map::iterator it;
std::unique_lock<std::mutex> guards_lock; std::unique_lock<std::mutex> guards_lock;
std::unique_lock<std::mutex> table_lock; std::unique_lock<std::mutex> table_lock;
@ -142,7 +142,7 @@ public:
/// Get an object that protects the table from concurrently executing multiple DDL operations. /// Get an object that protects the table from concurrently executing multiple DDL operations.
DDLGuardPtr getDDLGuard(const String & database, const String & table); DDLGuardPtr getDDLGuard(const String & database, const String & table);
/// Get an object that protects the database from concurrent DDL queries all tables in the database /// Get an object that protects the database from concurrent DDL queries all tables in the database
std::unique_lock<std::shared_mutex> getExclusiveDDLGuardForDatabase(const String & database); std::unique_lock<DB::FastSharedMutex> getExclusiveDDLGuardForDatabase(const String & database);
void assertDatabaseExists(const String & database_name) const; void assertDatabaseExists(const String & database_name) const;
@ -298,7 +298,7 @@ private:
/// For the duration of the operation, an element is placed here, and an object is returned, /// For the duration of the operation, an element is placed here, and an object is returned,
/// which deletes the element in the destructor when counter becomes zero. /// which deletes the element in the destructor when counter becomes zero.
/// In case the element already exists, waits when query will be executed in other thread. See class DDLGuard below. /// In case the element already exists, waits when query will be executed in other thread. See class DDLGuard below.
using DatabaseGuard = std::pair<DDLGuard::Map, std::shared_mutex>; using DatabaseGuard = std::pair<DDLGuard::Map, DB::FastSharedMutex>;
using DDLGuards = std::map<String, DatabaseGuard>; using DDLGuards = std::map<String, DatabaseGuard>;
DDLGuards ddl_guards TSA_GUARDED_BY(ddl_guards_mutex); DDLGuards ddl_guards TSA_GUARDED_BY(ddl_guards_mutex);
/// If you capture mutex and ddl_guards_mutex, then you need to grab them strictly in this order. /// If you capture mutex and ddl_guards_mutex, then you need to grab them strictly in this order.

View File

@ -7,6 +7,7 @@
#include <Core/Block.h> #include <Core/Block.h>
#include <Common/MultiVersion.h> #include <Common/MultiVersion.h>
#include <Common/Threading.h>
#include <mutex> #include <mutex>
@ -130,7 +131,7 @@ private:
TemporaryDataOnDiskPtr tmp_data; TemporaryDataOnDiskPtr tmp_data;
Buckets buckets; Buckets buckets;
mutable std::shared_mutex rehash_mutex; mutable DB::FastSharedMutex rehash_mutex;
FileBucket * current_bucket = nullptr; FileBucket * current_bucket = nullptr;
mutable std::mutex current_bucket_mutex; mutable std::mutex current_bucket_mutex;

View File

@ -7,11 +7,11 @@
#include <IO/WriteBufferFromString.h> #include <IO/WriteBufferFromString.h>
#include <IO/WriteHelpers.h> #include <IO/WriteHelpers.h>
#include <Common/ActionBlocker.h> #include <Common/ActionBlocker.h>
#include <Common/Threading.h>
#include <base/types.h> #include <base/types.h>
#include <atomic> #include <atomic>
#include <map> #include <map>
#include <shared_mutex>
#include <utility> #include <utility>
namespace zkutil namespace zkutil
@ -43,7 +43,7 @@ public:
/// You need to stop the data transfer if blocker is activated. /// You need to stop the data transfer if blocker is activated.
ActionBlocker blocker; ActionBlocker blocker;
std::shared_mutex rwlock; DB::FastSharedMutex rwlock;
}; };
using InterserverIOEndpointPtr = std::shared_ptr<InterserverIOEndpoint>; using InterserverIOEndpointPtr = std::shared_ptr<InterserverIOEndpoint>;

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <shared_mutex> #include <Common/Threading.h>
#include <Common/CacheBase.h> #include <Common/CacheBase.h>
#include <Core/Block.h> #include <Core/Block.h>
#include <Core/SortDescription.h> #include <Core/SortDescription.h>
@ -72,7 +71,7 @@ private:
using Cache = CacheBase<size_t, Block, std::hash<size_t>, BlockByteWeight>; using Cache = CacheBase<size_t, Block, std::hash<size_t>, BlockByteWeight>;
mutable std::shared_mutex rwlock; mutable DB::FastSharedMutex rwlock;
std::shared_ptr<TableJoin> table_join; std::shared_ptr<TableJoin> table_join;
SizeLimits size_limits; SizeLimits size_limits;
SortDescription left_sort_description; SortDescription left_sort_description;

View File

@ -19,13 +19,13 @@
#include <Common/Stopwatch.h> #include <Common/Stopwatch.h>
#include <Common/Throttler.h> #include <Common/Throttler.h>
#include <Common/OvercommitTracker.h> #include <Common/OvercommitTracker.h>
#include <Common/Threading.h>
#include <condition_variable> #include <condition_variable>
#include <list> #include <list>
#include <map> #include <map>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <shared_mutex>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>

View File

@ -176,7 +176,7 @@ bool Set::insertFromBlock(const ColumnsWithTypeAndName & columns)
bool Set::insertFromBlock(const Columns & columns) bool Set::insertFromBlock(const Columns & columns)
{ {
std::lock_guard<std::shared_mutex> lock(rwlock); std::lock_guard lock(rwlock);
if (data.empty()) if (data.empty())
throw Exception("Method Set::setHeader must be called before Set::insertFromBlock", ErrorCodes::LOGICAL_ERROR); throw Exception("Method Set::setHeader must be called before Set::insertFromBlock", ErrorCodes::LOGICAL_ERROR);

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <shared_mutex>
#include <Core/Block.h> #include <Core/Block.h>
#include <QueryPipeline/SizeLimits.h> #include <QueryPipeline/SizeLimits.h>
#include <DataTypes/IDataType.h> #include <DataTypes/IDataType.h>
@ -8,6 +7,7 @@
#include <Parsers/IAST.h> #include <Parsers/IAST.h>
#include <Storages/MergeTree/BoolMask.h> #include <Storages/MergeTree/BoolMask.h>
#include <Common/Threading.h>
#include <Common/logger_useful.h> #include <Common/logger_useful.h>
@ -131,7 +131,7 @@ private:
/** Protects work with the set in the functions `insertFromBlock` and `execute`. /** Protects work with the set in the functions `insertFromBlock` and `execute`.
* These functions can be called simultaneously from different threads only when using StorageSet, * These functions can be called simultaneously from different threads only when using StorageSet,
*/ */
mutable std::shared_mutex rwlock; mutable DB::FastSharedMutex rwlock;
template <typename Method> template <typename Method>
void insertFromBlockImpl( void insertFromBlockImpl(

View File

@ -17,9 +17,9 @@
#include <Common/Exception.h> #include <Common/Exception.h>
#include <Common/RWLock.h> #include <Common/RWLock.h>
#include <Common/TypePromotion.h> #include <Common/TypePromotion.h>
#include <Common/Threading.h>
#include <optional> #include <optional>
#include <shared_mutex>
#include <compare> #include <compare>

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "IO/WriteSettings.h" #include <Common/Threading.h>
#include <IO/WriteSettings.h>
#include <Core/Block.h> #include <Core/Block.h>
#include <base/types.h> #include <base/types.h>
#include <Core/NamesAndTypes.h> #include <Core/NamesAndTypes.h>
@ -22,8 +23,6 @@
#include <DataTypes/Serializations/SerializationInfo.h> #include <DataTypes/Serializations/SerializationInfo.h>
#include <Storages/MergeTree/IPartMetadataManager.h> #include <Storages/MergeTree/IPartMetadataManager.h>
#include <shared_mutex>
namespace zkutil namespace zkutil
{ {

View File

@ -1086,7 +1086,7 @@ protected:
MultiVersion<MergeTreeSettings> storage_settings; MultiVersion<MergeTreeSettings> storage_settings;
/// Used to determine which UUIDs to send to root query executor for deduplication. /// Used to determine which UUIDs to send to root query executor for deduplication.
mutable std::shared_mutex pinned_part_uuids_mutex; mutable DB::FastSharedMutex pinned_part_uuids_mutex;
PinnedPartUUIDsPtr pinned_part_uuids; PinnedPartUUIDsPtr pinned_part_uuids;
/// True if at least one part was created/removed with transaction. /// True if at least one part was created/removed with transaction.

View File

@ -25,6 +25,7 @@
#include <Poco/Util/AbstractConfiguration.h> #include <Poco/Util/AbstractConfiguration.h>
#include <Common/logger_useful.h> #include <Common/logger_useful.h>
#include <Common/Exception.h> #include <Common/Exception.h>
#include <Common/Threading.h>
#include <base/sort.h> #include <base/sort.h>
#include <rocksdb/table.h> #include <rocksdb/table.h>
@ -33,7 +34,6 @@
#include <cstddef> #include <cstddef>
#include <filesystem> #include <filesystem>
#include <shared_mutex>
#include <utility> #include <utility>
@ -491,7 +491,7 @@ static StoragePtr create(const StorageFactory::Arguments & args)
std::shared_ptr<rocksdb::Statistics> StorageEmbeddedRocksDB::getRocksDBStatistics() const std::shared_ptr<rocksdb::Statistics> StorageEmbeddedRocksDB::getRocksDBStatistics() const
{ {
std::shared_lock<std::shared_mutex> lock(rocksdb_ptr_mx); std::shared_lock lock(rocksdb_ptr_mx);
if (!rocksdb_ptr) if (!rocksdb_ptr)
return nullptr; return nullptr;
return rocksdb_ptr->GetOptions().statistics; return rocksdb_ptr->GetOptions().statistics;
@ -499,7 +499,7 @@ std::shared_ptr<rocksdb::Statistics> StorageEmbeddedRocksDB::getRocksDBStatistic
std::vector<rocksdb::Status> StorageEmbeddedRocksDB::multiGet(const std::vector<rocksdb::Slice> & slices_keys, std::vector<String> & values) const std::vector<rocksdb::Status> StorageEmbeddedRocksDB::multiGet(const std::vector<rocksdb::Slice> & slices_keys, std::vector<String> & values) const
{ {
std::shared_lock<std::shared_mutex> lock(rocksdb_ptr_mx); std::shared_lock lock(rocksdb_ptr_mx);
if (!rocksdb_ptr) if (!rocksdb_ptr)
return {}; return {};
return rocksdb_ptr->MultiGet(rocksdb::ReadOptions(), slices_keys, &values); return rocksdb_ptr->MultiGet(rocksdb::ReadOptions(), slices_keys, &values);

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <shared_mutex> #include <Common/Threading.h>
#include <Storages/IStorage.h> #include <Storages/IStorage.h>
#include <Interpreters/IKeyValueEntity.h> #include <Interpreters/IKeyValueEntity.h>
#include <rocksdb/status.h> #include <rocksdb/status.h>
@ -86,7 +86,7 @@ private:
const String primary_key; const String primary_key;
using RocksDBPtr = std::unique_ptr<rocksdb::DB>; using RocksDBPtr = std::unique_ptr<rocksdb::DB>;
RocksDBPtr rocksdb_ptr; RocksDBPtr rocksdb_ptr;
mutable std::shared_mutex rocksdb_ptr_mx; mutable DB::FastSharedMutex rocksdb_ptr_mx;
String rocksdb_dir; String rocksdb_dir;
Int32 ttl; Int32 ttl;
bool read_only; bool read_only;

View File

@ -3,10 +3,10 @@
#include <Storages/IStorage.h> #include <Storages/IStorage.h>
#include <Storages/Cache/SchemaCache.h> #include <Storages/Cache/SchemaCache.h>
#include <Common/Threading.h>
#include <Common/logger_useful.h> #include <Common/logger_useful.h>
#include <atomic> #include <atomic>
#include <shared_mutex>
namespace DB namespace DB

View File

@ -1,15 +1,14 @@
#pragma once #pragma once
#include <map> #include <map>
#include <shared_mutex>
#include <Disks/IDisk.h> #include <Disks/IDisk.h>
#include <Storages/IStorage.h> #include <Storages/IStorage.h>
#include <Common/FileChecker.h> #include <Common/FileChecker.h>
#include <Common/Threading.h>
#include <Common/escapeForFileName.h> #include <Common/escapeForFileName.h>
#include <Core/NamesAndTypes.h> #include <Core/NamesAndTypes.h>
namespace DB namespace DB
{ {

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include <map> #include <map>
#include <shared_mutex>
#include <Core/Defines.h> #include <Core/Defines.h>
#include <Storages/IStorage.h> #include <Storages/IStorage.h>
#include <Formats/IndexForNativeFormat.h> #include <Formats/IndexForNativeFormat.h>
#include <Common/Threading.h>
#include <Common/FileChecker.h> #include <Common/FileChecker.h>
#include <Common/escapeForFileName.h> #include <Common/escapeForFileName.h>
#include <Disks/IDisk.h> #include <Disks/IDisk.h>

View File

@ -1443,11 +1443,11 @@ void StorageWindowView::writeIntoWindowView(
}); });
} }
std::shared_lock<std::shared_mutex> fire_signal_lock; std::shared_lock<DB::FastSharedMutex> fire_signal_lock;
QueryPipelineBuilder builder; QueryPipelineBuilder builder;
if (window_view.is_proctime) if (window_view.is_proctime)
{ {
fire_signal_lock = std::shared_lock<std::shared_mutex>(window_view.fire_signal_mutex); fire_signal_lock = std::shared_lock(window_view.fire_signal_mutex);
/// Fill ____timestamp column with current time in case of now() time column. /// Fill ____timestamp column with current time in case of now() time column.
if (window_view.is_time_column_func_now) if (window_view.is_time_column_func_now)

View File

@ -213,7 +213,7 @@ private:
/// Mutex for the blocks and ready condition /// Mutex for the blocks and ready condition
std::mutex mutex; std::mutex mutex;
std::shared_mutex fire_signal_mutex; DB::FastSharedMutex fire_signal_mutex;
mutable std::mutex sample_block_lock; /// Mutex to protect access to sample block mutable std::mutex sample_block_lock; /// Mutex to protect access to sample block
IntervalKind::Kind window_kind; IntervalKind::Kind window_kind;