Skip to content

Commit 3e9f1d7

Browse files
committed
Move some code
1 parent 782e710 commit 3e9f1d7

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

replication/event.go

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,20 @@ func (e *GTIDEvent) Decode(data []byte) error {
383383
}
384384

385385
func (e *GTIDEvent) Dump(w io.Writer) {
386+
fmtTime := func(t time.Time) string {
387+
if t.IsZero() {
388+
return "N/A"
389+
}
390+
return t.Format(time.RFC3339Nano)
391+
}
392+
386393
fmt.Fprintf(w, "Commit flag: %d\n", e.CommitFlag)
387394
u, _ := uuid.FromBytes(e.SID)
388395
fmt.Fprintf(w, "GTID_NEXT: %s:%d\n", u.String(), e.GNO)
389396
fmt.Fprintf(w, "LAST_COMMITTED: %d\n", e.LastCommitted)
390397
fmt.Fprintf(w, "SEQUENCE_NUMBER: %d\n", e.SequenceNumber)
391-
fmt.Fprintf(w, "Immediate commmit timestamp: %d (%s)\n", e.ImmediateCommitTimestamp, e.fmtTime(e.ImmediateCommitTime()))
392-
fmt.Fprintf(w, "Orignal commmit timestamp: %d (%s)\n", e.OriginalCommitTimestamp, e.fmtTime(e.OriginalCommitTime()))
398+
fmt.Fprintf(w, "Immediate commmit timestamp: %d (%s)\n", e.ImmediateCommitTimestamp, fmtTime(e.ImmediateCommitTime()))
399+
fmt.Fprintf(w, "Orignal commmit timestamp: %d (%s)\n", e.OriginalCommitTimestamp, fmtTime(e.OriginalCommitTime()))
393400
fmt.Fprintf(w, "Transaction length: %d\n", e.TransactionLength)
394401
fmt.Fprintf(w, "Immediate server version: %d\n", e.ImmediateServerVersion)
395402
fmt.Fprintf(w, "Orignal server version: %d\n", e.OriginalServerVersion)
@@ -399,27 +406,13 @@ func (e *GTIDEvent) Dump(w io.Writer) {
399406
// ImmediateCommitTime returns the commit time of this trx on the immediate server
400407
// or zero time if not available.
401408
func (e *GTIDEvent) ImmediateCommitTime() time.Time {
402-
return e.microsecTimestamp2Time(e.ImmediateCommitTimestamp)
409+
return microSecTimestampToTime(e.ImmediateCommitTimestamp)
403410
}
404411

405412
// OriginalCommitTime returns the commit time of this trx on the original server
406413
// or zero time if not available.
407414
func (e *GTIDEvent) OriginalCommitTime() time.Time {
408-
return e.microsecTimestamp2Time(e.OriginalCommitTimestamp)
409-
}
410-
411-
func (e *GTIDEvent) microsecTimestamp2Time(ts uint64) time.Time {
412-
if ts == 0 {
413-
return time.Time{}
414-
}
415-
return time.Unix(int64(ts/1000000), int64(ts%1000000)*1000)
416-
}
417-
418-
func (e *GTIDEvent) fmtTime(t time.Time) string {
419-
if t.IsZero() {
420-
return "N/A"
421-
}
422-
return t.Format(time.RFC3339Nano)
415+
return microSecTimestampToTime(e.OriginalCommitTimestamp)
423416
}
424417

425418
type BeginLoadQueryEvent struct {

replication/time.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ func formatBeforeUnixZeroTime(year, month, day, hour, minute, second, frac, dec
5050
return s[0 : len(s)-(6-dec)]
5151
}
5252

53+
func microSecTimestampToTime(ts uint64) time.Time {
54+
if ts == 0 {
55+
return time.Time{}
56+
}
57+
return time.Unix(int64(ts/1000000), int64(ts%1000000)*1000)
58+
}
59+
5360
func init() {
5461
fracTimeFormat = make([]string, 7)
5562
fracTimeFormat[0] = "2006-01-02 15:04:05"

0 commit comments

Comments
 (0)