File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
modules/module-mysql/src/replication Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -484,7 +484,19 @@ AND table_type = 'BASE TABLE';`,
484
484
} ,
485
485
onCommit : async ( lsn : string ) => {
486
486
this . metrics . getCounter ( ReplicationMetric . TRANSACTIONS_REPLICATED ) . add ( 1 ) ;
487
- await batch . commit ( lsn ) ;
487
+ const didCommit = await batch . commit ( lsn , { oldestUncommittedChange : this . oldestUncommittedChange } ) ;
488
+ if ( didCommit ) {
489
+ this . oldestUncommittedChange = null ;
490
+ this . isStartingReplication = false ;
491
+ }
492
+ } ,
493
+ onTransactionStart : async ( options ) => {
494
+ if ( this . oldestUncommittedChange == null ) {
495
+ this . oldestUncommittedChange = options . timestamp ;
496
+ }
497
+ } ,
498
+ onRotate : async ( ) => {
499
+ this . isStartingReplication = false ;
488
500
}
489
501
} ;
490
502
}
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ const MAX_QUEUE_PAUSE_TIME_MS = 45_000;
12
12
export type Row = Record < string , any > ;
13
13
14
14
export interface BinLogEventHandler {
15
+ onTransactionStart : ( options : { timestamp : Date } ) => Promise < void > ;
16
+ onRotate : ( ) => Promise < void > ;
15
17
onWrite : ( rows : Row [ ] , tableMap : TableMapEntry ) => Promise < void > ;
16
18
onUpdate : ( rowsAfter : Row [ ] , rowsBefore : Row [ ] , tableMap : TableMapEntry ) => Promise < void > ;
17
19
onDelete : ( rows : Row [ ] , tableMap : TableMapEntry ) => Promise < void > ;
@@ -196,10 +198,12 @@ export class BinLogListener {
196
198
offset : evt . nextPosition
197
199
}
198
200
} ) ;
201
+ await this . eventHandler . onTransactionStart ( { timestamp : new Date ( evt . timestamp ) } ) ;
199
202
break ;
200
203
case zongji_utils . eventIsRotation ( evt ) :
201
204
this . binLogPosition . filename = evt . binlogName ;
202
205
this . binLogPosition . offset = evt . position ;
206
+ await this . eventHandler . onRotate ( ) ;
203
207
break ;
204
208
case zongji_utils . eventIsWriteMutation ( evt ) :
205
209
await this . eventHandler . onWrite ( evt . rows , evt . tableMap [ evt . tableId ] ) ;
You can’t perform that action at this time.
0 commit comments