summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2016-03-04 06:00:05 -0500
committermatt dannenberg <matt.dannenberg@10gen.com>2016-03-07 13:19:29 -0500
commit03eb4777de6cc9bade4041190b837b3c31a88e34 (patch)
tree8208f193b3d107362c98fbfbd036d829851437be
parentb34164948c4727e1038cb76ce3783570c7f90d15 (diff)
downloadmongo-03eb4777de6cc9bade4041190b837b3c31a88e34.tar.gz
SERVER-22965 move OplogEntry into repl/oplog_entry.{cpp,h}
-rw-r--r--src/mongo/db/repl/SConscript1
-rw-r--r--src/mongo/db/repl/oplog_entry.cpp56
-rw-r--r--src/mongo/db/repl/oplog_entry.h61
-rw-r--r--src/mongo/db/repl/sync_tail.cpp40
-rw-r--r--src/mongo/db/repl/sync_tail.h30
-rw-r--r--src/mongo/db/repl/sync_tail_test.cpp2
6 files changed, 133 insertions, 57 deletions
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript
index 10f4c6047bf..c6a5250be46 100644
--- a/src/mongo/db/repl/SConscript
+++ b/src/mongo/db/repl/SConscript
@@ -209,6 +209,7 @@ env.Library(
target='sync_tail',
source=[
'sync_tail.cpp',
+ 'oplog_entry.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/db/auth/authorization_manager_global',
diff --git a/src/mongo/db/repl/oplog_entry.cpp b/src/mongo/db/repl/oplog_entry.cpp
new file mode 100644
index 00000000000..1b612d6ca1a
--- /dev/null
+++ b/src/mongo/db/repl/oplog_entry.cpp
@@ -0,0 +1,56 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 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 GNU Affero General 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.
+ */
+
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kReplication
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/repl/oplog_entry.h"
+
+namespace mongo {
+namespace repl {
+
+OplogEntry::OplogEntry(const BSONObj& rawInput) : raw(rawInput.getOwned()) {
+ for (auto elem : raw) {
+ const auto name = elem.fieldNameStringData();
+ if (name == "ns") {
+ ns = elem.valuestrsafe();
+ } else if (name == "op") {
+ opType = elem.valuestrsafe();
+ } else if (name == "o2") {
+ o2 = elem;
+ } else if (name == "v") {
+ version = elem;
+ } else if (name == "o") {
+ o = elem;
+ }
+ }
+}
+
+} // namespace repl
+} // namespace mongo
diff --git a/src/mongo/db/repl/oplog_entry.h b/src/mongo/db/repl/oplog_entry.h
new file mode 100644
index 00000000000..b86851b34d3
--- /dev/null
+++ b/src/mongo/db/repl/oplog_entry.h
@@ -0,0 +1,61 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 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 GNU Affero General 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/bson/bsonobj.h"
+
+namespace mongo {
+namespace repl {
+/**
+ * A parsed oplog entry.
+ *
+ * This only includes the fields used by the code using this object at the time this was
+ * written. As more code uses this, more fields should be added.
+ *
+ * All unowned members (such as StringDatas and BSONElements) point into the raw BSON.
+ * All StringData members are guaranteed to be NUL terminated.
+ */
+struct OplogEntry {
+ explicit OplogEntry(const BSONObj& raw);
+
+ // This member is not parsed from the BSON and is instead populated by fillWriterVectors.
+ bool isForCappedCollection = false;
+
+ BSONObj raw; // Owned.
+
+ StringData ns = "";
+ StringData opType = "";
+
+ BSONElement version;
+ BSONElement o;
+ BSONElement o2;
+};
+
+} // namespace repl
+} // namespace mongo
diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp
index f6a56395827..cd1e9eace81 100644
--- a/src/mongo/db/repl/sync_tail.cpp
+++ b/src/mongo/db/repl/sync_tail.cpp
@@ -432,7 +432,7 @@ void prefetchOp(const BSONObj& op) {
}
// Doles out all the work to the reader pool threads and waits for them to complete
-void prefetchOps(const std::deque<SyncTail::OplogEntry>& ops, OldThreadPool* prefetcherPool) {
+void prefetchOps(const std::deque<OplogEntry>& ops, OldThreadPool* prefetcherPool) {
invariant(prefetcherPool);
for (auto&& op : ops) {
prefetcherPool->schedule(&prefetchOp, op.raw);
@@ -441,12 +441,12 @@ void prefetchOps(const std::deque<SyncTail::OplogEntry>& ops, OldThreadPool* pre
}
// Doles out all the work to the writer pool threads and waits for them to complete
-void applyOps(const std::vector<std::vector<SyncTail::OplogEntry>>& writerVectors,
+void applyOps(const std::vector<std::vector<OplogEntry>>& writerVectors,
OldThreadPool* writerPool,
SyncTail::MultiSyncApplyFunc func,
SyncTail* sync) {
TimerHolder timer(&applyBatchStats);
- for (std::vector<std::vector<SyncTail::OplogEntry>>::const_iterator it = writerVectors.begin();
+ for (std::vector<std::vector<OplogEntry>>::const_iterator it = writerVectors.begin();
it != writerVectors.end();
++it) {
if (!it->empty()) {
@@ -486,8 +486,8 @@ private:
};
void fillWriterVectors(OperationContext* txn,
- const std::deque<SyncTail::OplogEntry>& ops,
- std::vector<std::vector<SyncTail::OplogEntry>>* writerVectors) {
+ const std::deque<OplogEntry>& ops,
+ std::vector<std::vector<OplogEntry>>* writerVectors) {
const bool supportsDocLocking =
getGlobalServiceContext()->getGlobalStorageEngine()->supportsDocLocking();
const uint32_t numWriters = writerVectors->size();
@@ -525,7 +525,7 @@ void fillWriterVectors(OperationContext* txn,
if (op.opType == "i" && isCapped(txn, hashedNs)) {
// Mark capped collection ops before storing them to ensure we do not attempt to bulk
// insert them.
- SyncTail::OplogEntry modifiedOp = op;
+ OplogEntry modifiedOp = op;
modifiedOp.isForCappedCollection = true;
(*writerVectors)[hash % numWriters].push_back(modifiedOp);
} else {
@@ -546,7 +546,7 @@ OpTime SyncTail::multiApply(OperationContext* txn, const OpQueue& ops) {
prefetchOps(ops.getDeque(), &_prefetcherPool);
}
- std::vector<std::vector<SyncTail::OplogEntry>> writerVectors(replWriterThreadCount);
+ std::vector<std::vector<OplogEntry>> writerVectors(replWriterThreadCount);
fillWriterVectors(txn, ops.getDeque(), &writerVectors);
LOG(2) << "replication batch size is " << ops.getDeque().size() << endl;
@@ -832,23 +832,6 @@ void SyncTail::oplogApplication() {
}
}
-SyncTail::OplogEntry::OplogEntry(const BSONObj& rawInput) : raw(rawInput.getOwned()) {
- for (auto elem : raw) {
- const auto name = elem.fieldNameStringData();
- if (name == "ns") {
- ns = elem.valuestrsafe();
- } else if (name == "op") {
- opType = elem.valuestrsafe();
- } else if (name == "o2") {
- o2 = elem;
- } else if (name == "v") {
- version = elem;
- } else if (name == "o") {
- o = elem;
- }
- }
-}
-
// Copies ops out of the bgsync queue into the deque passed in as a parameter.
// Returns true if the batch should be ended early.
// Batch should end early if we encounter a command, or if
@@ -1030,8 +1013,8 @@ static void initializeWriterThread() {
}
// This free function is used by the writer threads to apply each op
-void multiSyncApply(const std::vector<SyncTail::OplogEntry>& ops, SyncTail* st) {
- using OplogEntry = SyncTail::OplogEntry;
+void multiSyncApply(const std::vector<OplogEntry>& ops, SyncTail* st) {
+ using OplogEntry = OplogEntry;
std::vector<OplogEntry> oplogEntries(ops.begin(), ops.end());
std::vector<OplogEntry*> oplogEntryPointers(oplogEntries.size());
@@ -1149,7 +1132,7 @@ void multiSyncApply(const std::vector<SyncTail::OplogEntry>& ops, SyncTail* st)
}
// This free function is used by the initial sync writer threads to apply each op
-void multiInitialSyncApply(const std::vector<SyncTail::OplogEntry>& ops, SyncTail* st) {
+void multiInitialSyncApply(const std::vector<OplogEntry>& ops, SyncTail* st) {
initializeWriterThread();
OperationContextImpl txn;
@@ -1161,8 +1144,7 @@ void multiInitialSyncApply(const std::vector<SyncTail::OplogEntry>& ops, SyncTai
bool convertUpdatesToUpserts = false;
- for (std::vector<SyncTail::OplogEntry>::const_iterator it = ops.begin(); it != ops.end();
- ++it) {
+ for (std::vector<OplogEntry>::const_iterator it = ops.begin(); it != ops.end(); ++it) {
try {
const Status s = SyncTail::syncApply(&txn, it->raw, convertUpdatesToUpserts);
if (!s.isOK()) {
diff --git a/src/mongo/db/repl/sync_tail.h b/src/mongo/db/repl/sync_tail.h
index 85885143487..7fffb39d6e8 100644
--- a/src/mongo/db/repl/sync_tail.h
+++ b/src/mongo/db/repl/sync_tail.h
@@ -32,6 +32,7 @@
#include "mongo/base/status.h"
#include "mongo/bson/bsonobj.h"
+#include "mongo/db/repl/oplog_entry.h"
#include "mongo/db/storage/mmap_v1/dur.h"
#include "mongo/stdx/functional.h"
#include "mongo/util/concurrency/old_thread_pool.h"
@@ -51,31 +52,6 @@ class OpTime;
*/
class SyncTail {
public:
- /**
- * A parsed oplog entry.
- *
- * This only includes the fields used by the code using this object at the time this was
- * written. As more code uses this, more fields should be added.
- *
- * All unowned members (such as StringDatas and BSONElements) point into the raw BSON.
- * All StringData members are guaranteed to be NUL terminated.
- */
- struct OplogEntry {
- explicit OplogEntry(const BSONObj& raw);
-
- // This member is not parsed from the BSON and is instead populated by fillWriterVectors.
- bool isForCappedCollection = false;
-
- BSONObj raw; // Owned.
-
- StringData ns = "";
- StringData opType = "";
-
- BSONElement version;
- BSONElement o;
- BSONElement o2;
- };
-
using MultiSyncApplyFunc =
stdx::function<void(const std::vector<OplogEntry>& ops, SyncTail* st)>;
@@ -203,8 +179,8 @@ private:
};
// These free functions are used by the thread pool workers to write ops to the db.
-void multiSyncApply(const std::vector<SyncTail::OplogEntry>& ops, SyncTail* st);
-void multiInitialSyncApply(const std::vector<SyncTail::OplogEntry>& ops, SyncTail* st);
+void multiSyncApply(const std::vector<OplogEntry>& ops, SyncTail* st);
+void multiInitialSyncApply(const std::vector<OplogEntry>& ops, SyncTail* st);
} // namespace repl
} // namespace mongo
diff --git a/src/mongo/db/repl/sync_tail_test.cpp b/src/mongo/db/repl/sync_tail_test.cpp
index a0534c769df..3d0829151e5 100644
--- a/src/mongo/db/repl/sync_tail_test.cpp
+++ b/src/mongo/db/repl/sync_tail_test.cpp
@@ -124,7 +124,7 @@ void SyncTailTest::tearDown() {
TEST_F(SyncTailTest, Peek) {
BackgroundSyncMock bgsync;
- SyncTail syncTail(&bgsync, [](const std::vector<SyncTail::OplogEntry>& ops, SyncTail* st) {});
+ SyncTail syncTail(&bgsync, [](const std::vector<OplogEntry>& ops, SyncTail* st) {});
BSONObj obj;
ASSERT_FALSE(syncTail.peek(&obj));
}