( execCtx *common.ExecContext, cfg *common.MySQLDriverConfig, logger g.LoggerType, replicateDoDb map[string]*common.SchemaContext, sqleContext *sqle.Context, memory *int64, db *gosql.DB, targetGtid string, lctn mysqlconfig.LowerCaseTableNamesValue, ctx context.Context)
| 178 | } |
| 179 | |
| 180 | func NewBinlogReader( |
| 181 | execCtx *common.ExecContext, cfg *common.MySQLDriverConfig, logger g.LoggerType, |
| 182 | replicateDoDb map[string]*common.SchemaContext, sqleContext *sqle.Context, |
| 183 | memory *int64, db *gosql.DB, targetGtid string, lctn mysqlconfig.LowerCaseTableNamesValue, |
| 184 | ctx context.Context) (binlogReader *BinlogReader, err error) { |
| 185 | |
| 186 | sqlFilter, err := parseSqlFilter(cfg.SqlFilter) |
| 187 | if err != nil { |
| 188 | return nil, err |
| 189 | } |
| 190 | |
| 191 | binlogReader = &BinlogReader{ |
| 192 | ctx: ctx, |
| 193 | execCtx: execCtx, |
| 194 | logger: logger, |
| 195 | currentCoord: common.MySQLCoordinates{}, |
| 196 | currentCoordMutex: &sync.Mutex{}, |
| 197 | mysqlContext: cfg, |
| 198 | ReMap: make(map[string]*regexp.Regexp), |
| 199 | shutdownCh: make(chan struct{}), |
| 200 | tables: make(map[string]*common.SchemaContext), |
| 201 | sqlFilter: sqlFilter, |
| 202 | maybeSqleContext: sqleContext, |
| 203 | memory: memory, |
| 204 | db: db, |
| 205 | lowerCaseTableNames: lctn, |
| 206 | } |
| 207 | |
| 208 | binlogReader.serverUUID, err = sql.GetServerUUID(db) |
| 209 | if err != nil { |
| 210 | return nil, err |
| 211 | } |
| 212 | |
| 213 | gset, _ := gomysql.ParseMysqlGTIDSet("") |
| 214 | binlogReader.CurrentGtidSet = gset.(*gomysql.MysqlGTIDSet) |
| 215 | if targetGtid != "" { |
| 216 | binlogReader.targetGtid, err = gomysql.ParseMysqlGTIDSet(targetGtid) |
| 217 | if err != nil { |
| 218 | return nil, errors.Wrap(err, "ParseMysqlGTIDSet") |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | binlogReader.tables = replicateDoDb |
| 223 | |
| 224 | id, err := util.NewIdWorker(2, 3, util.SnsEpoch) |
| 225 | if err != nil { |
| 226 | return nil, err |
| 227 | } |
| 228 | sid, err := id.NextId() |
| 229 | if err != nil { |
| 230 | return nil, err |
| 231 | } |
| 232 | bid := []byte(strconv.FormatUint(uint64(sid), 10)) |
| 233 | binlogReader.serverId, err = strconv.ParseUint(string(bid), 10, 32) |
| 234 | if err != nil { |
| 235 | return nil, err |
| 236 | } |
| 237 | logger.Debug("got replication serverId", "id", binlogReader.serverId) |
no test coverage detected