Skip to content

Commit 51284b8

Browse files
committed
[SR]: Expand printed details in PassiveDM::operator<<
Include details of the trackedWrites and high prepared/completed seqnos in debug output of PassiveDM. Change-Id: Icf9ed52ef5ac911b78b38d9db65c4326452f6bcb Reviewed-on: http://review.couchbase.org/112698 Tested-by: Build Bot <[email protected]> Reviewed-by: Ben Huddleston <[email protected]>
1 parent 2d81f46 commit 51284b8

File tree

6 files changed

+69
-22
lines changed

6 files changed

+69
-22
lines changed

engines/ep/src/durability/active_durability_monitor.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ void ActiveDurabilityMonitor::toOStream(std::ostream& os) const {
11341134
} else {
11351135
os << "<null>";
11361136
}
1137+
os << "\n";
11371138
}
11381139

11391140
void ActiveDurabilityMonitor::chainToOstream(
@@ -1144,15 +1145,8 @@ void ActiveDurabilityMonitor::chainToOstream(
11441145
<< " majority:" << int(rc.majority) << " active:" << rc.active
11451146
<< " maxAllowedReplicas:" << rc.maxAllowedReplicas << " positions:[\n";
11461147
for (const auto& pos : rc.positions) {
1147-
os << " " << pos.first << ": {lastAck:" << pos.second.lastAckSeqno
1148-
<< " lastWrite:" << pos.second.lastWriteSeqno << " it: @"
1149-
<< &*pos.second.it;
1150-
if (pos.second.it == trackedWritesEnd) {
1151-
os << " <end>";
1152-
} else {
1153-
os << " seqno:" << pos.second.it->getBySeqno();
1154-
}
1155-
os << "\n";
1148+
os << " " << pos.first << ": "
1149+
<< to_string(pos.second, trackedWritesEnd) << "\n";
11561150
}
11571151
os << "]";
11581152
}

engines/ep/src/durability/durability_monitor.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ class DurabilityMonitor {
8888
const DurabilityMonitor& dm);
8989

9090
friend std::ostream& operator<<(std::ostream&, const SyncWrite&);
91+
92+
/** Return a string representation of the given Position.
93+
*
94+
* @param pos
95+
* @param trackedWritesEnd Iterator pointing at the end() of the
96+
* trackedWrites container this Position references. Used to check
97+
* if Position is at end and print appropiate info.
98+
*/
99+
friend std::string to_string(const DurabilityMonitor::Position& pos,
100+
Container::const_iterator trackedWritesEnd);
91101
};
92102

93103
std::string to_string(DurabilityMonitor::ReplicationChainName name);

engines/ep/src/durability/durability_monitor_impl.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,14 @@ DurabilityMonitor::ReplicationChain::ReplicationChain(
298298
continue;
299299
}
300300
// This check ensures that there is no duplicate in the given chain
301-
if (!positions.emplace(node, Position(it)).second) {
301+
auto result = positions.emplace(node, Position(it));
302+
if (!result.second) {
302303
throw std::invalid_argument(
303304
"ReplicationChain::ReplicationChain: Duplicate node: " +
304305
node);
305306
}
307+
result.first->second.lastAckSeqno.setLabel(node + "::lastAckSeqno");
308+
result.first->second.lastWriteSeqno.setLabel(node + "::lastWriteSeqno");
306309
}
307310
}
308311

@@ -352,3 +355,20 @@ std::string to_string(const SnapshotEndInfo& snapshotEndInfo) {
352355
return std::to_string(snapshotEndInfo.seqno) + "{" +
353356
to_string(snapshotEndInfo.type) + "}";
354357
}
358+
359+
std::string to_string(
360+
const DurabilityMonitor::Position& pos,
361+
std::list<DurabilityMonitor::SyncWrite,
362+
std::allocator<DurabilityMonitor::SyncWrite>>::const_iterator
363+
trackedWritesEnd) {
364+
std::stringstream ss;
365+
ss << "{lastAck:" << pos.lastAckSeqno << " lastWrite:" << pos.lastWriteSeqno
366+
<< " it: @" << &*pos.it;
367+
if (pos.it == trackedWritesEnd) {
368+
ss << " <end>";
369+
} else {
370+
ss << " seqno:" << pos.it->getBySeqno();
371+
}
372+
ss << "}";
373+
return ss.str();
374+
}

