From b3b9080901e5e97cfcb528fd54e7f4330fc59bd3 Mon Sep 17 00:00:00 2001 From: Roman Gershman Date: Mon, 12 Feb 2024 16:29:28 +0200 Subject: [PATCH] chore: fix fiber types in the codebase (#2574) Reduce reliance on core/fibers Signed-off-by: Roman Gershman --- src/core/fibers.h | 11 ----------- src/facade/dragonfly_connection.h | 4 ++-- src/server/acl/user_registry.cc | 20 +++++++++++--------- src/server/acl/user_registry.h | 13 ++++++------- src/server/engine_shard_set.h | 8 ++++---- src/server/io_utils.h | 6 +++--- src/server/journal/journal_slice.h | 2 +- src/server/journal/tx_executor.h | 4 ++-- src/server/replica.h | 9 +++++---- src/server/server_family.cc | 8 ++++---- src/server/server_family.h | 8 ++++---- src/server/server_state.h | 2 +- src/server/transaction.h | 4 ++-- 13 files changed, 45 insertions(+), 54 deletions(-) diff --git a/src/core/fibers.h b/src/core/fibers.h index 8a3dc314e..71adc2b36 100644 --- a/src/core/fibers.h +++ b/src/core/fibers.h @@ -12,20 +12,9 @@ namespace dfly { -using util::fb2::Barrier; -using util::fb2::BlockingCounter; -using util::fb2::CondVar; -using util::fb2::Done; -using util::fb2::EventCount; using util::fb2::Fiber; -using util::fb2::Future; using util::fb2::Launch; using util::fb2::Mutex; -using util::fb2::Promise; using util::fb2::SimpleChannel; } // namespace dfly - -namespace util { -using fb2::SharedMutex; -} diff --git a/src/facade/dragonfly_connection.h b/src/facade/dragonfly_connection.h index e730a91a7..e3168768b 100644 --- a/src/facade/dragonfly_connection.h +++ b/src/facade/dragonfly_connection.h @@ -308,7 +308,7 @@ class Connection : public util::Connection { // Block until memory usage is below limit, can be called from any thread void EnsureBelowLimit(); - dfly::EventCount ec; + util::fb2::EventCount ec; std::atomic_size_t subscriber_bytes = 0; size_t subscriber_thread_limit = 0; // cached flag subscriber_thread_limit @@ -377,7 +377,7 @@ class Connection : public util::Connection { void DecreaseStatsOnClose(); std::deque dispatch_q_; // dispatch queue - dfly::EventCount evc_; // dispatch queue waker + util::fb2::EventCount evc_; // dispatch queue waker util::fb2::Fiber dispatch_fb_; // dispatch fiber (if started) size_t pending_pipeline_cmd_cnt_ = 0; // how many queued async commands in dispatch_q diff --git a/src/server/acl/user_registry.cc b/src/server/acl/user_registry.cc index 52c14aecd..653c379e5 100644 --- a/src/server/acl/user_registry.cc +++ b/src/server/acl/user_registry.cc @@ -14,21 +14,23 @@ ABSL_DECLARE_FLAG(std::string, requirepass); +using namespace util; + namespace dfly::acl { void UserRegistry::MaybeAddAndUpdate(std::string_view username, User::UpdateRequest req) { - std::unique_lock lock(mu_); + std::unique_lock lock(mu_); auto& user = registry_[username]; user.Update(std::move(req)); } bool UserRegistry::RemoveUser(std::string_view username) { - std::unique_lock lock(mu_); + std::unique_lock lock(mu_); return registry_.erase(username); } UserRegistry::UserCredentials UserRegistry::GetCredentials(std::string_view username) const { - std::shared_lock lock(mu_); + std::shared_lock lock(mu_); auto it = registry_.find(username); if (it == registry_.end()) { return {}; @@ -37,7 +39,7 @@ UserRegistry::UserCredentials UserRegistry::GetCredentials(std::string_view user } bool UserRegistry::IsUserActive(std::string_view username) const { - std::shared_lock lock(mu_); + std::shared_lock lock(mu_); auto it = registry_.find(username); if (it == registry_.end()) { return false; @@ -46,7 +48,7 @@ bool UserRegistry::IsUserActive(std::string_view username) const { } bool UserRegistry::AuthUser(std::string_view username, std::string_view password) const { - std::shared_lock lock(mu_); + std::shared_lock lock(mu_); const auto& user = registry_.find(username); if (user == registry_.end()) { return false; @@ -56,23 +58,23 @@ bool UserRegistry::AuthUser(std::string_view username, std::string_view password } UserRegistry::RegistryViewWithLock UserRegistry::GetRegistryWithLock() const { - std::shared_lock lock(mu_); + std::shared_lock lock(mu_); return {std::move(lock), registry_}; } UserRegistry::RegistryWithWriteLock UserRegistry::GetRegistryWithWriteLock() { - std::unique_lock lock(mu_); + std::unique_lock lock(mu_); return {std::move(lock), registry_}; } -UserRegistry::UserWithWriteLock::UserWithWriteLock(std::unique_lock lk, +UserRegistry::UserWithWriteLock::UserWithWriteLock(std::unique_lock lk, const User& user, bool exists) : user(user), exists(exists), registry_lk_(std::move(lk)) { } UserRegistry::UserWithWriteLock UserRegistry::MaybeAddAndUpdateWithLock(std::string_view username, User::UpdateRequest req) { - std::unique_lock lock(mu_); + std::unique_lock lock(mu_); const bool exists = registry_.contains(username); auto& user = registry_[username]; user.Update(std::move(req)); diff --git a/src/server/acl/user_registry.h b/src/server/acl/user_registry.h index bd4cba4b2..a9ce519c2 100644 --- a/src/server/acl/user_registry.h +++ b/src/server/acl/user_registry.h @@ -5,7 +5,6 @@ #pragma once #include -#include #include #include @@ -13,8 +12,8 @@ #include #include -#include "core/fibers.h" #include "server/acl/user.h" +#include "util/fibers/synchronization.h" namespace dfly::acl { @@ -70,12 +69,12 @@ class UserRegistry { // Helper class for accessing a user with a ReadLock outside the scope of UserRegistry class UserWithWriteLock { public: - UserWithWriteLock(std::unique_lock lk, const User& user, bool exists); + UserWithWriteLock(std::unique_lock lk, const User& user, bool exists); const User& user; const bool exists; private: - std::unique_lock registry_lk_; + std::unique_lock registry_lk_; }; UserWithWriteLock MaybeAddAndUpdateWithLock(std::string_view username, User::UpdateRequest req); @@ -84,18 +83,18 @@ class UserRegistry { private: RegistryType registry_; - mutable util::SharedMutex mu_; + mutable util::fb2::SharedMutex mu_; // Helper class for accessing the registry with a ReadLock outside the scope of UserRegistry template