-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathmysql.go
More file actions
170 lines (137 loc) · 5.09 KB
/
Copy pathmysql.go
File metadata and controls
170 lines (137 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package exceptions
import (
"context"
"crypto/tls"
"errors"
"fmt"
"regexp"
"strings"
"time"
"github.com/go-mysql-org/go-mysql/mysql"
)
// InvalidSequenceRe go-mysql-org returns "invalid sequence X != Y" (or "invalid compressed sequence X != Y"
// for the compressed protocol) when the packet sequence byte is out of sync — always transient, safe to retry.
var InvalidSequenceRe = regexp.MustCompile(`invalid (compressed )?sequence \d+ != \d+`)
type MySQLIncompatibleColumnTypeError struct {
TableName string
ColumnName string
dataType string
qkind string
columnType byte
}
func NewMySQLIncompatibleColumnTypeError(
tableName string, columnName string, columnType byte, dataType string, qkind string,
) *MySQLIncompatibleColumnTypeError {
return &MySQLIncompatibleColumnTypeError{
TableName: tableName,
ColumnName: columnName,
dataType: dataType,
qkind: qkind,
columnType: columnType,
}
}
func (e *MySQLIncompatibleColumnTypeError) Error() string {
return fmt.Sprintf("Incompatible type for column %s in table %s, expect qkind %s but data is %s (mysql type %d)",
e.ColumnName, e.TableName, e.qkind, e.dataType, e.columnType)
}
type MySQLUnsupportedBinlogRowMetadataError struct {
SchemaName string
TableName string
}
func NewMySQLUnsupportedBinlogRowMetadataError(schema string, table string) *MySQLUnsupportedBinlogRowMetadataError {
return &MySQLUnsupportedBinlogRowMetadataError{SchemaName: schema, TableName: table}
}
func (e *MySQLUnsupportedBinlogRowMetadataError) Error() string {
return fmt.Sprintf("Detected binlog_row_metadata change from FULL to MINIMAL while processing %s.%s",
e.SchemaName, e.TableName)
}
type MySQLUnsupportedBinlogRowValueOptionsError struct {
Schema string
Table string
}
func NewMySQLUnsupportedBinlogRowValueOptionsError(schema string, table string) *MySQLUnsupportedBinlogRowValueOptionsError {
return &MySQLUnsupportedBinlogRowValueOptionsError{Schema: schema, Table: table}
}
func (e *MySQLUnsupportedBinlogRowValueOptionsError) Error() string {
return fmt.Sprintf(
"Received a partial JSON update event while processing %s.%s; binlog_row_value_options must be disabled (set to '')",
e.Schema, e.Table)
}
type MySQLUnsupportedDDLError struct {
TableName string
}
func NewMySQLUnsupportedDDLError(tableName string) *MySQLUnsupportedDDLError {
return &MySQLUnsupportedDDLError{TableName: tableName}
}
func (e *MySQLUnsupportedDDLError) Error() string {
return fmt.Sprintf(
"Detected position-shifting DDL on table %s but binlog_row_metadata is not supported by this MySQL version.", e.TableName)
}
// MySQLGeometryParseError wraps go-geos WKB parse failures so they can be
// classified as MySQL-source errors without string-matching at the alerting layer.
// The underlying message comes from go-geos C code and is not unique to MySQL on its own.
type MySQLGeometryParseError struct {
error
}
func NewMySQLGeometryParseError(err error) *MySQLGeometryParseError {
return &MySQLGeometryParseError{err}
}
func (e *MySQLGeometryParseError) Error() string {
return "failed to parse MySQL geometry WKB: " + e.error.Error()
}
func (e *MySQLGeometryParseError) Unwrap() error {
return e.error
}
type MySQLExecuteError struct {
error
Retryable bool
}
func NewMySQLExecuteError(err error) *MySQLExecuteError {
if errors.Is(err, context.DeadlineExceeded) {
return &MySQLExecuteError{err, true}
}
if recordHeaderError, ok := errors.AsType[tls.RecordHeaderError](err); ok {
if recordHeaderError.Msg == "first record does not look like a TLS handshake" {
return &MySQLExecuteError{err, true}
}
}
if strings.Contains(err.Error(), mysql.ErrBadConn.Error()) {
return &MySQLExecuteError{err, true}
}
if InvalidSequenceRe.MatchString(err.Error()) {
return &MySQLExecuteError{err, true}
}
return &MySQLExecuteError{err, false}
}
func (e *MySQLExecuteError) Error() string {
return "MySQL execute error: " + e.error.Error()
}
func (e *MySQLExecuteError) Unwrap() error {
return e.error
}
// MySQLStaleConnectionError indicates that no events (rows or heartbeats) have arrived
// from the MySQL master in longer than the configured staleness window.
type MySQLStaleConnectionError struct {
Since time.Duration
HeartbeatPeriod time.Duration
}
func NewMySQLStaleConnectionError(since, heartbeatPeriod time.Duration) *MySQLStaleConnectionError {
return &MySQLStaleConnectionError{Since: since, HeartbeatPeriod: heartbeatPeriod}
}
func (e *MySQLStaleConnectionError) Error() string {
return fmt.Sprintf("MySQL connection is stale: no events received in %v (heartbeat=%v)",
e.Since, e.HeartbeatPeriod)
}
type MySQLBinlogIncidentError struct {
Message string
Incident uint16
}
func NewMySQLBinlogIncidentError(incident uint16, message string) *MySQLBinlogIncidentError {
return &MySQLBinlogIncidentError{Incident: incident, Message: message}
}
func (e *MySQLBinlogIncidentError) Error() string {
if e.Message != "" {
return fmt.Sprintf("MySQL binlog incident event received (incident=%d): %s; a resync is required", e.Incident, e.Message)
}
return fmt.Sprintf("MySQL binlog incident event received (incident=%d); a resync is required", e.Incident)
}