Skip to content

Commit f45a0bd

Browse files
authored
chore: add more logs for takeover (#5765)
1 parent 5a9a94b commit f45a0bd

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/server/dflycmd.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ bool WaitReplicaFlowToCatchup(absl::Time end_time, const DflyCmd::ReplicaInfo* r
8585
shard->journal()->RecordEntry(0, journal::Op::PING, 0, 0, nullopt, {});
8686

8787
const FlowInfo* flow = &replica->flows[shard->shard_id()];
88+
8889
while (flow->last_acked_lsn < shard->journal()->GetLsn()) {
8990
if (absl::Now() > end_time) {
9091
LOG(WARNING) << "Couldn't synchronize with replica for takeover in time: " << replica->address
@@ -95,8 +96,9 @@ bool WaitReplicaFlowToCatchup(absl::Time end_time, const DflyCmd::ReplicaInfo* r
9596
if (!replica->exec_st.IsRunning()) {
9697
return false;
9798
}
98-
VLOG(1) << "Replica lsn:" << flow->last_acked_lsn
99-
<< " master lsn:" << shard->journal()->GetLsn();
99+
LOG_EVERY_T(INFO, 1) << "Replica lsn:" << flow->last_acked_lsn
100+
<< " master lsn:" << shard->journal()->GetLsn()
101+
<< "; Journal streamer state: " << flow->streamer->FormatInternalState();
100102
ThisFiber::SleepFor(1ms);
101103
}
102104

@@ -512,7 +514,7 @@ void DflyCmd::TakeOver(CmdArgList args, RedisReplyBuilder* rb, ConnectionContext
512514
atomic_bool catchup_success = true;
513515
if (*status == OpStatus::OK) {
514516
dfly::SharedLock lk{replica_ptr->shared_mu};
515-
auto cb = [replica_ptr, end_time, &catchup_success](EngineShard* shard) {
517+
auto cb = [replica_ptr = replica_ptr, end_time, &catchup_success](EngineShard* shard) {
516518
if (!WaitReplicaFlowToCatchup(end_time, replica_ptr.get(), shard)) {
517519
catchup_success.store(false);
518520
}

src/server/journal/streamer.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ size_t JournalStreamer::UsedBytes() const {
164164
return pending_buf_.Size();
165165
}
166166

167+
std::string JournalStreamer::FormatInternalState() const {
168+
return absl::StrCat(
169+
"pending_buf_size:", pending_buf_.Size(), " in_flight_bytes:", in_flight_bytes_,
170+
" total_sent:", total_sent_, " throttle_count:", throttle_count_,
171+
" total_throttle_wait_usec:", total_throttle_wait_usec_,
172+
" throttle_waiters:", throttle_waiters_, " last_async_write_time_ms:", last_async_write_time_,
173+
" last_lsn_time_s:", last_lsn_time_, " last_lsn_writen_:", last_lsn_writen_);
174+
}
175+
167176
void JournalStreamer::Write(std::string str) {
168177
DCHECK(!str.empty());
169178
DVLOG(3) << "Writing " << str.size() << " bytes";

src/server/journal/streamer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class JournalStreamer : public journal::JournalConsumerInterface {
3636

3737
size_t UsedBytes() const;
3838

39+
// For debugging purposes. Return string with formatted internal state.
40+
std::string FormatInternalState() const;
41+
3942
protected:
4043
// TODO: we copy the string on each write because JournalItem may be passed to multiple
4144
// streamers so we can not move it. However, if we would either wrap JournalItem in shared_ptr

0 commit comments

Comments
 (0)