diff options
author | Pavi Vetriselvan <pavithra.vetriselvan@mongodb.com> | 2021-02-02 11:26:23 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-04 01:36:53 +0000 |
commit | 3a02c6d491ee701bcf6180285a260b5e1e9c9346 (patch) | |
tree | 883ef460b9f21ded6a611bfda4d6306fd0cbeac2 /src/mongo/db/repl/tenant_migration_util.cpp | |
parent | 2dabb75cad1228ab235ae4978e5dec6514ac03c5 (diff) | |
download | mongo-3a02c6d491ee701bcf6180285a260b5e1e9c9346.tar.gz |
SERVER-53319 move createRetryableWritesView into tenant_migration_util
Diffstat (limited to 'src/mongo/db/repl/tenant_migration_util.cpp')
-rw-r--r-- | src/mongo/db/repl/tenant_migration_util.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/mongo/db/repl/tenant_migration_util.cpp b/src/mongo/db/repl/tenant_migration_util.cpp index 8b789a55ca5..66c39f1a897 100644 --- a/src/mongo/db/repl/tenant_migration_util.cpp +++ b/src/mongo/db/repl/tenant_migration_util.cpp @@ -107,6 +107,41 @@ ExecutorFuture<void> storeExternalClusterTimeKeyDocsAndRefreshCache( }); } +void createRetryableWritesView(OperationContext* opCtx, Database* db) { + writeConflictRetry( + opCtx, "createDonorOplogView", "local.system.tenantMigration.oplogView", [&] { + { + // Create 'system.views' in a separate WUOW if it does not exist. + WriteUnitOfWork wuow(opCtx); + CollectionPtr coll = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace( + opCtx, NamespaceString(db->getSystemViewsName())); + if (!coll) { + coll = db->createCollection(opCtx, NamespaceString(db->getSystemViewsName())); + } + invariant(coll); + wuow.commit(); + } + + // First match entries with a `stmtId` so that we're filtering for retryable writes + // oplog entries. Pass the result into the next stage of the pipeline and only project + // the fields that a tenant migration recipient needs to refetch retryable writes oplog + // entries: `ts`, `prevOpTime`, `preImageOpTime`, and `postImageOpTime`. + CollectionOptions options; + options.viewOn = NamespaceString::kRsOplogNamespace.coll().toString(); + options.pipeline = BSON_ARRAY( + BSON("$match" << BSON("stmtId" << BSON("$exists" << true))) + << BSON("$project" << BSON("_id" + << "$ts" + << "ns" << 1 << "ts" << 1 << "prevOpTime" << 1 + << "preImageOpTime" << 1 << "postImageOpTime" << 1))); + + WriteUnitOfWork wuow(opCtx); + uassertStatusOK(db->createView( + opCtx, NamespaceString("local.system.tenantMigration.oplogView"), options)); + wuow.commit(); + }); +} + } // namespace tenant_migration_util } // namespace mongo |