| 115 | } |
| 116 | |
| 117 | void ReplicateNode::SyncData() { |
| 118 | uint32_t coffee_time = 0; |
| 119 | while (is_running_.load(std::memory_order_relaxed)) { |
| 120 | if (coffee_time > 0) { |
| 121 | bthread_usleep(coffee_time * 1000); |
| 122 | coffee_time = 0; |
| 123 | } |
| 124 | { |
| 125 | std::unique_lock<bthread::Mutex> lock(*mu_); |
| 126 | // no new data append and wait |
| 127 | while (last_sync_offset_ >= |
| 128 | leader_log_offset_->load(std::memory_order_relaxed)) { |
| 129 | cv_->wait_for(lock, FLAGS_binlog_sync_wait_time * 1000); |
| 130 | if (!is_running_.load(std::memory_order_relaxed)) { |
| 131 | PDLOG(INFO, |
| 132 | "replicate log to endpoint %s for table #tid %u #pid " |
| 133 | "%u exist", |
| 134 | endpoint_.c_str(), tid_, pid_); |
| 135 | return; |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | int ret; |
| 140 | if (rep_node_.load(std::memory_order_relaxed)) { |
| 141 | ret = SyncData(follower_offset_->load(std::memory_order_relaxed)); |
| 142 | } else { |
| 143 | ret = SyncData(leader_log_offset_->load(std::memory_order_relaxed)); |
| 144 | } |
| 145 | if (ret == 1) { |
| 146 | coffee_time = FLAGS_binlog_coffee_time; |
| 147 | } |
| 148 | } |
| 149 | PDLOG(INFO, "replicate log to endpoint %s for table #tid %u #pid %u exist", |
| 150 | endpoint_.c_str(), tid_, pid_); |
| 151 | } |
| 152 | |
| 153 | int ReplicateNode::GetLogIndex() { return log_reader_.GetLogIndex(); } |
| 154 |
no test coverage detected