summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/replsets/refresh_sessions_rs.js5
-rw-r--r--jstests/replsets/sessions_collection_auto_healing.js26
-rw-r--r--src/mongo/db/sessions_collection.cpp25
-rw-r--r--src/mongo/db/sessions_collection.h6
-rw-r--r--src/mongo/db/sessions_collection_rs.cpp75
5 files changed, 54 insertions, 83 deletions
diff --git a/jstests/replsets/refresh_sessions_rs.js b/jstests/replsets/refresh_sessions_rs.js
index 9bd4527c7bf..3a5cdd98218 100644
--- a/jstests/replsets/refresh_sessions_rs.js
+++ b/jstests/replsets/refresh_sessions_rs.js
@@ -51,8 +51,9 @@
res = db2.runCommand(refresh);
assert.commandWorked(res, "failed to refresh");
- // Connect to the primary. The sessions collection here should not yet contain records.
- assert.eq(db1.system.sessions.count(), 0, "flushed refresh to the primary prematurely");
+ // Connect to the primary. The sessions collection here should have one record for the session
+ // on the secondary.
+ assert.eq(db1.system.sessions.count(), 1, "failed to refresh on the secondary");
// Trigger a refresh on the primary. The sessions collection should now contain two records.
res = db1.runCommand(refresh);
diff --git a/jstests/replsets/sessions_collection_auto_healing.js b/jstests/replsets/sessions_collection_auto_healing.js
index f4f147a5dd3..49d4eb27e84 100644
--- a/jstests/replsets/sessions_collection_auto_healing.js
+++ b/jstests/replsets/sessions_collection_auto_healing.js
@@ -18,8 +18,7 @@ load('jstests/libs/sessions_collection.js');
var secondary = replTest._slaves[0];
var secondaryAdmin = secondary.getDB("admin");
- // Test that we can use sessions on the primary
- // before the sessions collection exists.
+ // Test that we can use sessions on the primary before the sessions collection exists.
{
validateSessionsCollection(primary, false, false);
@@ -28,8 +27,7 @@ load('jstests/libs/sessions_collection.js');
validateSessionsCollection(primary, false, false);
}
- // Test that we can use sessions on secondaries
- // before the sessions collection exists.
+ // Test that we can use sessions on secondaries before the sessions collection exists.
{
validateSessionsCollection(primary, false, false);
validateSessionsCollection(secondary, false, false);
@@ -40,20 +38,20 @@ load('jstests/libs/sessions_collection.js');
validateSessionsCollection(secondary, false, false);
}
- // Test that a refresh on a secondary does not create the sessions
- // collection, on either the secondary or the primary.
+ // Test that a refresh on a secondary creates the sessions collection.
{
validateSessionsCollection(primary, false, false);
validateSessionsCollection(secondary, false, false);
assert.commandWorked(secondaryAdmin.runCommand({refreshLogicalSessionCacheNow: 1}));
- validateSessionsCollection(primary, false, false);
- validateSessionsCollection(secondary, false, false);
+ validateSessionsCollection(primary, true, true);
+ validateSessionsCollection(secondary, true, true);
}
-
// Test that a refresh on the primary creates the sessions collection.
{
+ assert.commandWorked(primary.getDB("config").runCommand(
+ {drop: "system.sessions", writeConcern: {w: "majority"}}));
validateSessionsCollection(primary, false, false);
validateSessionsCollection(secondary, false, false);
@@ -62,8 +60,7 @@ load('jstests/libs/sessions_collection.js');
validateSessionsCollection(primary, true, true);
}
- // Test that a refresh on a secondary will not create the
- // TTL index on the sessions collection.
+ // Test that a refresh on a secondary will create the TTL index on the sessions collection.
{
assert.commandWorked(primary.getDB("config").system.sessions.dropIndex({lastUse: 1}));
@@ -71,12 +68,13 @@ load('jstests/libs/sessions_collection.js');
assert.commandWorked(secondaryAdmin.runCommand({refreshLogicalSessionCacheNow: 1}));
- validateSessionsCollection(primary, true, false);
+ validateSessionsCollection(primary, true, true);
}
- // Test that a refresh on the primary will create the
- // TTL index on the sessions collection.
+ // Test that a refresh on the primary will create the TTL index on the sessions collection.
{
+ assert.commandWorked(primary.getDB("config").system.sessions.dropIndex({lastUse: 1}));
+
validateSessionsCollection(primary, true, false);
assert.commandWorked(primaryAdmin.runCommand({refreshLogicalSessionCacheNow: 1}));
diff --git a/src/mongo/db/sessions_collection.cpp b/src/mongo/db/sessions_collection.cpp
index cf8e0349a30..fe60b747c55 100644
--- a/src/mongo/db/sessions_collection.cpp
+++ b/src/mongo/db/sessions_collection.cpp
@@ -225,24 +225,6 @@ Status SessionsCollection::doRefresh(const NamespaceString& ns,
return runBulkCmd("updates", init, add, send, sessions);
}
-Status SessionsCollection::doRefreshExternal(const NamespaceString& ns,
- const LogicalSessionRecordSet& sessions,
- SendBatchFn send) {
- auto makeT = [] { return std::vector<LogicalSessionRecord>{}; };
-
- auto add = [](std::vector<LogicalSessionRecord>& batch, const LogicalSessionRecord& record) {
- batch.push_back(record);
- };
-
- auto sendLocal = [&](std::vector<LogicalSessionRecord>& batch) {
- RefreshSessionsCmdFromClusterMember idl;
- idl.setRefreshSessionsInternal(batch);
- return send(idl.toBSON());
- };
-
- return runBulkGeneric(makeT, add, sendLocal, sessions);
-}
-
Status SessionsCollection::doRemove(const NamespaceString& ns,
const LogicalSessionIdSet& sessions,
SendBatchFn send) {
@@ -259,13 +241,6 @@ Status SessionsCollection::doRemove(const NamespaceString& ns,
return runBulkCmd("deletes", init, add, send, sessions);
}
-Status SessionsCollection::doRemoveExternal(const NamespaceString& ns,
- const LogicalSessionIdSet& sessions,
- SendBatchFn send) {
- // TODO SERVER-28335 Implement endSessions, with internal counterpart.
- return Status::OK();
-}
-
StatusWith<LogicalSessionIdSet> SessionsCollection::doFetch(const NamespaceString& ns,
const LogicalSessionIdSet& sessions,
FindBatchFn send) {
diff --git a/src/mongo/db/sessions_collection.h b/src/mongo/db/sessions_collection.h
index 59440a5c755..7635124c5a7 100644
--- a/src/mongo/db/sessions_collection.h
+++ b/src/mongo/db/sessions_collection.h
@@ -103,9 +103,6 @@ protected:
Status doRefresh(const NamespaceString& ns,
const LogicalSessionRecordSet& sessions,
SendBatchFn send);
- Status doRefreshExternal(const NamespaceString& ns,
- const LogicalSessionRecordSet& sessions,
- SendBatchFn send);
/**
* Formats and sends batches of deletes for the given set of sessions.
@@ -113,9 +110,6 @@ protected:
Status doRemove(const NamespaceString& ns,
const LogicalSessionIdSet& sessions,
SendBatchFn send);
- Status doRemoveExternal(const NamespaceString& ns,
- const LogicalSessionIdSet& sessions,
- SendBatchFn send);
/**
* Formats and sends batches of fetches for the given set of sessions.
diff --git a/src/mongo/db/sessions_collection_rs.cpp b/src/mongo/db/sessions_collection_rs.cpp
index d9c403696e2..d8f72b470f2 100644
--- a/src/mongo/db/sessions_collection_rs.cpp
+++ b/src/mongo/db/sessions_collection_rs.cpp
@@ -159,52 +159,55 @@ Status SessionsCollectionRS::setupSessionsCollection(OperationContext* opCtx) {
return Status::OK();
},
- [&](DBClientBase*) {
- // If we are not the primary, we aren't going to do writes anyway, so just return ok.
+ [&](DBClientBase* client) {
+ BSONObj info;
+ auto cmd = generateCreateIndexesCmd();
+ if (!client->runCommand(
+ NamespaceString::kLogicalSessionsNamespace.db().toString(), cmd, info)) {
+ return getStatusFromCommandResult(info);
+ }
return Status::OK();
});
}
Status SessionsCollectionRS::refreshSessions(OperationContext* opCtx,
const LogicalSessionRecordSet& sessions) {
- return dispatch(
- NamespaceString::kLogicalSessionsNamespace,
- MODE_IX,
- opCtx,
- [&] {
- DBDirectClient client(opCtx);
- return doRefresh(
- NamespaceString::kLogicalSessionsNamespace,
- sessions,
- makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, &client));
- },
- [&](DBClientBase* client) {
- return doRefreshExternal(
- NamespaceString::kLogicalSessionsNamespace,
- sessions,
- makeSendFnForCommand(NamespaceString::kLogicalSessionsNamespace, client));
- });
+ return dispatch(NamespaceString::kLogicalSessionsNamespace,
+ MODE_IX,
+ opCtx,
+ [&] {
+ DBDirectClient client(opCtx);
+ return doRefresh(NamespaceString::kLogicalSessionsNamespace,
+ sessions,
+ makeSendFnForBatchWrite(
+ NamespaceString::kLogicalSessionsNamespace, &client));
+ },
+ [&](DBClientBase* client) {
+ return doRefresh(NamespaceString::kLogicalSessionsNamespace,
+ sessions,
+ makeSendFnForBatchWrite(
+ NamespaceString::kLogicalSessionsNamespace, client));
+ });
}
Status SessionsCollectionRS::removeRecords(OperationContext* opCtx,
const LogicalSessionIdSet& sessions) {
- return dispatch(
- NamespaceString::kLogicalSessionsNamespace,
- MODE_IX,
- opCtx,
- [&] {
- DBDirectClient client(opCtx);
- return doRemove(
- NamespaceString::kLogicalSessionsNamespace,
- sessions,
- makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, &client));
- },
- [&](DBClientBase* client) {
- return doRemoveExternal(
- NamespaceString::kLogicalSessionsNamespace,
- sessions,
- makeSendFnForCommand(NamespaceString::kLogicalSessionsNamespace, client));
- });
+ return dispatch(NamespaceString::kLogicalSessionsNamespace,
+ MODE_IX,
+ opCtx,
+ [&] {
+ DBDirectClient client(opCtx);
+ return doRemove(NamespaceString::kLogicalSessionsNamespace,
+ sessions,
+ makeSendFnForBatchWrite(
+ NamespaceString::kLogicalSessionsNamespace, &client));
+ },
+ [&](DBClientBase* client) {
+ return doRemove(NamespaceString::kLogicalSessionsNamespace,
+ sessions,
+ makeSendFnForBatchWrite(
+ NamespaceString::kLogicalSessionsNamespace, client));
+ });
}
StatusWith<LogicalSessionIdSet> SessionsCollectionRS::findRemovedSessions(