diff options
author | Erwin Pe <erwin.pe@mongodb.com> | 2022-08-22 13:22:50 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-22 13:54:19 +0000 |
commit | ce2913d15a9c5eb063ec2c41e0097370ce46c1b3 (patch) | |
tree | ec3d26c59ce3e6cf320351923a94b4dec7560827 | |
parent | ba75ef94152996b7b61b2da9f22a772cb160d731 (diff) | |
download | mongo-ce2913d15a9c5eb063ec2c41e0097370ce46c1b3.tar.gz |
SERVER-68461 Persist the result of the doCompactOperation in the Pre61Compatible compaction coordinator
3 files changed, 51 insertions, 1 deletions
diff --git a/src/mongo/db/s/compact_structured_encryption_data_coordinator.cpp b/src/mongo/db/s/compact_structured_encryption_data_coordinator.cpp index 836dde1bf79..bbf34ba008f 100644 --- a/src/mongo/db/s/compact_structured_encryption_data_coordinator.cpp +++ b/src/mongo/db/s/compact_structured_encryption_data_coordinator.cpp @@ -213,6 +213,39 @@ boost::optional<BSONObj> CompactStructuredEncryptionDataCoordinator::reportForCu return bob.obj(); } +// TODO: SERVER-68373 remove once 7.0 becomes last LTS +void CompactStructuredEncryptionDataCoordinator::_enterPhase(const Phase& newPhase) { + // Before 6.1, this coordinator persists the result of the doCompactOperation() + // by reusing the compactionTokens field to store the _response BSON. + // If newPhase is kDropTempCollection, this override of _enterPhase performs this + // replacement on the in-memory state document (_doc), before calling the base _enterPhase() + // which persists _doc to disk. In the event that updating the persisted document fails, + // the replaced compaction tokens are restored in _doc. + using Base = RecoverableShardingDDLCoordinator<CompactStructuredEncryptionDataState, + CompactStructuredEncryptionDataPhaseEnum>; + bool useOverload = _isPre61Compatible() && (newPhase == Phase::kDropTempCollection); + + if (useOverload) { + BSONObj compactionTokensCopy; + { + stdx::lock_guard lg(_docMutex); + compactionTokensCopy = _doc.getCompactionTokens().getOwned(); + _doc.setCompactionTokens(_response->toBSON()); + } + + try { + Base::_enterPhase(newPhase); + } catch (...) { + // on error, restore the compaction tokens + stdx::lock_guard lg(_docMutex); + _doc.setCompactionTokens(std::move(compactionTokensCopy)); + throw; + } + } else { + Base::_enterPhase(newPhase); + } +} + ExecutorFuture<void> CompactStructuredEncryptionDataCoordinator::_runImpl( std::shared_ptr<executor::ScopedTaskExecutor> executor, const CancellationToken& token) noexcept { @@ -236,7 +269,21 @@ ExecutorFuture<void> CompactStructuredEncryptionDataCoordinator::_runImpl( if (!_isPre61Compatible()) { invariant(_doc.getResponse()); _response = *_doc.getResponse(); + } else { + try { + // restore the response that was stored in the compactionTokens field + IDLParserContext ctxt("response"); + _response = CompactStructuredEncryptionDataCommandReply::parse( + ctxt, _doc.getCompactionTokens()); + } catch (...) { + LOGV2_ERROR(6846101, + "Failed to parse response from " + "CompactStructuredEncryptionDataState document", + "response"_attr = _doc.getCompactionTokens()); + // ignore for compatibility with 6.0.0 + } } + doDropOperation(_doc); if (MONGO_unlikely(fleCompactHangAfterDropTempCollection.shouldFail())) { LOGV2(6790902, "Hanging due to fleCompactHangAfterDropTempCollection fail point"); diff --git a/src/mongo/db/s/compact_structured_encryption_data_coordinator.h b/src/mongo/db/s/compact_structured_encryption_data_coordinator.h index bb0667add70..3b8c9ad2a9e 100644 --- a/src/mongo/db/s/compact_structured_encryption_data_coordinator.h +++ b/src/mongo/db/s/compact_structured_encryption_data_coordinator.h @@ -79,6 +79,9 @@ private: DDLCoordinatorTypeEnum::kCompactStructuredEncryptionDataPre61Compatible; } + // TODO SERVER-68373 remove once 7.0 becomes last LTS + void _enterPhase(const Phase& newPhase) override; + private: boost::optional<CompactStructuredEncryptionDataCommandReply> _response; bool _skipCompact{false}; diff --git a/src/mongo/db/s/sharding_ddl_coordinator.h b/src/mongo/db/s/sharding_ddl_coordinator.h index ecbd0980a41..d8eaad0139d 100644 --- a/src/mongo/db/s/sharding_ddl_coordinator.h +++ b/src/mongo/db/s/sharding_ddl_coordinator.h @@ -271,7 +271,7 @@ protected: }; } - void _enterPhase(const Phase& newPhase) { + virtual void _enterPhase(const Phase& newPhase) { auto newDoc = [&] { stdx::lock_guard lk{_docMutex}; return _doc; |