diff options
author | Eric Milkie <milkie@10gen.com> | 2017-09-12 16:36:07 -0400 |
---|---|---|
committer | Eric Milkie <milkie@10gen.com> | 2017-09-13 13:30:29 -0400 |
commit | dc22fc57bff9e804ef42fbbf19e8f685a2cb434e (patch) | |
tree | cfa959ac4c2fc6ad807a5b1a27331de8c0f3839e | |
parent | 5dbccb4a861aa2db993dd673097a1300bcdc9cca (diff) | |
download | mongo-dc22fc57bff9e804ef42fbbf19e8f685a2cb434e.tar.gz |
SERVER-30639 change getNextOpTimes interface to return a value
-rw-r--r-- | src/mongo/db/catalog/collection_impl.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/ops/write_ops_exec.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 18 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.h | 7 |
4 files changed, 23 insertions, 9 deletions
diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp index d78c3e6f43d..26af94b10ff 100644 --- a/src/mongo/db/catalog/collection_impl.cpp +++ b/src/mongo/db/catalog/collection_impl.cpp @@ -423,7 +423,7 @@ Status CollectionImpl::insertDocument(OperationContext* opCtx, auto replCoord = repl::ReplicationCoordinator::get(opCtx); if (!replCoord->isOplogDisabledFor(opCtx, _ns)) { // Populate 'slot' with a new optime. - repl::getNextOpTimes(opCtx, 1, &slot); + slot = repl::getNextOpTime(opCtx); } inserts.emplace_back(kUninitializedStmtId, doc, slot); diff --git a/src/mongo/db/ops/write_ops_exec.cpp b/src/mongo/db/ops/write_ops_exec.cpp index bfb2d326773..1f92597211c 100644 --- a/src/mongo/db/ops/write_ops_exec.cpp +++ b/src/mongo/db/ops/write_ops_exec.cpp @@ -310,14 +310,13 @@ void insertDocuments(OperationContext* opCtx, // physically written in timestamp order, so we defer optime assignment until the oplog is about // to be written. auto batchSize = std::distance(begin, end); - std::unique_ptr<OplogSlot[]> slots(new OplogSlot[batchSize]); if (supportsDocLocking()) { auto replCoord = repl::ReplicationCoordinator::get(opCtx); if (!replCoord->isOplogDisabledFor(opCtx, collection->ns())) { // Populate 'slots' with new optimes for each insert. // This also notifies the storage engine of each new timestamp. - repl::getNextOpTimes(opCtx, batchSize, slots.get()); - OplogSlot* slot = slots.get(); + auto oplogSlots = repl::getNextOpTimes(opCtx, batchSize); + auto slot = oplogSlots.begin(); for (auto it = begin; it != end; it++) { it->oplogSlot = *slot++; } diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index d377f41df24..cf8c0539ff4 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -623,14 +623,28 @@ void createOplog(OperationContext* opCtx) { createOplog(opCtx, _oplogCollectionName, isReplSet); } -void getNextOpTimes(OperationContext* opCtx, std::size_t count, OplogSlot* slotsOut) { +OplogSlot getNextOpTime(OperationContext* opCtx) { // The local oplog collection pointer must already be established by this point. // We can't establish it here because that would require locking the local database, which would // be a lock order violation. invariant(_localOplogCollection); - _getNextOpTimes(opCtx, _localOplogCollection, count, slotsOut); + OplogSlot os; + _getNextOpTimes(opCtx, _localOplogCollection, 1, &os); + return os; } +std::vector<OplogSlot> getNextOpTimes(OperationContext* opCtx, std::size_t count) { + // The local oplog collection pointer must already be established by this point. + // We can't establish it here because that would require locking the local database, which would + // be a lock order violation. + invariant(_localOplogCollection); + std::vector<OplogSlot> oplogSlots(count); + auto oplogSlot = oplogSlots.begin(); + _getNextOpTimes(opCtx, _localOplogCollection, count, &(*oplogSlot)); + return oplogSlots; +} + + // ------------------------------------- namespace { diff --git a/src/mongo/db/repl/oplog.h b/src/mongo/db/repl/oplog.h index 2198bb86c7e..444b83236a2 100644 --- a/src/mongo/db/repl/oplog.h +++ b/src/mongo/db/repl/oplog.h @@ -215,10 +215,11 @@ void createIndexForApplyOps(OperationContext* opCtx, IncrementOpsAppliedStatsFn incrementOpsAppliedStats); /** - * Allocates optimes for new entries in the oplog. Returns an array of OplogSlots, which contain - * the new optimes along with their terms and newly calculated hash fields. + * Allocates optimes for new entries in the oplog. Returns an OplogSlot or a vector of OplogSlots, + * which contain the new optimes along with their terms and newly calculated hash fields. */ -void getNextOpTimes(OperationContext* opCtx, std::size_t count, OplogSlot* slotsOut); +OplogSlot getNextOpTime(OperationContext* opCtx); +std::vector<OplogSlot> getNextOpTimes(OperationContext* opCtx, std::size_t count); } // namespace repl } // namespace mongo |