Skip to content

Commit

Permalink
fix: display real replica remote address in INFO logs
Browse files Browse the repository at this point in the history
  • Loading branch information
romange committed Aug 22, 2024
1 parent f74c131 commit 1f74fc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
18 changes: 10 additions & 8 deletions src/server/dflycmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ bool WaitReplicaFlowToCatchup(absl::Time end_time, const DflyCmd::ReplicaInfo* r
const FlowInfo* flow = &replica->flows[shard->shard_id()];
while (flow->last_acked_lsn < shard->journal()->GetLsn()) {
if (absl::Now() > end_time) {
LOG(WARNING) << "Couldn't synchronize with replica for takeover in time: " << replica->address
<< ":" << replica->listening_port << ", last acked: " << flow->last_acked_lsn
<< ", expecting " << shard->journal()->GetLsn();
LOG(WARNING) << "Couldn't synchronize with replica for takeover in time: "
<< replica->remote_address << ":" << replica->listening_port
<< ", last acked: " << flow->last_acked_lsn << ", expecting "
<< shard->journal()->GetLsn();
return false;
}
if (replica->cntx.IsCancelled()) {
Expand Down Expand Up @@ -321,7 +322,7 @@ void DflyCmd::Sync(CmdArgList args, ConnectionContext* cntx) {
return cntx->SendError(kInvalidState);
}

LOG(INFO) << "Started sync with replica " << replica_ptr->address << ":"
LOG(INFO) << "Started sync with replica " << replica_ptr->remote_address << ":"
<< replica_ptr->listening_port;

// protected by lk above.
Expand Down Expand Up @@ -359,7 +360,7 @@ void DflyCmd::StartStable(CmdArgList args, ConnectionContext* cntx) {
return cntx->SendError(kInvalidState);
}

LOG(INFO) << "Transitioned into stable sync with replica " << replica_ptr->address << ":"
LOG(INFO) << "Transitioned into stable sync with replica " << replica_ptr->remote_address << ":"
<< replica_ptr->listening_port;

replica_ptr->replica_state = SyncState::STABLE_SYNC;
Expand Down Expand Up @@ -603,12 +604,13 @@ auto DflyCmd::CreateSyncSession(ConnectionContext* cntx)
};

string address = cntx->conn_state.replication_info.repl_ip_address;
string remote_address = cntx->conn()->RemoteEndpointAddress();
uint32_t port = cntx->conn_state.replication_info.repl_listening_port;

LOG(INFO) << "Registered replica " << address << ":" << port;
LOG(INFO) << "Registered replica " << remote_address << ":" << port;

auto replica_ptr =
make_shared<ReplicaInfo>(flow_count, std::move(address), port, std::move(err_handler));
auto replica_ptr = make_shared<ReplicaInfo>(
flow_count, std::move(address), std::move(remote_address), port, std::move(err_handler));
auto [it, inserted] = replica_infos_.emplace(sync_id, std::move(replica_ptr));
CHECK(inserted);

Expand Down
7 changes: 4 additions & 3 deletions src/server/dflycmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ class DflyCmd {

// Stores information related to a single replica.
struct ReplicaInfo {
ReplicaInfo(unsigned flow_count, std::string address, uint32_t listening_port,
Context::ErrHandler err_handler)
ReplicaInfo(unsigned flow_count, std::string address, std::string remote_addr,
uint32_t listening_port, Context::ErrHandler err_handler)
: replica_state{SyncState::PREPARATION},
cntx{std::move(err_handler)},
address{std::move(address)},
remote_address(std::move(remote_addr)),
listening_port(listening_port),
flows{flow_count} {
}
Expand All @@ -126,7 +127,7 @@ class DflyCmd {
Context cntx;

std::string id;
std::string address;
std::string address, remote_address;
uint32_t listening_port;
DflyVersion version = DflyVersion::VER0;

Expand Down

0 comments on commit 1f74fc2

Please sign in to comment.