diff options
author | Andrew Morrow <acm@mongodb.com> | 2016-04-15 12:46:30 -0400 |
---|---|---|
committer | Andrew Morrow <acm@mongodb.com> | 2016-04-15 14:16:14 -0400 |
commit | 9f1b2799bf446d8aea806523a574878fcfa6be62 (patch) | |
tree | 5924b40ac85bdd4e41f96a4cdf13ea742b8f581e /src/mongo/db/catalog/collection.cpp | |
parent | f1bfcba98689943266d0269af2a8405b528d2d07 (diff) | |
download | mongo-9f1b2799bf446d8aea806523a574878fcfa6be62.tar.gz |
SERVER-16221 SERVER-22703 ObOpserver may be nullptr in tests
Diffstat (limited to 'src/mongo/db/catalog/collection.cpp')
-rw-r--r-- | src/mongo/db/catalog/collection.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp index c7de03a69de..2a4e3aaaee4 100644 --- a/src/mongo/db/catalog/collection.cpp +++ b/src/mongo/db/catalog/collection.cpp @@ -360,7 +360,9 @@ Status Collection::insertDocuments(OperationContext* txn, return status; invariant(sid == txn->recoveryUnit()->getSnapshotId()); - getGlobalServiceContext()->getOpObserver()->onInserts(txn, ns(), begin, end, fromMigrate); + auto opObserver = getGlobalServiceContext()->getOpObserver(); + if (opObserver) + opObserver->onInserts(txn, ns(), begin, end, fromMigrate); txn->recoveryUnit()->onCommit([this]() { notifyCappedWaitersIfNeeded(); }); @@ -403,7 +405,10 @@ Status Collection::insertDocument(OperationContext* txn, vector<BSONObj> docs; docs.push_back(doc); - getGlobalServiceContext()->getOpObserver()->onInserts(txn, ns(), docs.begin(), docs.end()); + + auto opObserver = getGlobalServiceContext()->getOpObserver(); + if (opObserver) + opObserver->onInserts(txn, ns(), docs.begin(), docs.end()); txn->recoveryUnit()->onCommit([this]() { notifyCappedWaitersIfNeeded(); }); @@ -487,8 +492,10 @@ void Collection::deleteDocument(OperationContext* txn, Snapshotted<BSONObj> doc = docFor(txn, loc); + OpObserver::DeleteState deleteState; auto opObserver = getGlobalServiceContext()->getOpObserver(); - OpObserver::DeleteState deleteState = opObserver->aboutToDelete(txn, ns(), doc.value()); + if (opObserver) + deleteState = opObserver->aboutToDelete(txn, ns(), doc.value()); /* check if any cursors point to us. if so, advance them. */ _cursorManager.invalidateDocument(txn, loc, INVALIDATION_DELETION); @@ -497,7 +504,8 @@ void Collection::deleteDocument(OperationContext* txn, _recordStore->deleteRecord(txn, loc); - opObserver->onDelete(txn, ns(), std::move(deleteState), fromMigrate); + if (opObserver) + opObserver->onDelete(txn, ns(), std::move(deleteState), fromMigrate); } Counter64 moveCounter; @@ -616,7 +624,10 @@ StatusWith<RecordId> Collection::updateDocument(OperationContext* txn, return StatusWith<RecordId>(s); invariant(sid == txn->recoveryUnit()->getSnapshotId()); args->updatedDoc = newDoc; - getGlobalServiceContext()->getOpObserver()->onUpdate(txn, *args); + + auto opObserver = getGlobalServiceContext()->getOpObserver(); + if (opObserver) + opObserver->onUpdate(txn, *args); return newLocation; } @@ -643,7 +654,10 @@ StatusWith<RecordId> Collection::updateDocument(OperationContext* txn, invariant(sid == txn->recoveryUnit()->getSnapshotId()); args->updatedDoc = newDoc; - getGlobalServiceContext()->getOpObserver()->onUpdate(txn, *args); + + auto opObserver = getGlobalServiceContext()->getOpObserver(); + if (opObserver) + opObserver->onUpdate(txn, *args); return newLocation; } @@ -691,7 +705,10 @@ StatusWith<RecordData> Collection::updateDocumentWithDamages( if (newRecStatus.isOK()) { args->updatedDoc = newRecStatus.getValue().toBson(); - getGlobalServiceContext()->getOpObserver()->onUpdate(txn, *args); + + auto opObserver = getGlobalServiceContext()->getOpObserver(); + if (opObserver) + opObserver->onUpdate(txn, *args); } return newRecStatus; } |