Skip to content

Commit

Permalink
SERVER-37245 Use the SessionCatalog to track sessions on MongoS
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloianm committed Nov 19, 2018
1 parent c131f59 commit 55478ba
Show file tree
Hide file tree
Showing 14 changed files with 296 additions and 344 deletions.
2 changes: 1 addition & 1 deletion src/mongo/db/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ env.CppUnitTest(
LIBDEPS=[
'$BUILD_DIR/mongo/unittest/concurrency',
'auth/authmocks',
'service_context_d_test_fixture',
'service_context_test_fixture',
'session_catalog',
],
)
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/concurrency/locker_noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class LockerNoop : public Locker {
virtual void endWriteUnitOfWork() {}

virtual bool inAWriteUnitOfWork() const {
MONGO_UNREACHABLE;
return false;
}

virtual LockResult lock(OperationContext* opCtx,
Expand Down
4 changes: 2 additions & 2 deletions src/mongo/db/session_catalog_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "mongo/platform/basic.h"

#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/db/service_context_test_fixture.h"
#include "mongo/db/session_catalog.h"
#include "mongo/stdx/future.h"
#include "mongo/stdx/memory.h"
Expand All @@ -42,7 +42,7 @@
namespace mongo {
namespace {

class SessionCatalogTest : public ServiceContextMongoDTest {
class SessionCatalogTest : public ServiceContextTest {
protected:
SessionCatalog* catalog() {
return SessionCatalog::get(getServiceContext());
Expand Down
5 changes: 4 additions & 1 deletion src/mongo/s/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,20 @@ env.Library(
'cluster_commands_helpers.cpp',
'multi_statement_transaction_requests_sender.cpp',
'transaction_router.cpp',
'session_catalog_router.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/db/commands/txn_cmd_request',
'$BUILD_DIR/mongo/db/curop',
'$BUILD_DIR/mongo/db/logical_session_id',
'$BUILD_DIR/mongo/db/logical_session_id_helpers',
'$BUILD_DIR/mongo/db/repl/read_concern_args',
'async_requests_sender',
'common_s',
'grid',
],
LIBDEPS_PRIVATE=[
'$BUILD_DIR/mongo/db/session_catalog',
],
)

env.Library(
Expand Down
5 changes: 3 additions & 2 deletions src/mongo/s/commands/strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include "mongo/s/grid.h"
#include "mongo/s/query/cluster_cursor_manager.h"
#include "mongo/s/query/cluster_find.h"
#include "mongo/s/session_catalog_router.h"
#include "mongo/s/stale_exception.h"
#include "mongo/s/transaction_router.h"
#include "mongo/util/fail_point_service.h"
Expand Down Expand Up @@ -403,11 +404,11 @@ void runCommand(OperationContext* opCtx,
!readConcernArgs.getArgsAtClusterTime());
}

boost::optional<ScopedRouterSession> scopedSession;
boost::optional<RouterOperationContextSession> routerSession;
try {
CommandHelpers::evaluateFailCommandFailPoint(opCtx, commandName);
if (osi.getAutocommit()) {
scopedSession.emplace(opCtx);
routerSession.emplace(opCtx);

auto txnRouter = TransactionRouter::get(opCtx);
invariant(txnRouter);
Expand Down
9 changes: 3 additions & 6 deletions src/mongo/s/compute_at_cluster_time_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "mongo/s/catalog_cache_test_fixture.h"
#include "mongo/s/client/shard_remote.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/session_catalog_router.h"
#include "mongo/s/shard_id.h"
#include "mongo/s/sharding_router_test_fixture.h"
#include "mongo/s/transaction_router.h"
Expand Down Expand Up @@ -83,8 +84,6 @@ class AtClusterTimeTest : public ShardingTestFixture {
repl::ReadConcernArgs(repl::ReadConcernLevel::kSnapshotReadConcern);

_scopedSession.emplace(operationContext());

txnRouter()->checkOut();
txnRouter()->beginOrContinueTxn(operationContext(), kTxnNumber, true);
}

Expand All @@ -97,7 +96,7 @@ class AtClusterTimeTest : public ShardingTestFixture {
}

private:
boost::optional<ScopedRouterSession> _scopedSession;
boost::optional<RouterOperationContextSession> _scopedSession;
};

TEST_F(AtClusterTimeTest, ComputeValidValid) {
Expand Down Expand Up @@ -187,8 +186,6 @@ class AtClusterTimeTargetingTest : public CatalogCacheTestFixture {
repl::ReadConcernArgs(repl::ReadConcernLevel::kSnapshotReadConcern);

_scopedSession.emplace(operationContext());

txnRouter()->checkOut();
txnRouter()->beginOrContinueTxn(operationContext(), kTxnNumber, true);
}

Expand All @@ -201,7 +198,7 @@ class AtClusterTimeTargetingTest : public CatalogCacheTestFixture {
}

private:
boost::optional<ScopedRouterSession> _scopedSession;
boost::optional<RouterOperationContextSession> _scopedSession;
};

// Verifies that the latest in-memory logical time is returned when lastCommittedOpTime on one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,17 @@
* it in the license file.
*/

#pragma once
#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding

namespace mongo {
namespace unittest {
#include "mongo/platform/basic.h"

#include "mongo/s/session_catalog_router.h"

template <typename T>
Test::RegistrationAgent<T>::RegistrationAgent(const std::string& suiteName,
const std::string& testName)
: _suiteName(suiteName), _testName(testName) {
Suite::getSuite(suiteName)->add<T>(testName);
}
namespace mongo {

template <typename T>
std::string Test::RegistrationAgent<T>::getSuiteName() const {
return _suiteName;
}
RouterOperationContextSession::RouterOperationContextSession(OperationContext* opCtx)
: _operationContextSession(opCtx) {}

template <typename T>
std::string Test::RegistrationAgent<T>::getTestName() const {
return _testName;
}
RouterOperationContextSession::~RouterOperationContextSession() = default;

} // namespace mongo
} // namespace unittest
53 changes: 53 additions & 0 deletions src/mongo/s/session_catalog_router.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

/**
* Copyright (C) 2018-present MongoDB, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*
* As a special exception, the copyright holders give permission to link the
* code of portions of this program with the OpenSSL library under certain
* conditions as described in each individual source file and distribute
* linked combinations including the program with the OpenSSL library. You
* must comply with the Server Side Public License in all respects for
* all of the code used other than as permitted herein. If you modify file(s)
* with this exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do so,
* delete this exception statement from your version. If you delete this
* exception statement from all source files in the program, then also delete
* it in the license file.
*/

#pragma once

#include "mongo/db/session_catalog.h"

namespace mongo {

/**
* Scoped object, which checks out the session specified in the passed operation context and stores
* it for later access by the command. The session is installed at construction time and is removed
* at destruction. This can only be used for multi-statement transactions.
*/
class RouterOperationContextSession {
MONGO_DISALLOW_COPYING(RouterOperationContextSession);

public:
RouterOperationContextSession(OperationContext* opCtx);
~RouterOperationContextSession();

private:
OperationContextSession _operationContextSession;
};

} // namespace mongo
Loading

0 comments on commit 55478ba

Please sign in to comment.