diff options
Diffstat (limited to 'src/mongo/db/repl/change_stream_oplog_notification.cpp')
-rw-r--r-- | src/mongo/db/repl/change_stream_oplog_notification.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/mongo/db/repl/change_stream_oplog_notification.cpp b/src/mongo/db/repl/change_stream_oplog_notification.cpp index 1c8fb6a78c2..0f8e1a2e0b2 100644 --- a/src/mongo/db/repl/change_stream_oplog_notification.cpp +++ b/src/mongo/db/repl/change_stream_oplog_notification.cpp @@ -102,20 +102,29 @@ void notifyChangeStreamsOnShardCollection(OperationContext* opCtx, void notifyChangeStreamsOnDatabaseAdded(OperationContext* opCtx, const DatabasesAdded& databasesAddedNotification) { - const auto& notifiedPhase = databasesAddedNotification.getPhase(); + const std::string operationName = [&] { + switch (databasesAddedNotification.getPhase()) { + case CommitPhaseEnum::kSuccessful: + return "createDatabase"; + case CommitPhaseEnum::kAborted: + return "createDatabaseAbort"; + case CommitPhaseEnum::kPrepare: + return "createDatabasePrepare"; + default: + MONGO_UNREACHABLE; + } + }(); + for (const auto& dbName : databasesAddedNotification.getNames()) { repl::MutableOplogEntry oplogEntry; oplogEntry.setOpType(repl::OpTypeEnum::kNoop); oplogEntry.setNss(NamespaceString(dbName)); oplogEntry.setTid(dbName.tenantId()); - oplogEntry.setObject(BSON("msg" << BSON("createDatabase" << dbName.db()))); + oplogEntry.setObject(BSON("msg" << BSON(operationName << dbName.db()))); BSONObjBuilder o2Builder; - o2Builder.append("createDatabase", dbName.db()); - if (notifiedPhase) { - o2Builder.append("phase", *notifiedPhase); - if (*notifiedPhase == CommitPhaseEnum::kPrepare) { - o2Builder.append("primaryShard", *databasesAddedNotification.getPrimaryShard()); - } + o2Builder.append(operationName, dbName.db()); + if (databasesAddedNotification.getPhase() == CommitPhaseEnum::kPrepare) { + o2Builder.append("primaryShard", *databasesAddedNotification.getPrimaryShard()); } o2Builder.append("isImported", databasesAddedNotification.getAreImported()); |