summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2015-06-04 15:45:16 -0400
committerBenety Goh <benety@mongodb.com>2015-06-09 12:38:31 -0400
commit089c07c95443283390db78937ab5785041b991fd (patch)
tree4441fae4128e355057eb6515823a41cf40b993b9 /src/mongo/db
parent1e3a1c444432e05d72da58d8d2d82db7638cace8 (diff)
downloadmongo-089c07c95443283390db78937ab5785041b991fd.tar.gz
SERVER-18807 local oplog should grab database and collection locks
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/repl/oplog_interface_local.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/mongo/db/repl/oplog_interface_local.cpp b/src/mongo/db/repl/oplog_interface_local.cpp
index 14a2906217b..c005865e9b0 100644
--- a/src/mongo/db/repl/oplog_interface_local.cpp
+++ b/src/mongo/db/repl/oplog_interface_local.cpp
@@ -31,6 +31,7 @@
#include "mongo/db/repl/oplog_interface_local.h"
#include "mongo/db/db_raii.h"
+#include "mongo/db/namespace_string.h"
#include "mongo/db/query/internal_plans.h"
#include "mongo/db/query/plan_executor.h"
#include "mongo/util/mongoutils/str.h"
@@ -43,22 +44,31 @@ namespace {
class OplogIteratorLocal : public OplogInterface::Iterator {
public:
- OplogIteratorLocal(std::unique_ptr<OldClientContext> ctx,
- std::unique_ptr<PlanExecutor> exec);
+ OplogIteratorLocal(OperationContext* txn,
+ const std::string& collectionName);
StatusWith<Value> next() override;
private:
- std::unique_ptr<OldClientContext> _ctx;
+ ScopedTransaction _transaction;
+ Lock::DBLock _dbLock;
+ Lock::CollectionLock _collectionLock;
+ OldClientContext _ctx;
std::unique_ptr<PlanExecutor> _exec;
};
- OplogIteratorLocal::OplogIteratorLocal(std::unique_ptr<OldClientContext> ctx,
- std::unique_ptr<PlanExecutor> exec)
- : _ctx(std::move(ctx)),
- _exec(std::move(exec)) { }
+ OplogIteratorLocal::OplogIteratorLocal(OperationContext* txn,
+ const std::string& collectionName)
+ : _transaction(txn, MODE_IS),
+ _dbLock(txn->lockState(), nsToDatabase(collectionName), MODE_IS),
+ _collectionLock(txn->lockState(), collectionName, MODE_S),
+ _ctx(txn, collectionName),
+ _exec(InternalPlanner::collectionScan(txn,
+ collectionName,
+ _ctx.db()->getCollection(collectionName),
+ InternalPlanner::BACKWARD)) { }
StatusWith<OplogInterface::Iterator::Value> OplogIteratorLocal::next() {
BSONObj obj;
@@ -89,14 +99,8 @@ namespace {
}
std::unique_ptr<OplogInterface::Iterator> OplogInterfaceLocal::makeIterator() const {
- std::unique_ptr<OldClientContext> ctx(new OldClientContext(_txn, _collectionName));
- std::unique_ptr<PlanExecutor> exec(
- InternalPlanner::collectionScan(_txn,
- _collectionName,
- ctx->db()->getCollection(_collectionName),
- InternalPlanner::BACKWARD));
return std::unique_ptr<OplogInterface::Iterator>(
- new OplogIteratorLocal(std::move(ctx), std::move(exec)));
+ new OplogIteratorLocal(_txn, _collectionName));
}
} // namespace repl