engines/ep/src/durability/durability_monitor_impl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ struct PassiveDurabilityMonitor::State {
361361
/**
362362
* @param pdm The owning PassiveDurabilityMonitor
363363
*/
364-
State(const PassiveDurabilityMonitor& pdm) : pdm(pdm) {
365-
}
364+
State(const PassiveDurabilityMonitor& pdm);
366365

367366
/**
368367
* Returns the next position for a given Container::iterator.

engines/ep/src/durability/passive_durability_monitor.cc

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ PassiveDurabilityMonitor::PassiveDurabilityMonitor(VBucket& vb)
3636
: vb(vb), state(std::make_unique<State>(*this)) {
3737
// By design, instances of Container::Position can never be invalid
3838
auto s = state.wlock();
39-
s->highPreparedSeqno = Position(s->trackedWrites.end());
40-
s->highCompletedSeqno = Position(s->trackedWrites.end());
39+
s->highPreparedSeqno.it = s->trackedWrites.end();
40+
s->highCompletedSeqno.it = s->trackedWrites.end();
4141
}
4242

4343
PassiveDurabilityMonitor::PassiveDurabilityMonitor(VBucket& vb,
@@ -419,14 +419,21 @@ int64_t PassiveDurabilityMonitor::getHighestTrackedSeqno() const {
419419
}
420420

421421
void PassiveDurabilityMonitor::toOStream(std::ostream& os) const {
422-
os << "PassiveDurabilityMonitor[" << this << "]"
423-
<< " high_prepared_seqno:" << getHighPreparedSeqno()
424-
<< " trackedWrites:\n";
425-
state.withRLock([&os](auto& s) {
426-
for (const auto& w : s.trackedWrites) {
427-
os << " " << w << "\n";
428-
}
429-
});
422+
os << "PassiveDurabilityMonitor[" << this << "] " << *state.rlock();
423+
}
424+
425+
PassiveDurabilityMonitor::State::State(const PassiveDurabilityMonitor& pdm)
426+
: pdm(pdm) {
427+
const auto prefix =
428+
"PassiveDM(" + pdm.vb.getId().to_string() + ")::State::";
429+
430+
const auto hpsPrefix = prefix + "highPreparedSeqno";
431+
highPreparedSeqno.lastWriteSeqno.setLabel(hpsPrefix + ".lastWriteSeqno");
432+
highPreparedSeqno.lastAckSeqno.setLabel(hpsPrefix + ".lastAckSeqno");
433+
434+
const auto hcsPrefix = prefix + "highCompletedSeqno";
435+
highCompletedSeqno.lastWriteSeqno.setLabel(hcsPrefix + ".lastWriteSeqno");
436+
highCompletedSeqno.lastAckSeqno.setLabel(hcsPrefix + ".lastAckSeqno");
430437
}
431438

432439
DurabilityMonitor::Container::iterator
@@ -616,3 +623,17 @@ template <class exception>
616623
throw exception("PassiveDurabilityMonitor::" + thrower + " " +
617624
vb.getId().to_string() + " " + error);
618625
}
626+
627+
std::ostream& operator<<(std::ostream& os,
628+
const PassiveDurabilityMonitor::State& state) {
629+
os << "State[" << &state << "] highPreparedSeqno:"
630+
<< to_string(state.highPreparedSeqno, state.trackedWrites.end())
631+
<< " highCompletedSeqno:"
632+
<< to_string(state.highCompletedSeqno, state.trackedWrites.end())
633+
<< "\ntrackedWrites:[\n";
634+
for (const auto& w : state.trackedWrites) {
635+
os << " " << w << "\n";
636+
}
637+
os << "]\n";
638+
return os;
639+
}

engines/ep/src/durability/passive_durability_monitor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,7 @@ class PassiveDurabilityMonitor : public DurabilityMonitor {
183183

184184
// Necessary for implementing ADM(PDM&&)
185185
friend class ActiveDurabilityMonitor;
186+
187+
friend std::ostream& operator<<(
188+
std::ostream& os, const PassiveDurabilityMonitor::State& state);
186189
};

0 commit comments

Comments
 (0)