func positionCmd(subFlags *flag.FlagSet, args []string) error { subFlags.Parse(args) if len(args) < 3 { return fmt.Errorf("Not enough arguments for position operation.") } pos1, err := replication.DecodePosition(args[1]) if err != nil { return err } switch args[0] { case "equal": pos2, err := replication.DecodePosition(args[2]) if err != nil { return err } fmt.Println(pos1.Equal(pos2)) case "at_least": pos2, err := replication.DecodePosition(args[2]) if err != nil { return err } fmt.Println(pos1.AtLeast(pos2)) case "append": gtid, err := replication.DecodeGTID(args[2]) if err != nil { return err } fmt.Println(replication.AppendGTID(pos1, gtid)) } return nil }
func (rci *RowcacheInvalidator) processEvent(event *binlogdatapb.StreamEvent) error { defer rci.handleInvalidationError(event) switch event.Category { case binlogdatapb.StreamEvent_SE_DDL: log.Infof("DDL invalidation: %s", event.Sql) rci.handleDDLEvent(event.Sql) case binlogdatapb.StreamEvent_SE_DML: rci.handleDMLEvent(event) case binlogdatapb.StreamEvent_SE_ERR: rci.handleUnrecognizedEvent(event.Sql) case binlogdatapb.StreamEvent_SE_POS: gtid, err := replication.DecodeGTID(event.TransactionId) if err != nil { return err } rci.AppendGTID(gtid) default: log.Errorf("unknown event: %#v", event) rci.qe.queryServiceStats.InternalErrors.Add("Invalidation", 1) return nil } rci.lagSeconds.Set(time.Now().Unix() - event.Timestamp) return nil }
// writeRecoveryPosition will write the current GTID as the recovery position // for the next transaction. // We will also try to get the timestamp for the transaction. Two cases: // - we have statements, and they start with a SET TIMESTAMP that we // can parse: then we update transaction_timestamp in blp_checkpoint // with it, and set SecondsBehindMaster to now() - transaction_timestamp // - otherwise (the statements are probably filtered out), we leave // transaction_timestamp alone (keeping the old value), and we don't // change SecondsBehindMaster func (blp *BinlogPlayer) writeRecoveryPosition(tx *pb.BinlogTransaction) error { gtid, err := replication.DecodeGTID(tx.TransactionId) if err != nil { return err } now := time.Now().Unix() blp.position = replication.AppendGTID(blp.position, gtid) updateRecovery := updateBlpCheckpoint(blp.uid, blp.position, now, tx.Timestamp) qr, err := blp.exec(updateRecovery) if err != nil { return fmt.Errorf("Error %v in writing recovery info %v", err, updateRecovery) } if qr.RowsAffected != 1 { return fmt.Errorf("Cannot update blp_recovery table, affected %v rows", qr.RowsAffected) } blp.blplStats.SetLastPosition(blp.position) if tx.Timestamp != 0 { blp.blplStats.SecondsBehindMaster.Set(now - tx.Timestamp) } return nil }