github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/pkg/binlog/reader/reader.go (about) 1 // Copyright 2019 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package reader 15 16 import ( 17 "context" 18 19 gmysql "github.com/go-mysql-org/go-mysql/mysql" 20 "github.com/go-mysql-org/go-mysql/replication" 21 ) 22 23 // Reader is a binlog event reader, it may read binlog events from a TCP stream, binlog files or any other in-memory buffer. 24 // One reader should read binlog events either through position mode or GTID mode. 25 type Reader interface { 26 Streamer 27 28 // StartSyncByPos prepares the reader for reading binlog from the specified position. 29 StartSyncByPos(pos gmysql.Position) error 30 31 // StartSyncByGTID prepares the reader for reading binlog from the specified GTID set. 32 StartSyncByGTID(gSet gmysql.GTIDSet) error 33 34 // Close closes the reader and release the resource. 35 // Close will be blocked if `GetEvent` has not returned. 36 Close() error 37 38 // Status returns the status of the reader. 39 Status() interface{} 40 } 41 42 // Streamer provides the ability to get binlog event from remote server or local file. 43 type Streamer interface { 44 // GetEvent returns binlog event 45 GetEvent(ctx context.Context) (*replication.BinlogEvent, error) 46 }