diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/op_observer_impl.cpp | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/op_observer_impl.cpp')
| -rw-r--r-- | src/mongo/db/op_observer_impl.cpp | 106 |
1 files changed, 4 insertions, 102 deletions
diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp index 56343465374..75a0ff101c8 100644 --- a/src/mongo/db/op_observer_impl.cpp +++ b/src/mongo/db/op_observer_impl.cpp @@ -38,7 +38,6 @@ #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/batched_write_context.h" -#include "mongo/db/catalog/backwards_compatible_collection_options_util.h" #include "mongo/db/catalog/collection_options.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" @@ -47,7 +46,7 @@ #include "mongo/db/catalog_raii.h" #include "mongo/db/commands/txn_cmds_gen.h" #include "mongo/db/concurrency/d_concurrency.h" -#include "mongo/db/concurrency/exception_util.h" +#include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/exec/write_stage_common.h" #include "mongo/db/index/index_descriptor.h" @@ -72,7 +71,6 @@ #include "mongo/db/server_options.h" #include "mongo/db/session_catalog_mongod.h" #include "mongo/db/timeseries/bucket_catalog.h" -#include "mongo/db/timeseries/timeseries_extended_range.h" #include "mongo/db/transaction_participant.h" #include "mongo/db/transaction_participant_gen.h" #include "mongo/db/views/durable_view_catalog.h" @@ -80,7 +78,6 @@ #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" #include "mongo/scripting/engine.h" -#include "mongo/stdx/mutex.h" #include "mongo/util/assert_util.h" #include "mongo/util/fail_point.h" @@ -247,9 +244,6 @@ OpTimeBundle replLogUpdate(OperationContext* opCtx, oplogEntry->setObject(args.updateArgs->update); oplogEntry->setObject2(args.updateArgs->criteria); oplogEntry->setFromMigrateIfTrue(args.updateArgs->source == OperationSource::kFromMigrate); - if (args.updateArgs->mustCheckExistenceForInsertOperations) { - oplogEntry->setCheckExistenceForDiffInsert(); - } // oplogLink could have been changed to include pre/postImageOpTime by the previous no-op write. repl::appendOplogEntryChainInfo(opCtx, oplogEntry, &oplogLink, args.updateArgs->stmtIds); if (!args.updateArgs->oplogSlots.empty()) { @@ -321,15 +315,8 @@ void writeToImageCollection(OperationContext* opCtx, AllowLockAcquisitionOnTimestampedUnitOfWork allowLockAcquisition(opCtx->lockState()); AutoGetCollection imageCollectionRaii( opCtx, NamespaceString::kConfigImagesNamespace, LockMode::MODE_IX); - auto curOp = CurOp::get(opCtx); - const std::string existingNs = curOp->getNS(); UpdateResult res = Helpers::upsert( opCtx, NamespaceString::kConfigImagesNamespace.toString(), imageEntry.toBSON()); - { - stdx::lock_guard<Client> clientLock(*opCtx->getClient()); - curOp->setNS_inlock(existingNs); - } - invariant(res.numDocsModified == 1 || !res.upsertedId.isEmpty()); } @@ -615,15 +602,7 @@ void OpObserverImpl::onInserts(OperationContext* opCtx, if (nss.coll() == "system.js") { Scope::storedFuncMod(opCtx); } else if (nss.coll() == DurableViewCatalog::viewsCollectionName()) { - try { - for (auto it = first; it != last; it++) { - uassertStatusOK(DurableViewCatalog::onExternalInsert(opCtx, it->doc, nss)); - } - } catch (const DBException&) { - // If a previous operation left the view catalog in an invalid state, our inserts can - // fail even if all the definitions are valid. Reloading may help us reset the state. - DurableViewCatalog::onExternalChange(opCtx, nss); - } + DurableViewCatalog::onExternalChange(opCtx, nss); } else if (nss == NamespaceString::kSessionTransactionsTableNamespace && !lastOpTime.isNull()) { for (auto it = first; it != last; it++) { MongoDSessionCatalog::observeDirectWriteToConfigTransactions(opCtx, it->doc); @@ -646,40 +625,6 @@ void OpObserverImpl::onInserts(OperationContext* opCtx, } }); } - } else if (nss.isTimeseriesBucketsCollection()) { - // Check if the bucket _id is sourced from a date outside the standard range. If our writes - // end up erroring out or getting rolled back, then this flag will stay set. This is okay - // though, as it only disables some query optimizations and won't result in any correctness - // issues if the flag is set when it doesn't need to be (as opposed to NOT being set when it - // DOES need to be -- that will cause correctness issues). Additionally, if the user tried - // to insert measurements with dates outside the standard range, chances are they will do so - // again, and we will have only set the flag a little early. - invariant(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_IX)); - auto bucketsColl = - CollectionCatalog::get(opCtx)->lookupCollectionByNamespaceForRead(opCtx, nss); - tassert(6905201, "Could not find collection for write", bucketsColl); - auto timeSeriesOptions = bucketsColl->getTimeseriesOptions(); - if (timeSeriesOptions.has_value()) { - if (auto currentSetting = bucketsColl->getRequiresTimeseriesExtendedRangeSupport(); - !currentSetting && - timeseries::bucketsHaveDateOutsideStandardRange( - timeSeriesOptions.value(), first, last)) { - bucketsColl->setRequiresTimeseriesExtendedRangeSupport(opCtx); - } - } - - uassert( - ErrorCodes::CannotInsertTimeseriesBucketsWithMixedSchema, - "Cannot write time-series bucket containing mixed schema data, please ensure all nodes " - "are upgraded to the latest v6.0 release, run collMod with " - "timeseriesBucketsMayHaveMixedSchemaData, and retry your insert", - !opCtx->isEnforcingConstraints() || - bucketsColl->getTimeseriesBucketsMayHaveMixedSchemaData().value_or(false) || - std::none_of(first, last, [bucketsColl](auto&& insert) { - auto mixedSchema = - bucketsColl->doesTimeseriesBucketsDocContainMixedSchemaData(insert.doc); - return mixedSchema.isOK() && mixedSchema.getValue(); - })); } } @@ -769,21 +714,10 @@ void OpObserverImpl::onUpdate(OperationContext* opCtx, const OplogUpdateEntryArg operation.setChangeStreamPreImageRecordingMode( ChangeStreamPreImageRecordingMode::kPreImagesCollection); } - - auto collectionDescription = - CollectionShardingState::get(opCtx, args.nss)->getCollectionDescription(opCtx); - if (collectionDescription.isSharded()) { - operation.setPostImageDocumentKey( - collectionDescription.extractDocumentKey(args.updateArgs->updatedDoc).getOwned()); - } - operation.setDestinedRecipient( shardingWriteRouter.getReshardingDestinedRecipient(args.updateArgs->updatedDoc)); operation.setFromMigrateIfTrue_BackwardsCompatible(args.updateArgs->source == OperationSource::kFromMigrate); - if (args.updateArgs->mustCheckExistenceForInsertOperations) { - operation.setCheckExistenceForDiffInsert(true); - } txnParticipant.addTransactionOperation(opCtx, operation); } else { MutableOplogEntry oplogEntry; @@ -879,26 +813,6 @@ void OpObserverImpl::onUpdate(OperationContext* opCtx, const OplogUpdateEntryArg opCtx, args.updateArgs->updatedDoc["_id"], args.updateArgs->updatedDoc); } else if (args.nss.isTimeseriesBucketsCollection()) { if (args.updateArgs->source != OperationSource::kTimeseriesInsert) { - invariant(opCtx->lockState()->isCollectionLockedForMode(args.nss, MODE_IX)); - auto bucketsColl = - CollectionCatalog::get(opCtx)->lookupCollectionByNamespaceForRead(opCtx, args.nss); - tassert(8453101, "Could not find collection for write", bucketsColl); - - auto mixedSchema = [&args, &bucketsColl] { - auto result = bucketsColl->doesTimeseriesBucketsDocContainMixedSchemaData( - args.updateArgs->updatedDoc); - return result.isOK() && result.getValue(); - }; - - uassert( - ErrorCodes::CannotInsertTimeseriesBucketsWithMixedSchema, - "Cannot write time-series bucket containing mixed schema data, please ensure all " - "nodes are upgraded to the latest v6.0 release, run collMod with " - "timeseriesBucketsMayHaveMixedSchemaData, and retry your update", - !opCtx->isEnforcingConstraints() || - bucketsColl->getTimeseriesBucketsMayHaveMixedSchemaData().value_or(false) || - !mixedSchema()); - auto& bucketCatalog = BucketCatalog::get(opCtx); bucketCatalog.clear(args.updateArgs->updatedDoc["_id"].OID()); } @@ -1071,7 +985,7 @@ void OpObserverImpl::onDelete(OperationContext* opCtx, ShardingWriteRouter shardingWriteRouter(opCtx, nss, Grid::get(opCtx)->catalogCache()); shardObserveDeleteOp(opCtx, nss, - documentKey, + documentKey.getShardKeyAndId(), opTime.writeOpTime, shardingWriteRouter, opTime.prePostImageOpTime, @@ -1155,8 +1069,6 @@ void OpObserverImpl::onCollMod(OperationContext* opCtx, const BSONObj& collModCmd, const CollectionOptions& oldCollOptions, boost::optional<IndexCollModInfo> indexInfo) { - const auto [collModOplogCmd, additionalO2Field] = - backwards_compatible_collection_options::getCollModCmdAndAdditionalO2Field(collModCmd); if (!nss.isSystemDotProfile()) { // do not replicate system.profile modifications @@ -1164,10 +1076,6 @@ void OpObserverImpl::onCollMod(OperationContext* opCtx, // Create the 'o2' field object. We save the old collection metadata and TTL expiration. BSONObjBuilder o2Builder; o2Builder.append("collectionOptions_old", oldCollOptions.toBSON()); - if (!additionalO2Field.isEmpty()) { - o2Builder.append(backwards_compatible_collection_options::additionalCollModO2Field, - additionalO2Field); - } if (indexInfo) { BSONObjBuilder oldIndexOptions; if (indexInfo->oldExpireAfterSeconds) { @@ -1190,7 +1098,7 @@ void OpObserverImpl::onCollMod(OperationContext* opCtx, oplogEntry.setOpType(repl::OpTypeEnum::kCommand); oplogEntry.setNss(nss.getCommandNS()); oplogEntry.setUuid(uuid); - oplogEntry.setObject(repl::makeCollModCmdObj(collModOplogCmd, oldCollOptions, indexInfo)); + oplogEntry.setObject(repl::makeCollModCmdObj(collModCmd, oldCollOptions, indexInfo)); oplogEntry.setObject2(o2Builder.done()); logOperation(opCtx, &oplogEntry); } @@ -2264,12 +2172,6 @@ void OpObserverImpl::onTransactionPrepare( shardObserveTransactionPrepareOrUnpreparedCommit(opCtx, *statements, prepareOpTime); } -void OpObserverImpl::onTransactionPrepareNonPrimary(OperationContext* opCtx, - const std::vector<repl::OplogEntry>& statements, - const repl::OpTime& prepareOpTime) { - shardObserveNonPrimaryTransactionPrepare(opCtx, statements, prepareOpTime); -} - void OpObserverImpl::onTransactionAbort(OperationContext* opCtx, boost::optional<OplogSlot> abortOplogEntryOpTime) { invariant(opCtx->getTxnNumber()); |
