@@ -155,7 +155,6 @@ export class MongoBucketBatchV3 extends MongoBucketBatch {
155155 } ) ) ;
156156
157157 let result : storage . ResolveTablesResult | null = null ;
158- let ensureSourceRecordIndexesFor : bson . ObjectId [ ] = [ ] ;
159158 const session = this . db . client . startSession ( ) ;
160159 await using _ = { [ Symbol . asyncDispose ] : ( ) => session . endSession ( ) } ;
161160
@@ -239,6 +238,7 @@ export class MongoBucketBatchV3 extends MongoBucketBatch {
239238 sourceTable . storeCurrentData = sendsCompleteRows !== true ;
240239
241240 await col . insertOne ( createDoc , { session } ) ;
241+ await this . db . initializeSourceRecordsCollection ( this . replicationStreamId , createDoc . _id , session ) ;
242242 retainedDocIds . push ( createDoc . _id ) ;
243243 tables . push ( sourceTable ) ;
244244 }
@@ -254,7 +254,6 @@ export class MongoBucketBatchV3 extends MongoBucketBatch {
254254 table . syncEvent = table === eventCarrier ;
255255 }
256256 }
257- ensureSourceRecordIndexesFor = retainedDocIds ;
258257
259258 const retainedDocIdStrings = new Set ( retainedDocIds . map ( ( id ) => id . toHexString ( ) ) ) ;
260259 const conflictingTables = candidateDocs . filter (
@@ -269,14 +268,6 @@ export class MongoBucketBatchV3 extends MongoBucketBatch {
269268 } ;
270269 } ) ;
271270
272- // Index creation is idempotent. Running it for all retained tables - not only newly
273- // created ones - heals the index if an earlier resolveTables crashed between inserting
274- // the document and reaching this point (this runs outside the session on purpose, since
275- // index creation cannot be transactional).
276- for ( const sourceTableId of ensureSourceRecordIndexesFor ) {
277- await this . db . initializeSourceRecordsCollection ( this . replicationStreamId , sourceTableId ) ;
278- }
279-
280271 return result ! ;
281272 }
282273
0 commit comments