diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2019-10-07 15:24:36 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-07 15:24:36 +0000 |
commit | add5e59c4b2a2e2229f4c08bc42daa060307e123 (patch) | |
tree | dd9b9e99b3c4af9e7b8e5b552cb1a7a398d4d171 /src/mongo/db | |
parent | db72f68739de5e01b11ce3b02e0540ef2b2bd601 (diff) | |
download | mongo-add5e59c4b2a2e2229f4c08bc42daa060307e123.tar.gz |
SERVER-43823 Fail background validation if restartCatalog runs while validate locks are yielded
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/catalog/catalog_control.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/catalog/validate_state.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/catalog/validate_state.h | 3 | ||||
-rw-r--r-- | src/mongo/db/service_context.h | 11 |
4 files changed, 21 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/catalog_control.cpp b/src/mongo/db/catalog/catalog_control.cpp index 0bbdf6b81a0..b7e4dfae103 100644 --- a/src/mongo/db/catalog/catalog_control.cpp +++ b/src/mongo/db/catalog/catalog_control.cpp @@ -189,6 +189,7 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib // Opening CollectionCatalog: The collection catalog is now in sync with the storage engine // catalog. Clear the pre-closing state. CollectionCatalog::get(opCtx).onOpenCatalog(opCtx); + opCtx->getServiceContext()->incrementCatalogGeneration(); log() << "openCatalog: finished reloading collection catalog"; } } // namespace catalog diff --git a/src/mongo/db/catalog/validate_state.cpp b/src/mongo/db/catalog/validate_state.cpp index 71c6684a51f..1ab76ef20b2 100644 --- a/src/mongo/db/catalog/validate_state.cpp +++ b/src/mongo/db/catalog/validate_state.cpp @@ -81,6 +81,7 @@ ValidateState::ValidateState(OperationContext* opCtx, } _uuid = _collection->uuid(); + _catalogGeneration = opCtx->getServiceContext()->getCatalogGeneration(); } void ValidateState::yieldLocks(OperationContext* opCtx) { @@ -89,6 +90,11 @@ void ValidateState::yieldLocks(OperationContext* opCtx) { // Drop and reacquire the locks. _relockDatabaseAndCollection(opCtx); + uassert(ErrorCodes::Interrupted, + str::stream() << "Interrupted due to: catalog restart: " << _nss << " (" << *_uuid + << ") while validating the collection", + _catalogGeneration == opCtx->getServiceContext()->getCatalogGeneration()); + // Check if any of the indexes we were validating were dropped. Indexes created while // yielding will be ignored. for (const auto& index : _indexes) { diff --git a/src/mongo/db/catalog/validate_state.h b/src/mongo/db/catalog/validate_state.h index eb3ce80285b..ce2b342bbc3 100644 --- a/src/mongo/db/catalog/validate_state.h +++ b/src/mongo/db/catalog/validate_state.h @@ -169,6 +169,9 @@ private: RecordId _firstRecordId; DataThrottle _dataThrottle; + + // Used to detect when the catalog is re-opened while yielding locks. + uint64_t _catalogGeneration; }; } // namespace CollectionValidation diff --git a/src/mongo/db/service_context.h b/src/mongo/db/service_context.h index 3d4fdd1609b..178a3ff19a6 100644 --- a/src/mongo/db/service_context.h +++ b/src/mongo/db/service_context.h @@ -510,6 +510,14 @@ public: */ BatonHandle makeBaton(OperationContext* opCtx) const; + uint64_t getCatalogGeneration() const { + return _catalogGeneration.load(); + } + + void incrementCatalogGeneration() { + _catalogGeneration.fetchAndAdd(1); + } + private: class ClientObserverHolder { public: @@ -592,6 +600,9 @@ private: // Counter for assigning operation ids. AtomicWord<unsigned> _nextOpId{1}; + // When the catalog is restarted, the generation goes up by one each time. + AtomicWord<uint64_t> _catalogGeneration{0}; + bool _startupComplete = false; stdx::condition_variable _startupCompleteCondVar; }; |