Skip to content

Commit

Permalink
add GetEventWithStartTime (go-mysql-org#327)
Browse files Browse the repository at this point in the history
* add GetEventWithStartTime
  • Loading branch information
cenkore authored and siddontang committed Oct 16, 2018
1 parent 17cd885 commit c8bed9e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion replication/binlogstreamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package replication

import (
"context"

"time"
"github.com/juju/errors"
"github.com/siddontang/go-log/log"
)
Expand Down Expand Up @@ -36,6 +36,26 @@ func (s *BinlogStreamer) GetEvent(ctx context.Context) (*BinlogEvent, error) {
}
}

// Get the binlog event with starttime, if current binlog event timestamp smaller than specify starttime
// return nil event
func (s *BinlogStreamer) GetEventWithStartTime(ctx context.Context,startTime time.Time) (*BinlogEvent, error) {
if s.err != nil {
return nil, ErrNeedSyncAgain
}
startUnix := startTime.Unix()
select {
case c := <-s.ch:
if int64(c.Header.Timestamp) >= startUnix {
return c, nil
}
return nil,nil
case s.err = <-s.ech:
return nil, s.err
case <-ctx.Done():
return nil, ctx.Err()
}
}

// DumpEvents dumps all left events
func (s *BinlogStreamer) DumpEvents() []*BinlogEvent {
count := len(s.ch)
Expand Down

0 comments on commit c8bed9e

Please sign in to comment.