@@ -356,12 +356,12 @@ func (e *QueryEvent) Dump(w io.Writer) {
356
356
fmt .Fprintln (w )
357
357
}
358
358
359
- type MySQLGTIDEvent struct {
359
+ type GTIDEvent struct {
360
360
CommitFlag uint8
361
361
SID []byte
362
362
GNO int64
363
- LastCommitted int64
364
- SequenceNumber int64
363
+ lastCommitted int64
364
+ sequenceNumber int64
365
365
366
366
// ImmediateCommitTimestamp/OriginalCommitTimestamp are introduced in MySQL-8.0.1, see:
367
367
// https://mysqlhighavailability.com/replication-features-in-mysql-8-0-1/
@@ -378,7 +378,7 @@ type MySQLGTIDEvent struct {
378
378
OriginalServerVersion uint32
379
379
}
380
380
381
- func (e * MySQLGTIDEvent ) Decode (data []byte ) error {
381
+ func (e * GTIDEvent ) Decode (data []byte ) error {
382
382
pos := 0
383
383
e .CommitFlag = data [pos ]
384
384
pos ++
@@ -390,9 +390,9 @@ func (e *MySQLGTIDEvent) Decode(data []byte) error {
390
390
if len (data ) >= 42 {
391
391
if data [pos ] == LogicalTimestampTypeCode {
392
392
pos ++
393
- e .LastCommitted = int64 (binary .LittleEndian .Uint64 (data [pos :]))
393
+ e .lastCommitted = int64 (binary .LittleEndian .Uint64 (data [pos :]))
394
394
pos += PartLogicalTimestampLength
395
- e .SequenceNumber = int64 (binary .LittleEndian .Uint64 (data [pos :]))
395
+ e .sequenceNumber = int64 (binary .LittleEndian .Uint64 (data [pos :]))
396
396
pos += 8
397
397
398
398
// IMMEDIATE_COMMIT_TIMESTAMP_LENGTH = 7
@@ -441,7 +441,7 @@ func (e *MySQLGTIDEvent) Decode(data []byte) error {
441
441
return nil
442
442
}
443
443
444
- func (e * MySQLGTIDEvent ) Dump (w io.Writer ) {
444
+ func (e * GTIDEvent ) Dump (w io.Writer ) {
445
445
fmtTime := func (t time.Time ) string {
446
446
if t .IsZero () {
447
447
return "<n/a>"
@@ -452,8 +452,8 @@ func (e *MySQLGTIDEvent) Dump(w io.Writer) {
452
452
fmt .Fprintf (w , "Commit flag: %d\n " , e .CommitFlag )
453
453
u , _ := uuid .FromBytes (e .SID )
454
454
fmt .Fprintf (w , "GTID_NEXT: %s:%d\n " , u .String (), e .GNO )
455
- fmt .Fprintf (w , "LAST_COMMITTED: %d\n " , e .LastCommitted )
456
- fmt .Fprintf (w , "SEQUENCE_NUMBER: %d\n " , e .SequenceNumber )
455
+ fmt .Fprintf (w , "LAST_COMMITTED: %d\n " , e .lastCommitted )
456
+ fmt .Fprintf (w , "SEQUENCE_NUMBER: %d\n " , e .sequenceNumber )
457
457
fmt .Fprintf (w , "Immediate commmit timestamp: %d (%s)\n " , e .ImmediateCommitTimestamp , fmtTime (e .ImmediateCommitTime ()))
458
458
fmt .Fprintf (w , "Orignal commmit timestamp: %d (%s)\n " , e .OriginalCommitTimestamp , fmtTime (e .OriginalCommitTime ()))
459
459
fmt .Fprintf (w , "Transaction length: %d\n " , e .TransactionLength )
@@ -462,23 +462,31 @@ func (e *MySQLGTIDEvent) Dump(w io.Writer) {
462
462
fmt .Fprintln (w )
463
463
}
464
464
465
- func (e * MySQLGTIDEvent ) GTIDNext () (GTIDSet , error ) {
465
+ func (e * GTIDEvent ) GTIDNext () (GTIDSet , error ) {
466
466
u , err := uuid .FromBytes (e .SID )
467
467
if err != nil {
468
468
return nil , err
469
469
}
470
470
return ParseMysqlGTIDSet (strings .Join ([]string {u .String (), strconv .FormatInt (e .GNO , 10 )}, ":" ))
471
471
}
472
472
473
+ func (e * GTIDEvent ) SequenceNumber () int64 {
474
+ return e .sequenceNumber
475
+ }
476
+
477
+ func (e * GTIDEvent ) LastCommitted () int64 {
478
+ return e .lastCommitted
479
+ }
480
+
473
481
// ImmediateCommitTime returns the commit time of this trx on the immediate server
474
482
// or zero time if not available.
475
- func (e * MySQLGTIDEvent ) ImmediateCommitTime () time.Time {
483
+ func (e * GTIDEvent ) ImmediateCommitTime () time.Time {
476
484
return microSecTimestampToTime (e .ImmediateCommitTimestamp )
477
485
}
478
486
479
487
// OriginalCommitTime returns the commit time of this trx on the original server
480
488
// or zero time if not available.
481
- func (e * MySQLGTIDEvent ) OriginalCommitTime () time.Time {
489
+ func (e * GTIDEvent ) OriginalCommitTime () time.Time {
482
490
return microSecTimestampToTime (e .OriginalCommitTimestamp )
483
491
}
484
492
@@ -637,6 +645,14 @@ func (e *MariadbGTIDEvent) GTIDNext() (GTIDSet, error) {
637
645
return ParseMariadbGTIDSet (e .GTID .String ())
638
646
}
639
647
648
+ func (e * MariadbGTIDEvent ) SequenceNumber () int64 {
649
+ return int64 (e .GTID .SequenceNumber )
650
+ }
651
+
652
+ func (e * MariadbGTIDEvent ) LastCommitted () int64 {
653
+ return int64 (e .GTID .SequenceNumber - 1 )
654
+ }
655
+
640
656
type MariadbGTIDListEvent struct {
641
657
GTIDs []MariadbGTID
642
658
}
0 commit comments