Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate mutex that protects blocked stream consumers #1471

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "server.h"

#include <fcntl.h>
#include <glog/logging.h>
#include <rocksdb/convenience.h>
#include <rocksdb/statistics.h>
Expand All @@ -41,14 +40,12 @@
#include "fmt/format.h"
#include "lua.h"
#include "redis_connection.h"
#include "redis_request.h"
#include "storage/compaction_checker.h"
#include "storage/redis_db.h"
#include "storage/scripting.h"
#include "string_util.h"
#include "thread_util.h"
#include "time_util.h"
#include "tls_util.h"
#include "version.h"
#include "worker.h"

Expand Down Expand Up @@ -529,7 +526,7 @@ void Server::UnblockOnKey(const std::string &key, redis::Connection *conn) {

void Server::BlockOnStreams(const std::vector<std::string> &keys, const std::vector<redis::StreamEntryID> &entry_ids,
redis::Connection *conn) {
std::lock_guard<std::mutex> guard(blocking_keys_mu_);
std::lock_guard<std::mutex> guard(blocked_stream_consumers_mu_);

IncrBlockedClientNum();

Expand All @@ -546,7 +543,7 @@ void Server::BlockOnStreams(const std::vector<std::string> &keys, const std::vec
}

void Server::UnblockOnStreams(const std::vector<std::string> &keys, redis::Connection *conn) {
std::lock_guard<std::mutex> guard(blocking_keys_mu_);
std::lock_guard<std::mutex> guard(blocked_stream_consumers_mu_);

DecrBlockedClientNum();

Expand Down Expand Up @@ -590,7 +587,7 @@ void Server::WakeupBlockingConns(const std::string &key, size_t n_conns) {
}

void Server::OnEntryAddedToStream(const std::string &ns, const std::string &key, const redis::StreamEntryID &entry_id) {
std::lock_guard<std::mutex> guard(blocking_keys_mu_);
std::lock_guard<std::mutex> guard(blocked_stream_consumers_mu_);

auto iter = blocked_stream_consumers_.find(key);
if (iter == blocked_stream_consumers_.end() || iter->second.empty()) {
Expand Down
3 changes: 3 additions & 0 deletions src/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ class Server {
std::mutex pubsub_channels_mu_;
std::map<std::string, std::list<ConnContext *>> blocking_keys_;
std::mutex blocking_keys_mu_;

std::atomic<int> blocked_clients_{0};

std::mutex blocked_stream_consumers_mu_;
std::map<std::string, std::set<std::shared_ptr<StreamConsumer>>> blocked_stream_consumers_;

// threads
Expand Down