| 745 | } |
| 746 | |
| 747 | void Server::WakeupWaitConnections(rocksdb::SequenceNumber seq) { |
| 748 | std::unique_lock<std::shared_mutex> guard(wait_contexts_mu_); |
| 749 | |
| 750 | // find the last entry with target_seq > seq, which cannot wakeup |
| 751 | auto end_it = wait_contexts_.upper_bound(seq); |
| 752 | for (auto it = wait_contexts_.begin(); it != end_it;) { |
| 753 | // Count how many replicas have reached the target sequence |
| 754 | size_t reached_replicas = GetReplicasReachedSequence(it->second.target_seq); |
| 755 | |
| 756 | // If enough replicas have reached the target sequence, wake up the connection |
| 757 | if (reached_replicas >= it->second.num_replicas) { |
| 758 | // Send the response with the number of replicas that have reached the target sequence |
| 759 | it->second.conn->Reply(redis::Integer(reached_replicas)); |
| 760 | |
| 761 | auto s = it->second.conn->Owner()->EnableWriteEvent(it->second.conn->GetFD()); |
| 762 | if (!s.IsOK()) { |
| 763 | ERROR("[server] Failed to enable write event on WAIT connection {}: {}", it->second.conn->GetFD(), s.Msg()); |
| 764 | } |
| 765 | it = wait_contexts_.erase(it); |
| 766 | DecrBlockedClientNum(); |
| 767 | continue; |
| 768 | } |
| 769 | ++it; |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | void Server::WakeupWaitConnection(redis::Connection *conn, rocksdb::SequenceNumber seq) { |
| 774 | std::unique_lock<std::shared_mutex> guard(wait_contexts_mu_); |
no test coverage detected