diff options
author | Blake Oler <blake.oler@mongodb.com> | 2019-04-03 12:23:04 -0400 |
---|---|---|
committer | Blake Oler <blake.oler@mongodb.com> | 2019-04-16 16:27:00 -0400 |
commit | fbf88f57c0b356c665e8fe1a79d546bdebe4cc8d (patch) | |
tree | eb7ea0098652c0061a467a4ff51ba49a18d69191 | |
parent | 8d3de2bd46d679a32c8075f318731ef2d023b731 (diff) | |
download | mongo-fbf88f57c0b356c665e8fe1a79d546bdebe4cc8d.tar.gz |
SERVER-39420 Remove in-memory boolean to indicate config.server.sessions collection set up
(cherry picked from commit 2c20db31fcd6a2a9ac02506d55794f9b234af0a6)
-rw-r--r-- | jstests/sharding/sessions_collection_auto_healing.js | 22 | ||||
-rw-r--r-- | src/mongo/db/sessions_collection_config_server.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/sessions_collection_config_server.h | 1 |
3 files changed, 19 insertions, 12 deletions
diff --git a/jstests/sharding/sessions_collection_auto_healing.js b/jstests/sharding/sessions_collection_auto_healing.js index 61271bd8dc5..a9526628ee0 100644 --- a/jstests/sharding/sessions_collection_auto_healing.js +++ b/jstests/sharding/sessions_collection_auto_healing.js @@ -3,6 +3,8 @@ load('jstests/libs/sessions_collection.js'); (function() { "use strict"; + load("jstests/libs/collection_drop_recreate.js"); // For assert[Drop|Create]Collection. + // This test makes assertions about the number of sessions, which are not compatible with // implicit sessions. TestData.disableImplicitSessions = true; @@ -125,20 +127,34 @@ load('jstests/libs/sessions_collection.js'); assert.eq(shardConfig.system.sessions.count(), 4, "did not flush mongos' sessions"); } - // Test that if we drop the index on the sessions collection, - // refresh on neither the shard nor the config db heals it. + // Test that if we drop the index on the sessions collection, only a refresh on the config + // server heals it. { assert.commandWorked(shardConfig.system.sessions.dropIndex({lastUse: 1})); validateSessionsCollection(shard, true, false); assert.commandWorked(configAdmin.runCommand({refreshLogicalSessionCacheNow: 1})); - validateSessionsCollection(shard, true, false); + validateSessionsCollection(shard, true, true); + + assert.commandWorked(shardConfig.system.sessions.dropIndex({lastUse: 1})); assert.commandWorked(shardAdmin.runCommand({refreshLogicalSessionCacheNow: 1})); validateSessionsCollection(shard, true, false); } + // Test that if we drop the collection, it will be recreated only by the config server. + { + assertDropCollection(mongosConfig, "system.sessions"); + validateSessionsCollection(shard, false, false); + + assert.commandWorked(shardAdmin.runCommand({refreshLogicalSessionCacheNow: 1})); + validateSessionsCollection(shard, false, false); + + assert.commandWorked(configAdmin.runCommand({refreshLogicalSessionCacheNow: 1})); + validateSessionsCollection(shard, true, true); + } + st.stop(); rs.stopSet(); diff --git a/src/mongo/db/sessions_collection_config_server.cpp b/src/mongo/db/sessions_collection_config_server.cpp index 8ae627f1b90..e1409361931 100644 --- a/src/mongo/db/sessions_collection_config_server.cpp +++ b/src/mongo/db/sessions_collection_config_server.cpp @@ -99,13 +99,6 @@ Status SessionsCollectionConfigServer::setupSessionsCollection(OperationContext* stdx::lock_guard<stdx::mutex> lk(_mutex); { - // Only try to set up this collection until we have done so successfully once. - // Note: if there is a config server election, it's possible that two different - // primaries could both run the createIndexes scatter-gather query; this is ok. - if (_collectionSetUp) { - return Status::OK(); - } - auto res = _shardCollectionIfNeeded(opCtx); if (!res.isOK()) { log() << "Failed to create config.system.sessions: " << res.reason() @@ -119,7 +112,6 @@ Status SessionsCollectionConfigServer::setupSessionsCollection(OperationContext* << "will try again on the next refresh interval"; } - _collectionSetUp = true; return res; } } diff --git a/src/mongo/db/sessions_collection_config_server.h b/src/mongo/db/sessions_collection_config_server.h index 2e80ca90fca..9e687f9798f 100644 --- a/src/mongo/db/sessions_collection_config_server.h +++ b/src/mongo/db/sessions_collection_config_server.h @@ -66,7 +66,6 @@ private: Status _generateIndexesIfNeeded(OperationContext* opCtx); stdx::mutex _mutex; - bool _collectionSetUp{false}; }; } // namespace mongo |