{"modulePath":"github.com/windhooked/pkg","version":"v0.0.0-20210530195812-02de94908f4f","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package myreplicator\n\nPackage myreplicator handles the MySQL binary replication protocol.\n\n## Constants\n\n```go\nconst (\n\tLOG_EVENT_BINLOG_IN_USE_F            uint16 = 0x0001\n\tLOG_EVENT_FORCED_ROTATE_F            uint16 = 0x0002\n\tLOG_EVENT_THREAD_SPECIFIC_F          uint16 = 0x0004\n\tLOG_EVENT_SUPPRESS_USE_F             uint16 = 0x0008\n\tLOG_EVENT_UPDATE_TABLE_MAP_VERSION_F uint16 = 0x0010\n\tLOG_EVENT_ARTIFICIAL_F               uint16 = 0x0020\n\tLOG_EVENT_RELAY_LOG_F                uint16 = 0x0040\n\tLOG_EVENT_IGNORABLE_F                uint16 = 0x0080\n\tLOG_EVENT_NO_FILTER_F                uint16 = 0x0100\n\tLOG_EVENT_MTS_ISOLATE_F              uint16 = 0x0200\n)\n```\n\n```go\nconst (\n\tBINLOG_DUMP_NEVER_STOP  uint16 = 0x00\n\tBINLOG_DUMP_NON_BLOCK   uint16 = 0x01\n\tBINLOG_THROUGH_POSITION uint16 = 0x02\n\tBINLOG_THROUGH_GTID     uint16 = 0x04\n)\n```\n\n```go\nconst (\n\tBINLOG_ROW_IMAGE_FULL    = \"FULL\"\n\tBINLOG_ROW_IAMGE_MINIMAL = \"MINIMAL\"\n\tBINLOG_ROW_IMAGE_NOBLOB  = \"NOBLOB\"\n)\n```\n\n```go\nconst (\n\tBINLOG_CHECKSUM_ALG_OFF byte = 0 // Events are without checksum though its generator\n\t// is checksum-capable New Master (NM).\n\tBINLOG_CHECKSUM_ALG_CRC32 byte = 1 // CRC32 of zlib algorithm.\n\t//  BINLOG_CHECKSUM_ALG_ENUM_END,  // the cut line: valid alg range is [1, 0x7f].\n\tBINLOG_CHECKSUM_ALG_UNDEF byte = 255 // special value to tag undetermined yet checksum\n\n)\n```\n\n```go\nconst (\n\tEventHeaderSize            = 19\n\tSidLength                  = 16\n\tLogicalTimestampTypeCode   = 2\n\tPartLogicalTimestampLength = 8\n\tBinlogChecksumLength       = 4\n)\n```\n\n```go\nconst (\n\tJSONB_SMALL_OBJECT byte = iota // small JSON object\n\tJSONB_LARGE_OBJECT             // large JSON object\n\tJSONB_SMALL_ARRAY              // small JSON array\n\tJSONB_LARGE_ARRAY              // large JSON array\n\tJSONB_LITERAL                  // literal (true/false/null)\n\tJSONB_INT16                    // int16\n\tJSONB_UINT16                   // uint16\n\tJSONB_INT32                    // int32\n\tJSONB_UINT32                   // uint32\n\tJSONB_INT64                    // int64\n\tJSONB_UINT64                   // uint64\n\tJSONB_DOUBLE                   // double\n\tJSONB_STRING                   // string\n\tJSONB_OPAQUE       byte = 0x0f // custom data (any MySQL data type)\n)\n```\n\n```go\nconst (\n\tJSONB_NULL_LITERAL  byte = 0x00\n\tJSONB_TRUE_LITERAL  byte = 0x01\n\tJSONB_FALSE_LITERAL byte = 0x02\n)\n```\n\n```go\nconst DATETIMEF_INT_OFS int64 = 0x8000000000\n```\n\n```go\nconst (\n\t//we only support MySQL 5.0.0+ binlog format, maybe???\n\tMinBinlogVersion = 4\n)\n```\n\n```go\nconst RowsEventStmtEndFlag = 0x01\n```\nRowsEventStmtEndFlag is set in the end of the statement.\n\n```go\nconst TIMEF_INT_OFS int64 = 0x800000\n```\n\n```go\nconst TIMEF_OFS int64 = 0x800000000000\n```\n\n## Variables\n\n```go\nvar (\n\t//binlog header [ fe `bin` ]\n\tBinLogFileHeader []byte = []byte{0xfe, 0x62, 0x69, 0x6e}\n\n\tSemiSyncIndicator byte = 0xef\n)\n```\n\n## Types\n\n```go\ntype BeginLoadQueryEvent struct {\n\tFileID    uint32\n\tBlockData []byte\n}\n```\n\n```go\nfunc (e *BeginLoadQueryEvent) Dump(w io.Writer)\n```\n\n```go\ntype BinlogEvent struct {\n\t// RawData contains raw binlog data which contains all data, including\n\t// binlog header and event body, and including crc32 checksum if exists\n\tRawData []byte\n\n\tHeader *EventHeader\n\tEvent  EventDecoder\n}\n```\n\n```go\nfunc (e *BinlogEvent) Dump(w io.Writer)\n```\n\n```go\ntype BinlogParser struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewBinlogParser() *BinlogParser\n```\n\n```go\nfunc (p *BinlogParser) Parse(data []byte) (*BinlogEvent, error)\n```\nGiven the bytes for a a binary log event: return the decoded event. With the exception of the FORMAT\\_DESCRIPTION\\_EVENT event type there must have previously been passed a FORMAT\\_DESCRIPTION\\_EVENT into the parser for this to work properly on any given event. Passing a new FORMAT\\_DESCRIPTION\\_EVENT into the parser will replace an existing one.\n\n```go\nfunc (p *BinlogParser) ParseFile(name string, offset int64, onEvent OnEventFunc) error\n```\n\n```go\nfunc (p *BinlogParser) ParseReader(r io.Reader, onEvent OnEventFunc) error\n```\n\n```go\nfunc (p *BinlogParser) ParseSingleEvent(r io.Reader, onEvent OnEventFunc) (bool, error)\n```\nParseSingleEvent parses single binlog event and passes the event to onEvent function.\n\n```go\nfunc (p *BinlogParser) Reset()\n```\n\n```go\nfunc (p *BinlogParser) Resume()\n```\n\n```go\nfunc (p *BinlogParser) SetParseTime(parseTime bool)\n```\n\n```go\nfunc (p *BinlogParser) SetRawMode(mode bool)\n```\n\n```go\nfunc (p *BinlogParser) SetTimestampStringLocation(timestampStringLocation *time.Location)\n```\n\n```go\nfunc (p *BinlogParser) SetVerifyChecksum(verify bool)\n```\n\n```go\nfunc (p *BinlogParser) Stop()\n```\n\n```go\ntype BinlogStream struct {\n\tLog log.Logger\n\t// contains filtered or unexported fields\n}\n```\nBinlogStream gets the streaming event.\n\n```go\nfunc (s *BinlogStream) DumpEvents() []*BinlogEvent\n```\nDumpEvents dumps all left events\n\n```go\nfunc (s *BinlogStream) GetEvent(ctx context.Context) (*BinlogEvent, error)\n```\nGetEvent gets the binlog event one by one, it will block until Syncer receives any events from MySQL or meets a sync error. You can pass a context (like Cancel or Timeout) to break the block. May return a temporary error behaviour.\n\n```go\nfunc (s *BinlogStream) GetEventWithStartTime(ctx context.Context, startTime time.Time) (*BinlogEvent, error)\n```\nGetEventWithStartTime gets the binlog event with a start time, if current binlog event timestamp smaller than specify start time returns a nil event.\n\n```go\ntype BinlogSyncer struct {\n\t// contains filtered or unexported fields\n}\n```\nBinlogSyncer syncs binlog event from server.\n\n```go\nfunc NewBinlogSyncer(cfg *BinlogSyncerConfig) *BinlogSyncer\n```\nNewBinlogSyncer creates the BinlogSyncer with cfg.\n\n```go\nfunc (b *BinlogSyncer) Close() error\n```\nClose closes the BinlogSyncer.\n\n```go\nfunc (b *BinlogSyncer) LastConnectionID() uint32\n```\nLastConnectionID returns last connectionID.\n\n```go\nfunc (b *BinlogSyncer) StartBackup(backupDir string, perm os.FileMode, p ddl.MasterStatus, timeout time.Duration) error\n```\nStartBackup enables, like the mysqlbinlog command line tool, a remote raw backup. Backup remote binlog from position (filename, offset) and write in backupDir.\n\n```go\nfunc (b *BinlogSyncer) StartSync(pos ddl.MasterStatus) (*BinlogStream, error)\n```\nStartSync starts syncing from the \\`pos\\` position.\n\n```go\nfunc (b *BinlogSyncer) StartSyncGTID(gset mysql.GTIDSet) (*BinlogStream, error)\n```\nStartSyncGTID starts syncing from the \\`gset\\` mysql.GTIDSet.\n\n```go\ntype BinlogSyncerConfig struct {\n\t// ServerID is the unique ID in cluster.\n\tServerID uint32\n\t// Flavor is \"mysql\" or \"mariadb\", if not set, use \"mysql\" default.\n\tFlavor string\n\n\t// Host is for MySQL server host.\n\tHost string\n\t// Port is for MySQL server port.\n\tPort uint16\n\t// User is for MySQL user.\n\tUser string\n\t// Password is for MySQL password.\n\tPassword string\n\n\t// Localhost is local hostname if register salve.\n\t// If not set, use os.Hostname() instead.\n\tLocalhost string\n\n\t// Charset is for MySQL client character set\n\tCharset string\n\n\t// SemiSyncEnabled enables semi-sync or not.\n\tSemiSyncEnabled bool\n\n\t// RawModeEnabled is for not parsing binlog event.\n\tRawModeEnabled bool\n\n\tLog log.Logger\n\t// TLSConfig if not nil, use the provided tls.Config to connect to the\n\t// database using TLS/SSL.\n\tTLSConfig *tls.Config\n\n\t// Use replication.Time structure for timestamp and datetime.\n\t// We will use Local location for timestamp and UTC location for datatime.\n\tParseTime bool\n\n\t// If ParseTime is false, convert TIMESTAMP into this specified timezone. If\n\t// ParseTime is true, this option will have no effect and TIMESTAMP data will\n\t// be parsed into the local timezone and a full time.Time struct will be\n\t// returned.\n\t//\n\t// Note that MySQL TIMESTAMP columns are offset from the machine local\n\t// timezone while DATETIME columns are offset from UTC. This is consistent\n\t// with documented MySQL behaviour as it return TIMESTAMP in local timezone\n\t// and DATETIME in UTC.\n\t//\n\t// Setting this to UTC effectively equalizes the TIMESTAMP and DATETIME time\n\t// strings obtained from MySQL.\n\tTimestampStringLocation *time.Location\n\n\t// RecvBufferSize sets the size in bytes of the operating system's receive buffer associated with the connection.\n\tRecvBufferSize int\n\n\t// master heartbeat period\n\tHeartbeatPeriod time.Duration\n\n\t// read timeout\n\tReadTimeout time.Duration\n\n\t// maximum number of attempts to re-establish a broken connection\n\tMaxReconnectAttempts int\n\n\t// Only works when MySQL/MariaDB variable binlog_checksum=CRC32.\n\t// For MySQL, binlog_checksum was introduced since 5.6.2, but CRC32 was set as default value since 5.6.6 .\n\t// https://dev.mysql.com/doc/refman/5.6/en/replication-options-binary-log.html#option_mysqld_binlog-checksum\n\t// For MariaDB, binlog_checksum was introduced since MariaDB 5.3, but CRC32 was set as default value since MariaDB 10.2.1 .\n\t// https://mariadb.com/kb/en/library/replication-and-binary-log-server-system-variables/#binlog_checksum\n\tVerifyChecksum bool\n}\n```\nBinlogSyncerConfig is the configuration for BinlogSyncer.\n\n```go\ntype EventDecoder interface {\n\t//Dump Event, format like python-mysql-replication\n\tDump(w io.Writer)\n\t// contains filtered or unexported methods\n}\n```\n\n```go\ntype EventError struct {\n\tHeader *EventHeader\n\n\t//Error message\n\tErr string\n\n\t//Event data\n\tData []byte\n}\n```\n\n```go\nfunc (e *EventError) Error() string\n```\n\n```go\ntype EventHeader struct {\n\tTimestamp uint32\n\tEventType EventType\n\tServerID  uint32\n\tEventSize uint32\n\tLogPos    uint32\n\tFlags     uint16\n}\n```\n\n```go\nfunc (h *EventHeader) Dump(w io.Writer)\n```\n\n```go\ntype EventType byte\n```\n\n```go\nconst (\n\tUNKNOWN_EVENT EventType = iota\n\tSTART_EVENT_V3\n\tQUERY_EVENT\n\tSTOP_EVENT\n\tROTATE_EVENT\n\tINTVAR_EVENT\n\tLOAD_EVENT\n\tSLAVE_EVENT\n\tCREATE_FILE_EVENT\n\tAPPEND_BLOCK_EVENT\n\tEXEC_LOAD_EVENT\n\tDELETE_FILE_EVENT\n\tNEW_LOAD_EVENT\n\tRAND_EVENT\n\tUSER_VAR_EVENT\n\tFORMAT_DESCRIPTION_EVENT\n\tXID_EVENT\n\tBEGIN_LOAD_QUERY_EVENT\n\tEXECUTE_LOAD_QUERY_EVENT\n\tTABLE_MAP_EVENT\n\tWRITE_ROWS_EVENTv0\n\tUPDATE_ROWS_EVENTv0\n\tDELETE_ROWS_EVENTv0\n\tWRITE_ROWS_EVENTv1\n\tUPDATE_ROWS_EVENTv1\n\tDELETE_ROWS_EVENTv1\n\tINCIDENT_EVENT\n\tHEARTBEAT_EVENT\n\tIGNORABLE_EVENT\n\tROWS_QUERY_EVENT\n\tWRITE_ROWS_EVENTv2\n\tUPDATE_ROWS_EVENTv2\n\tDELETE_ROWS_EVENTv2\n\tGTID_EVENT\n\tANONYMOUS_GTID_EVENT\n\tPREVIOUS_GTIDS_EVENT\n)\n```\n\n```go\nconst (\n\t// MariaDB event starts from 160\n\tMARIADB_ANNOTATE_ROWS_EVENT EventType = 160 + iota\n\tMARIADB_BINLOG_CHECKPOINT_EVENT\n\tMARIADB_GTID_EVENT\n\tMARIADB_GTID_LIST_EVENT\n)\n```\n\n```go\nfunc (e EventType) String() string\n```\n\n```go\ntype ExecuteLoadQueryEvent struct {\n\tSlaveProxyID     uint32\n\tExecutionTime    uint32\n\tSchemaLength     uint8\n\tErrorCode        uint16\n\tStatusVars       uint16\n\tFileID           uint32\n\tStartPos         uint32\n\tEndPos           uint32\n\tDupHandlingFlags uint8\n}\n```\n\n```go\nfunc (e *ExecuteLoadQueryEvent) Dump(w io.Writer)\n```\n\n```go\ntype FormatDescriptionEvent struct {\n\tVersion uint16\n\t//len = 50\n\tServerVersion          []byte\n\tCreateTimestamp        uint32\n\tEventHeaderLength      uint8\n\tEventTypeHeaderLengths []byte\n\n\t// 0 is off, 1 is for CRC32, 255 is undefined\n\tChecksumAlgorithm byte\n}\n```\n\n```go\nfunc (e *FormatDescriptionEvent) Dump(w io.Writer)\n```\n\n```go\ntype GTIDEvent struct {\n\tCommitFlag     uint8\n\tSID            []byte\n\tGNO            int64\n\tLastCommitted  int64\n\tSequenceNumber int64\n}\n```\n\n```go\nfunc (e *GTIDEvent) Dump(w io.Writer)\n```\n\n```go\ntype GenericEvent struct {\n\tData []byte\n}\n```\nwe don't parse all event, so some we will use GenericEvent instead\n\n```go\nfunc (e *GenericEvent) Dump(w io.Writer)\n```\n\n```go\ntype MariadbAnnotateRowsEvent struct {\n\tQuery []byte\n}\n```\n\n```go\nfunc (e *MariadbAnnotateRowsEvent) Dump(w io.Writer)\n```\n\n```go\ntype MariadbBinlogCheckPointEvent struct {\n\tInfo []byte\n}\n```\n\n```go\nfunc (e *MariadbBinlogCheckPointEvent) Dump(w io.Writer)\n```\n\n```go\ntype MariadbGTIDEvent struct {\n\tGTID mysql.MariadbGTID\n}\n```\n\n```go\nfunc (e *MariadbGTIDEvent) Dump(w io.Writer)\n```\n\n```go\ntype MariadbGTIDListEvent struct {\n\tGTIDs []mysql.MariadbGTID\n}\n```\n\n```go\nfunc (e *MariadbGTIDListEvent) Dump(w io.Writer)\n```\n\n```go\ntype OnEventFunc func(*BinlogEvent) error\n```\n\n```go\ntype QueryEvent struct {\n\tSlaveProxyID  uint32\n\tExecutionTime uint32\n\tErrorCode     uint16\n\tStatusVars    []byte\n\tSchema        []byte\n\tQuery         []byte\n\n\t// in fact QueryEvent dosen't have the GTIDSet information, just for beneficial to use\n\tGSet mysql.GTIDSet\n}\n```\n\n```go\nfunc (e *QueryEvent) Dump(w io.Writer)\n```\n\n```go\ntype RotateEvent struct {\n\tPosition    uint64\n\tNextLogName []byte\n}\n```\n\n```go\nfunc (e *RotateEvent) Dump(w io.Writer)\n```\n\n```go\ntype RowsEvent struct {\n\tLog log.Logger\n\t//0, 1, 2\n\tVersion int\n\n\tTable *TableMapEvent\n\n\tTableID uint64\n\n\tFlags uint16\n\n\t//if version == 2\n\tExtraData []byte\n\n\t//lenenc_int\n\tColumnCount uint64\n\t//len = (ColumnCount + 7) / 8\n\tColumnBitmap1 []byte\n\n\t//if UPDATE_ROWS_EVENTv1 or v2\n\t//len = (ColumnCount + 7) / 8\n\tColumnBitmap2 []byte\n\n\t// Rows: invalid: int64, float64, bool, []byte, string\n\tRows [][]interface{}\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (e *RowsEvent) Dump(w io.Writer)\n```\n\n```go\ntype RowsQueryEvent struct {\n\tQuery []byte\n}\n```\n\n```go\nfunc (e *RowsQueryEvent) Dump(w io.Writer)\n```\n\n```go\ntype TableMapEvent struct {\n\tTableID uint64\n\n\tFlags uint16\n\n\tSchema []byte\n\tTable  []byte\n\n\tColumnCount uint64\n\tColumnType  []byte\n\tColumnMeta  []uint16\n\n\t//len = (ColumnCount + 7) / 8\n\tNullBitmap []byte\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (e *TableMapEvent) Dump(w io.Writer)\n```\n\n```go\ntype XIDEvent struct {\n\tXID uint64\n\n\t// in fact XIDEvent dosen't have the GTIDSet information, just for beneficial to use\n\tGSet mysql.GTIDSet\n}\n```\n\n```go\nfunc (e *XIDEvent) Dump(w io.Writer)\n```\n\n","path":"github.com/windhooked/pkg/sql/myreplicator","name":"myreplicator","synopsis":"Package myreplicator handles the MySQL binary replication protocol.","isRedistributable":true}
