diff --git a/go/mysql/flavor.go b/go/mysql/flavor.go index 19e0d4366bc..d66bdc5198d 100644 --- a/go/mysql/flavor.go +++ b/go/mysql/flavor.go @@ -299,8 +299,12 @@ func parseReplicationStatus(fields map[string]string) ReplicationStatus { status.MasterPort = int(parseInt) parseInt, _ = strconv.ParseInt(fields["Connect_Retry"], 10, 0) status.MasterConnectRetry = int(parseInt) - parseUint, _ := strconv.ParseUint(fields["Seconds_Behind_Master"], 10, 0) + parseUint, _ := strconv.ParseUint(fields["Last_SQL_Errno"], 10, 0) + status.LastSQLErrno = uint(parseUint) + parseUint, _ = strconv.ParseUint(fields["Seconds_Behind_Master"], 10, 0) status.SecondsBehindMaster = uint(parseUint) + parseUint, _ = strconv.ParseUint(fields["Skip_Counter"], 10, 0) + status.SkipCounter = uint(parseUint) parseUint, _ = strconv.ParseUint(fields["Master_Server_Id"], 10, 0) status.MasterServerID = uint(parseUint) diff --git a/go/mysql/replication_status.go b/go/mysql/replication_status.go index 58f17835b5f..60669d72e7f 100644 --- a/go/mysql/replication_status.go +++ b/go/mysql/replication_status.go @@ -36,7 +36,9 @@ type ReplicationStatus struct { MasterServerID uint IOThreadRunning bool SQLThreadRunning bool + LastSQLErrno uint SecondsBehindMaster uint + SkipCounter uint MasterHost string MasterPort int MasterConnectRetry int @@ -49,6 +51,14 @@ func (s *ReplicationStatus) ReplicationRunning() bool { return s.IOThreadRunning && s.SQLThreadRunning } +// HasReplicationSQLThreadError returns true if the replication SQL thread stopped on an +// error (ie: Slave_SQL_Running: no + Last_SQL_Errno > 0) and sql_slave_skip_counter is +// disabled (0). This suggests the replication SQL thread stopped on an error that can't +// be recovered/skipped automatically. A node in this state may have inconsistent data. +func (s *ReplicationStatus) HasReplicationSQLThreadError() bool { + return !s.SQLThreadRunning && s.LastSQLErrno > 0 && s.SkipCounter == 0 +} + // ReplicationStatusToProto translates a Status to proto3. func ReplicationStatusToProto(s ReplicationStatus) *replicationdatapb.Status { return &replicationdatapb.Status{ @@ -59,6 +69,8 @@ func ReplicationStatusToProto(s ReplicationStatus) *replicationdatapb.Status { MasterServerId: uint32(s.MasterServerID), IoThreadRunning: s.IOThreadRunning, SqlThreadRunning: s.SQLThreadRunning, + LastSqlErrno: uint32(s.LastSQLErrno), + SkipCounter: uint32(s.SkipCounter), SecondsBehindMaster: uint32(s.SecondsBehindMaster), MasterHost: s.MasterHost, MasterPort: int32(s.MasterPort), diff --git a/go/mysql/replication_status_test.go b/go/mysql/replication_status_test.go index d25e6e809b6..7653f790198 100644 --- a/go/mysql/replication_status_test.go +++ b/go/mysql/replication_status_test.go @@ -42,6 +42,17 @@ func TestStatusIOThreadNotRunning(t *testing.T) { } } +func TestStatusHasReplicationSQLThreadError(t *testing.T) { + input := &ReplicationStatus{ + LastSQLErrno: 1032, + SQLThreadRunning: false, + } + want := true + if got := input.HasReplicationSQLThreadError(); got != want { + t.Errorf("%v#v.HasReplicationSQLThreadError() = %v, want %v", input, got, want) + } +} + func TestStatusSQLThreadNotRunning(t *testing.T) { input := &ReplicationStatus{ IOThreadRunning: true, diff --git a/go/vt/proto/replicationdata/replicationdata.pb.go b/go/vt/proto/replicationdata/replicationdata.pb.go index ab6af754b31..98151ffb46d 100644 --- a/go/vt/proto/replicationdata/replicationdata.pb.go +++ b/go/vt/proto/replicationdata/replicationdata.pb.go @@ -63,6 +63,8 @@ type Status struct { FileRelayLogPosition string `protobuf:"bytes,10,opt,name=file_relay_log_position,json=fileRelayLogPosition,proto3" json:"file_relay_log_position,omitempty"` MasterServerId uint32 `protobuf:"varint,11,opt,name=master_server_id,json=masterServerId,proto3" json:"master_server_id,omitempty"` MasterUuid string `protobuf:"bytes,12,opt,name=master_uuid,json=masterUuid,proto3" json:"master_uuid,omitempty"` + LastSqlErrno uint32 `protobuf:"varint,13,opt,name=last_sql_errno,json=lastSqlErrno,proto3" json:"last_sql_errno,omitempty"` + SkipCounter uint32 `protobuf:"varint,14,opt,name=skip_counter,json=skipCounter,proto3" json:"skip_counter,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -177,6 +179,20 @@ func (m *Status) GetMasterUuid() string { return "" } +func (m *Status) GetLastSqlErrno() uint32 { + if m != nil { + return m.LastSqlErrno + } + return 0 +} + +func (m *Status) GetSkipCounter() uint32 { + if m != nil { + return m.SkipCounter + } + return 0 +} + // StopReplicationStatus represents the replication status before calling StopReplication, and the replication status collected immediately after // calling StopReplication. type StopReplicationStatus struct { @@ -284,34 +300,37 @@ func init() { func init() { proto.RegisterFile("replicationdata.proto", fileDescriptor_ee8ee22b8c4b9d06) } var fileDescriptor_ee8ee22b8c4b9d06 = []byte{ - // 454 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xc1, 0x6f, 0xd3, 0x30, - 0x18, 0xc5, 0x49, 0x47, 0x4b, 0xf7, 0xb5, 0xdb, 0x82, 0xb7, 0x6a, 0x11, 0x17, 0xaa, 0x72, 0x89, - 0xa6, 0xd1, 0xa0, 0x21, 0x4e, 0x9c, 0x36, 0x86, 0xb4, 0x4a, 0xdd, 0x3a, 0xdc, 0x71, 0x80, 0x8b, - 0x95, 0xd6, 0x6e, 0x6a, 0x29, 0xe4, 0xcb, 0x6c, 0xa7, 0x68, 0x7f, 0x3b, 0x17, 0x14, 0x3b, 0xeb, - 0x4a, 0x8a, 0x10, 0xb7, 0xf8, 0xbd, 0x9f, 0x1c, 0x7f, 0xcf, 0xcf, 0xd0, 0x53, 0x22, 0x4f, 0xe5, - 0x3c, 0x36, 0x12, 0x33, 0x1e, 0x9b, 0x78, 0x98, 0x2b, 0x34, 0x48, 0x0e, 0x6a, 0xf2, 0xe0, 0xd7, - 0x0e, 0xb4, 0xa6, 0x26, 0x36, 0x85, 0x26, 0xaf, 0xa0, 0x9d, 0xa3, 0x96, 0xa5, 0x15, 0x78, 0x7d, - 0x2f, 0xdc, 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, 0x42, 0x31, 0xc9, 0x83, 0x8e, 0x0d, 0x6b, - 0xdf, 0xe9, 0x53, 0x2b, 0x8f, 0xf8, 0x46, 0x0c, 0x45, 0x21, 0x79, 0xd0, 0xdd, 0xcc, 0xe9, 0x6b, - 0x21, 0xf9, 0xe0, 0x27, 0xf4, 0xa6, 0x06, 0x73, 0xfa, 0x54, 0x8a, 0xaa, 0x0b, 0x11, 0xb4, 0x66, - 0x62, 0x81, 0x4a, 0xd8, 0x26, 0x74, 0xce, 0x8e, 0x87, 0xf5, 0x3e, 0x39, 0x90, 0x56, 0x18, 0x79, - 0x0b, 0xcd, 0x78, 0x51, 0x5e, 0x5b, 0xe3, 0xdf, 0xbc, 0xa3, 0x06, 0x13, 0xe8, 0xba, 0xbb, 0xfc, - 0x8f, 0xee, 0x6d, 0x65, 0xd9, 0xd8, 0xce, 0xf2, 0xe4, 0x23, 0x1c, 0xd6, 0x26, 0xb9, 0x46, 0x2e, - 0x08, 0x81, 0xfd, 0xd1, 0xe4, 0xfc, 0xe6, 0x72, 0xfa, 0x65, 0x7c, 0x77, 0x45, 0x3f, 0x9f, 0x5f, - 0xfa, 0xcf, 0x88, 0x0f, 0xdd, 0xd1, 0xc4, 0xad, 0x26, 0x37, 0xe3, 0x6f, 0xbe, 0x77, 0x31, 0xfc, - 0x7e, 0xba, 0x92, 0x46, 0x68, 0x3d, 0x94, 0x18, 0xb9, 0xaf, 0x28, 0xc1, 0x68, 0x65, 0x22, 0xfb, - 0x6a, 0xa2, 0xda, 0x2c, 0xb3, 0x96, 0x95, 0xdf, 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x14, 0xa4, - 0xdd, 0xf6, 0x65, 0x03, 0x00, 0x00, + // 498 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x5d, 0x6f, 0xda, 0x3c, + 0x14, 0xc7, 0x9f, 0xf0, 0x14, 0x46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, 0x4e, 0x0e, 0xfb, 0xe5, 0xc1, 0x74, 0x62, 0xbc, 0xd6, 0xc8, 0x5b, 0xa8, 0x26, 0x33, 0x73, + 0x4a, 0xe5, 0xef, 0xbe, 0xb3, 0xba, 0x23, 0xf0, 0xdd, 0x50, 0xfc, 0xc3, 0x10, 0x3f, 0x69, 0x4a, + 0xe5, 0x69, 0x53, 0x8e, 0x3e, 0xc2, 0x7e, 0xe9, 0x25, 0xd7, 0x98, 0x32, 0x42, 0xa0, 0x35, 0x18, + 0x9d, 0xde, 0x5c, 0x8c, 0x3f, 0x0d, 0xef, 0xae, 0xe2, 0xcb, 0xd3, 0x8b, 0xe0, 0x3f, 0x12, 0x80, + 0x3f, 0x18, 0xb9, 0xd5, 0xe8, 0x66, 0xf8, 0x25, 0xf0, 0xce, 0xfa, 0x5f, 0x8f, 0x57, 0x5c, 0x33, + 0xa5, 0xfa, 0x1c, 0x23, 0xf7, 0x15, 0xcd, 0x31, 0x5a, 0xe9, 0xc8, 0xfe, 0x7e, 0x51, 0xe9, 0x2d, + 0x93, 0x9a, 0xc5, 0xef, 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, 0x08, 0x80, 0xcc, 0x74, 0xae, 0x03, + 0x00, 0x00, } diff --git a/go/vt/vttablet/tabletserver/repltracker/poller.go b/go/vt/vttablet/tabletserver/repltracker/poller.go index dd77cc22188..87f492ec8f2 100644 --- a/go/vt/vttablet/tabletserver/repltracker/poller.go +++ b/go/vt/vttablet/tabletserver/repltracker/poller.go @@ -46,6 +46,9 @@ func (p *poller) Status() (time.Duration, error) { return 0, err } + if status.HasReplicationSQLThreadError() { + return 0, vterrors.Errorf(vtrpcpb.Code_UNAVAILABLE, "replication sql thread error") + } if !status.ReplicationRunning() { if p.timeRecorded.IsZero() { return 0, vterrors.Errorf(vtrpcpb.Code_UNAVAILABLE, "replication is not running") diff --git a/proto/replicationdata.proto b/proto/replicationdata.proto index 2946ac4eb9e..6bc87dce75e 100644 --- a/proto/replicationdata.proto +++ b/proto/replicationdata.proto @@ -37,6 +37,8 @@ message Status { string file_relay_log_position = 10; uint32 master_server_id = 11; string master_uuid = 12; + uint32 last_sql_errno = 13; + uint32 skip_counter = 14; } // StopReplicationStatus represents the replication status before calling StopReplication, and the replication status collected immediately after