diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2020-01-21 18:38:41 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-01-21 18:38:41 +0000 |
commit | c6845bd41a393eedd3e1e979fef030d277de7144 (patch) | |
tree | f78e54133e272b86dbbdb5f23b3f2b39d4961e91 | |
parent | e1d3dc63cdb33e75d2a47dbafe0d4ac765dbb8aa (diff) | |
download | mongo-c6845bd41a393eedd3e1e979fef030d277de7144.tar.gz |
SERVER-43719 Load RWC defaults from persisted values during startup
-rw-r--r-- | jstests/noPassthrough/read_write_concern_defaults_startup.js | 62 | ||||
-rw-r--r-- | src/mongo/db/db.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/read_write_concern_defaults_cache_lookup_mongod.cpp | 7 | ||||
-rw-r--r-- | src/mongo/s/server.cpp | 7 |
4 files changed, 87 insertions, 0 deletions
diff --git a/jstests/noPassthrough/read_write_concern_defaults_startup.js b/jstests/noPassthrough/read_write_concern_defaults_startup.js new file mode 100644 index 00000000000..e63077fe1cd --- /dev/null +++ b/jstests/noPassthrough/read_write_concern_defaults_startup.js @@ -0,0 +1,62 @@ +// Verifies read/write concern defaults are loaded at startup by a mongos and non-sharded replica +// set node. +// +// This test restarts a replica set node, which requires persistence and journaling. +// @tags: [requires_sharding, requires_persistence, requires_journaling] +(function() { +"use strict"; + +function runTest(conn, failPointConn, restartFn) { + // Set a default rwc. + assert.commandWorked( + conn.adminCommand({setDefaultRWConcern: 1, defaultReadConcern: {level: "majority"}})); + let res = assert.commandWorked(conn.adminCommand({getDefaultRWConcern: 1})); + assert.eq(res.defaultReadConcern, {level: "majority"}); + + // Restart the node with disabled rwc refreshes. + restartFn(); + reconnect(conn); + reconnect(failPointConn); + + // Verify the server attempted to load the defaults at startup. + checkLog.contains(conn, "Failed to load read and write concern defaults at startup"); + checkLog.contains(conn, + "Failing read/write concern persisted defaults lookup because of fail point"); + + // Disable the fail point and verify the defaults can be returned. + assert.commandWorked( + failPointConn.adminCommand({configureFailPoint: "failRWCDefaultsLookup", mode: "off"})); + res = assert.commandWorked(conn.adminCommand({getDefaultRWConcern: 1})); + assert.eq(res.defaultReadConcern, {level: "majority"}); +} + +jsTestLog("Testing mongos..."); +{ + // Use 1 node CSRS so the failpoint to disable rwc lookup only needs to be set on one node. + const st = new ShardingTest({shards: 1, config: 1}); + + runTest(st.s, st.configRS.getPrimary(), () => { + assert.commandWorked(st.configRS.getPrimary().adminCommand( + {configureFailPoint: "failRWCDefaultsLookup", mode: "alwaysOn"})); + st.restartMongos(0); + }); + + st.stop(); +} + +jsTestLog("Testing plain replica set node..."); +{ + const rst = new ReplSetTest({nodes: 1}); + rst.startSet(); + rst.initiate(); + + const primary = rst.getPrimary(); + runTest(primary, primary, () => { + rst.restart( + primary, + {setParameter: "failpoint.failRWCDefaultsLookup=" + tojson({mode: "alwaysOn"})}); + }); + + rst.stopSet(); +} +})(); diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index 65fb74748a5..97f2580e389 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -525,6 +525,17 @@ ExitCode _initAndListen(int listenPort) { } } + try { + if (serverGlobalParams.clusterRole != ClusterRole::ShardServer && + replSettings.usingReplSets()) { + ReadWriteConcernDefaults::get(startupOpCtx.get()->getServiceContext()) + .refreshIfNecessary(startupOpCtx.get()); + } + } catch (const DBException& ex) { + warning() << "Failed to load read and write concern defaults at startup" + << causedBy(redact(ex.toStatus())); + } + auto storageEngine = serviceContext->getStorageEngine(); invariant(storageEngine); BackupCursorHooks::initialize(serviceContext, storageEngine); diff --git a/src/mongo/db/read_write_concern_defaults_cache_lookup_mongod.cpp b/src/mongo/db/read_write_concern_defaults_cache_lookup_mongod.cpp index 33a0cc3f22e..07dfc900c48 100644 --- a/src/mongo/db/read_write_concern_defaults_cache_lookup_mongod.cpp +++ b/src/mongo/db/read_write_concern_defaults_cache_lookup_mongod.cpp @@ -32,11 +32,18 @@ #include "mongo/db/dbdirectclient.h" #include "mongo/db/namespace_string.h" #include "mongo/db/read_write_concern_defaults.h" +#include "mongo/util/fail_point.h" namespace mongo { namespace { +MONGO_FAIL_POINT_DEFINE(failRWCDefaultsLookup); + BSONObj getPersistedDefaultRWConcernDocument(OperationContext* opCtx) { + uassert(51762, + "Failing read/write concern persisted defaults lookup because of fail point", + !MONGO_unlikely(failRWCDefaultsLookup.shouldFail())); + DBDirectClient client(opCtx); return client.findOne(NamespaceString::kConfigSettingsNamespace.toString(), QUERY("_id" << ReadWriteConcernDefaults::kPersistedDocumentId)); diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index 2db78c6db78..faa5ccf183b 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -579,6 +579,13 @@ ExitCode runMongosServer(ServiceContext* serviceContext) { ->getBalancerConfiguration() ->refreshAndCheck(opCtx) .transitional_ignore(); + + try { + ReadWriteConcernDefaults::get(serviceContext).refreshIfNecessary(opCtx); + } catch (const DBException& ex) { + warning() << "Failed to load read and write concern defaults at startup" + << causedBy(redact(ex.toStatus())); + } } startMongoSFTDC(); |