Skip to content

Commit a590887

Browse files
committed
MB-34910: Track HPS/HCS as member variables of the ADM::State
Instead of deriving the HPS and HCS when they are read, keep a tracked/cached counter in the ADM::State which is simply returned when needed. This is also required to simplify the warmup of the ADM as we can just assign the pre-warmup value. Note: highPreparedSeqno is tracked as weak monotonic counter becase updateHighPreparedSeqno can run and make no change, rather than detect when no-change occured we just tolerate assignment of the current value. Change-Id: I914637548fdfecd419d6492561a4a3319fe88b26 Reviewed-on: http://review.couchbase.org/111863 Reviewed-by: Ben Huddleston <[email protected]> Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 3f8628f commit a590887

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

engines/ep/src/durability/active_durability_monitor.cc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ struct ActiveDurabilityMonitor::State {
189189
*/
190190
void performQueuedAckForChain(const ReplicationChain& chain);
191191

192+
void updateHighCompletedSeqno();
193+
192194
private:
193195
/**
194196
* Advance the current Position (iterator and seqno).
@@ -228,6 +230,12 @@ struct ActiveDurabilityMonitor::State {
228230
// Stores the last aborted seqno.
229231
Monotonic<int64_t> lastAbortedSeqno = 0;
230232

233+
// Stores the highPreparedSeqno
234+
WeaklyMonotonic<int64_t> highPreparedSeqno = 0;
235+
236+
// Stores the highCompletedSeqno
237+
Monotonic<int64_t> highCompletedSeqno = 0;
238+
231239
// Cumulative count of accepted (tracked) SyncWrites.
232240
size_t totalAccepted = 0;
233241
// Cumulative count of Committed SyncWrites.
@@ -413,12 +421,11 @@ int64_t ActiveDurabilityMonitor::getHighPreparedSeqno() const {
413421
if (!s->firstChain) {
414422
return 0;
415423
}
416-
return s->getNodeWriteSeqno(s->getActive());
424+
return s->highPreparedSeqno;
417425
}
418426

419427
int64_t ActiveDurabilityMonitor::getHighCompletedSeqno() const {
420-
const auto s = state.rlock();
421-
return std::max(s->lastCommittedSeqno, s->lastAbortedSeqno);
428+
return state.rlock()->highCompletedSeqno;
422429
}
423430

424431
bool ActiveDurabilityMonitor::isDurabilityPossible() const {
@@ -932,6 +939,7 @@ void ActiveDurabilityMonitor::commit(const SyncWrite& sw) {
932939
{
933940
auto s = state.wlock();
934941
s->lastCommittedSeqno = sw.getBySeqno();
942+
s->updateHighCompletedSeqno();
935943
s->totalCommitted++;
936944
// Note:
937945
// - Level Majority locally-satisfied first at Active by-logic
@@ -965,6 +973,7 @@ void ActiveDurabilityMonitor::abort(const SyncWrite& sw) {
965973
}
966974
auto s = state.wlock();
967975
s->lastAbortedSeqno = sw.getBySeqno();
976+
s->updateHighCompletedSeqno();
968977
s->totalAborted++;
969978
}
970979

@@ -1046,6 +1055,8 @@ void ActiveDurabilityMonitor::toOStream(std::ostream& os) const {
10461055
const auto s = state.rlock();
10471056
os << "ActiveDurabilityMonitor[" << this
10481057
<< "] #trackedWrites:" << s->trackedWrites.size()
1058+
<< " highPreparedSeqno:" << s->highPreparedSeqno
1059+
<< " highCompletedSeqno:" << s->highCompletedSeqno
10491060
<< " lastTrackedSeqno:" << s->lastTrackedSeqno
10501061
<< " lastCommittedSeqno:" << s->lastCommittedSeqno
10511062
<< " lastAbortedSeqno:" << s->lastAbortedSeqno << "\n";
@@ -1326,6 +1337,7 @@ void ActiveDurabilityMonitor::State::updateHighPreparedSeqno(
13261337
while ((next = getNodeNext(active)) != trackedWrites.end() &&
13271338
static_cast<uint64_t>(next->getBySeqno()) <=
13281339
adm.vb.getPersistenceSeqno()) {
1340+
highPreparedSeqno = next->getBySeqno();
13291341
advanceNodePosition(active);
13301342
removeForCommitIfSatisfied();
13311343
}
@@ -1347,6 +1359,7 @@ void ActiveDurabilityMonitor::State::updateHighPreparedSeqno(
13471359
break;
13481360
}
13491361

1362+
highPreparedSeqno = next->getBySeqno();
13501363
advanceNodePosition(active);
13511364
removeForCommitIfSatisfied();
13521365
}
@@ -1355,6 +1368,10 @@ void ActiveDurabilityMonitor::State::updateHighPreparedSeqno(
13551368
// Position::lastAckSeqno for the local (Active) tracking.
13561369
}
13571370

1371+
void ActiveDurabilityMonitor::State::updateHighCompletedSeqno() {
1372+
highCompletedSeqno = std::max(lastCommittedSeqno, lastAbortedSeqno);
1373+
}
1374+
13581375
void ActiveDurabilityMonitor::checkForCommit() {
13591376
// Identify all SyncWrites which are now committed, transferring them into
13601377
// the completedQueue (under the correct locks).

0 commit comments

Comments
 (0)