diff options
-rw-r--r-- | src/mongo/db/catalog/collection.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp index 36f73778483..1341599ab65 100644 --- a/src/mongo/db/catalog/collection.cpp +++ b/src/mongo/db/catalog/collection.cpp @@ -107,20 +107,23 @@ bool CollectionPtr::_canYield() const { } void CollectionPtr::yield() const { - if (_canYield()) { + // Yield if we are yieldable and have a valid collection + if (_canYield() && _collection) { _uuid = _collection->uuid(); _ns = _collection->ns(); _collection = nullptr; } } void CollectionPtr::restore() const { - if (_canYield()) { + // Restore from yield if we are yieldable and if uuid was set in a previous yield. + if (_canYield() && _uuid) { // We may only do yield restore when we were holding locks that was yielded so we need to // refresh from the catalog to make sure we have a valid collection pointer. auto coll = _catalogLookup()(_opCtx, *_uuid, _catalogEpoch); if (coll && coll->ns() == _ns) { _collection = coll.get(); } + _uuid.reset(); } } |