diff options
author | Benety Goh <benety@mongodb.com> | 2019-03-06 09:06:16 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2019-03-06 09:06:16 -0500 |
commit | e960cdd7d37d6ddd9e378e710963033d19f7fdd5 (patch) | |
tree | e7a475cae9d71af01746aac71e086679732abbdb /src/mongo/db/repl | |
parent | 5b83a1b0c8a11787dbf034ade23a3f161804d9e4 (diff) | |
download | mongo-e960cdd7d37d6ddd9e378e710963033d19f7fdd5.tar.gz |
SERVER-39085 un-inline repl::TimestampBlock
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r-- | src/mongo/db/repl/SConscript | 12 | ||||
-rw-r--r-- | src/mongo/db/repl/timestamp_block.cpp | 55 | ||||
-rw-r--r-- | src/mongo/db/repl/timestamp_block.h | 17 |
3 files changed, 69 insertions, 15 deletions
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript index ae04d8d9ceb..ea5411e16fd 100644 --- a/src/mongo/db/repl/SConscript +++ b/src/mongo/db/repl/SConscript @@ -27,6 +27,7 @@ env.Library( 'dbcheck', 'repl_coordinator_interface', 'repl_settings', + 'timestamp_block', '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/db/background', '$BUILD_DIR/mongo/db/catalog/catalog_helpers', @@ -97,6 +98,17 @@ env.CppUnitTest( ], ) +env.Library( + target='timestamp_block', + source=[ + 'timestamp_block.cpp', + ], + LIBDEPS_PRIVATE=[ + '$BUILD_DIR/mongo/db/service_context', + '$BUILD_DIR/mongo/db/storage/storage_options', + ], +) + env.CppUnitTest( target='do_txn_test', source=[ diff --git a/src/mongo/db/repl/timestamp_block.cpp b/src/mongo/db/repl/timestamp_block.cpp new file mode 100644 index 00000000000..41992c8ed58 --- /dev/null +++ b/src/mongo/db/repl/timestamp_block.cpp @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2019-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. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/repl/timestamp_block.h" + +#include "mongo/db/storage/recovery_unit.h" +#include "mongo/db/storage/storage_options.h" +#include "mongo/util/assert_util.h" + +namespace mongo { + +TimestampBlock::TimestampBlock(OperationContext* opCtx, Timestamp ts) : _opCtx(opCtx), _ts(ts) { + uassert(ErrorCodes::IllegalOperation, + "Cannot timestamp a write operation in read-only mode", + !storageGlobalParams.readOnly); + if (!_ts.isNull()) { + _opCtx->recoveryUnit()->setCommitTimestamp(_ts); + } +} + +TimestampBlock::~TimestampBlock() { + if (!_ts.isNull()) { + _opCtx->recoveryUnit()->clearCommitTimestamp(); + } +} + +} // namespace mongo diff --git a/src/mongo/db/repl/timestamp_block.h b/src/mongo/db/repl/timestamp_block.h index 544e7920f62..1f512128d93 100644 --- a/src/mongo/db/repl/timestamp_block.h +++ b/src/mongo/db/repl/timestamp_block.h @@ -32,7 +32,6 @@ #include "mongo/base/disallow_copying.h" #include "mongo/bson/timestamp.h" #include "mongo/db/operation_context.h" -#include "mongo/db/storage/recovery_unit.h" namespace mongo { @@ -45,20 +44,8 @@ class TimestampBlock { MONGO_DISALLOW_COPYING(TimestampBlock); public: - TimestampBlock(OperationContext* opCtx, Timestamp ts) : _opCtx(opCtx), _ts(ts) { - uassert(ErrorCodes::IllegalOperation, - "Cannot timestamp a write operation in read-only mode", - !storageGlobalParams.readOnly); - if (!_ts.isNull()) { - _opCtx->recoveryUnit()->setCommitTimestamp(_ts); - } - } - - ~TimestampBlock() { - if (!_ts.isNull()) { - _opCtx->recoveryUnit()->clearCommitTimestamp(); - } - } + TimestampBlock(OperationContext* opCtx, Timestamp ts); + ~TimestampBlock(); private: OperationContext* const _opCtx; |