Skip to content

Commit

Permalink
fix data race error
Browse files Browse the repository at this point in the history
  • Loading branch information
AntiTopQuark committed Sep 5, 2024
1 parent eb96c7b commit 2781747
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cluster/replication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void FeedSlaveThread::loop() {
// first batch here to work around this issue instead of waiting for enough batch size.
bool is_first_repl_batch = true;
uint32_t yield_microseconds = 2 * 1000;
std::string &batches_bulk = conn_->GetOutputBuffer();
std::string &batches_bulk = conn_->GetSlaveOutputBuffer();
batches_bulk.clear();
size_t updates_in_batches = 0;
while (!IsStopped()) {
Expand Down
6 changes: 4 additions & 2 deletions src/server/redis_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Connection::Connection(bufferevent *bev, Worker *owner)
create_time_ = now;
last_interaction_ = now;
output_buffer_.clear();
slave_output_buffer_.clear();
}

Connection::~Connection() {
Expand Down Expand Up @@ -369,9 +370,9 @@ static bool IsCmdForIndexing(const CommandAttributes *attr) {
}

void Connection::ExecuteCommands(std::deque<CommandTokens> *to_process_cmds) {
output_buffer_.clear();
GetOutputBuffer().clear();
const Config *config = srv_->GetConfig();
std::string &reply = output_buffer_;
std::string &reply = GetOutputBuffer();
std::string password = config->requirepass;

while (!to_process_cmds->empty()) {
Expand Down Expand Up @@ -571,6 +572,7 @@ size_t Connection::GetConnectionMemoryUsed() const {
total_memory += addr_.capacity();
total_memory += last_cmd_.capacity();
total_memory += output_buffer_.capacity();
total_memory += slave_output_buffer_.capacity();
total_memory += evbuffer_get_length(Output()) + evbuffer_get_length(Input());

for (const auto &channel : subscribe_channels_) {
Expand Down
2 changes: 2 additions & 0 deletions src/server/redis_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class Connection : public EvbufCallbackBase<Connection> {
std::atomic<bool> watched_keys_modified = false;

inline std::string &GetOutputBuffer() { return output_buffer_; }
inline std::string &GetSlaveOutputBuffer() { return slave_output_buffer_; }
size_t GetConnectionMemoryUsed() const;

private:
Expand Down Expand Up @@ -219,6 +220,7 @@ class Connection : public EvbufCallbackBase<Connection> {
bool importing_ = false;
RESP protocol_version_ = RESP::v2;
std::string output_buffer_;
std::string slave_output_buffer_;
};

} // namespace redis

0 comments on commit 2781747

Please sign in to comment.