0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-45906 Ensure initial stable checkpoint is triggered properly when enableMajorityReadConcern=false

This commit is contained in:
William Schultz 2020-01-31 21:46:35 +00:00 committed by evergreen
parent 15801e543a
commit d9bd7a1be8
4 changed files with 57 additions and 0 deletions

View File

@ -51,6 +51,8 @@ replica_sets_multiversion:
test_file: jstests/replsets/step_down_on_secondary.js
- ticket: SERVER-45010
test_file: jstests/replsets/rollback_dup_ids_clean_shutdown_during_rollback.js
- ticket: SERVER-45906
test_file: jstests/replsets/trigger_initial_stable_checkpoint.js
sharding_multiversion:
- ticket: SERVER-38691

View File

@ -0,0 +1,32 @@
/**
* Ensure that we properly trigger a stable checkpoint when starting up a replica set node.
*
* @tags: [requires_persistence]
*/
(function() {
const rst = new ReplSetTest({
nodes: 1,
nodeOptions: {
// Turn up the syncdelay (in seconds) to effectively disable background checkpoints.
syncdelay: 600,
setParameter: {logComponentVerbosity: tojson({storage: 2})}
}
});
rst.startSet();
rst.initiate();
// By the time a node is primary it should have triggered a stable checkpoint. We subsequently kill
// and restart the node to check that the initial collections it created are durable in its
// checkpoint.
let primary = rst.getPrimary();
assert(checkLog.checkContainsOnce(primary, "Triggering the first stable checkpoint"));
jsTestLog("Kill and restart the node.");
rst.stop(0, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL}, {forRestart: true});
rst.start(0, undefined, true /* restart */);
jsTestLog("Waiting for the node to restart and become primary again.");
rst.getPrimary();
rst.stopSet();
}());

View File

@ -2912,6 +2912,14 @@ Status ReplicationCoordinatorImpl::processReplSetInitiate(OperationContext* opCt
auto configStateGuard =
makeGuard([&] { lockAndCall(&lk, [=] { _setConfigState_inlock(kConfigUninitialized); }); });
// When writing our first oplog entry below, disable advancement of the stable timestamp so that
// we don't set it before setting our initial data timestamp. We will set it after we set our
// initialDataTimestamp. This will ensure we trigger an initial stable checkpoint properly.
if (!serverGlobalParams.enableMajorityReadConcern) {
_shouldSetStableTimestamp = false;
}
lk.unlock();
ReplSetConfig newConfig;
@ -2969,6 +2977,14 @@ Status ReplicationCoordinatorImpl::processReplSetInitiate(OperationContext* opCt
_storage->setInitialDataTimestamp(getServiceContext(),
lastAppliedOpTimeAndWallTime.opTime.getTimestamp());
// Set our stable timestamp for storage and re-enable stable timestamp advancement after we have
// set our initial data timestamp.
if (!serverGlobalParams.enableMajorityReadConcern) {
stdx::unique_lock<Latch> lk(_mutex);
_shouldSetStableTimestamp = true;
_setStableTimestampForStorage(lk);
}
_finishReplSetInitiate(opCtx, newConfig, myIndex.getValue());
// A configuration passed to replSetInitiate() with the current node as an arbiter
@ -3842,6 +3858,10 @@ boost::optional<OpTimeAndWallTime> ReplicationCoordinatorImpl::_recalculateStabl
MONGO_FAIL_POINT_DEFINE(disableSnapshotting);
void ReplicationCoordinatorImpl::_setStableTimestampForStorage(WithLock lk) {
if (!_shouldSetStableTimestamp) {
LOG(2) << "Not setting stable timestamp for storage.";
return;
}
// Get the current stable optime.
auto stableOpTime = _recalculateStableOpTime(lk);

View File

@ -1477,6 +1477,9 @@ private:
// This set should also be cleared if a rollback occurs.
std::set<OpTimeAndWallTime> _stableOpTimeCandidates; // (M)
// A flag that enables/disables advancement of the stable timestamp for storage.
bool _shouldSetStableTimestamp = true; // (M)
// Used to signal threads that are waiting for new committed snapshots.
stdx::condition_variable _currentCommittedSnapshotCond; // (M)