Skip to content

Commit

Permalink
remove an unnecessary shared_lock in a hot path(every request will co…
Browse files Browse the repository at this point in the history
…nduct this unnecessary lock) (OpenAtomFoundation#2773)

Co-authored-by: cheniujh <[email protected]>
  • Loading branch information
cheniujh and cheniujh authored Jul 3, 2024
1 parent 86b6e7e commit 02fdfd5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/pika_binlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Binlog : public pstd::noncopyable {
void Unlock() { mutex_.unlock(); }

pstd::Status Put(const std::string& item);

pstd::Status IsOpened();
pstd::Status GetProducerStatus(uint32_t* filenum, uint64_t* pro_offset, uint32_t* term = nullptr, uint64_t* logic_id = nullptr);
/*
* Set Producer pro_num and pro_offset with lock
Expand Down
7 changes: 7 additions & 0 deletions src/pika_binlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ void Binlog::InitLogFile() {
opened_.store(true);
}

Status Binlog::IsOpened() {
if (!opened_.load()) {
return Status::Busy("Binlog is not open yet");
}
return Status::OK();
}

Status Binlog::GetProducerStatus(uint32_t* filenum, uint64_t* pro_offset, uint32_t* term, uint64_t* logic_id) {
if (!opened_.load()) {
return Status::Busy("Binlog is not open yet");
Expand Down
4 changes: 1 addition & 3 deletions src/pika_consensus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,7 @@ Status ConsensusCoordinator::InternalAppendBinlog(const std::shared_ptr<Cmd>& cm
}
return s;
}
uint32_t filenum = 0;
uint64_t offset = 0;
return stable_logger_->Logger()->GetProducerStatus(&filenum, &offset);
return stable_logger_->Logger()->IsOpened();
}

Status ConsensusCoordinator::AddSlaveNode(const std::string& ip, int port, int session_id) {
Expand Down

0 comments on commit 02fdfd5

Please sign in to comment.