From f8330d428b22cbcd5c1be8271655ab64e9030978 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Fri, 21 Feb 2025 20:41:02 +0100 Subject: [PATCH 1/3] Return `SourceAlias` in `FullStatus` RPC, use to optimize VTOrc Signed-off-by: Tim Vaillancourt --- .../replicationdata/replicationdata.pb.go | 46 ++++++++++------ .../replicationdata_vtproto.pb.go | 54 +++++++++++++++++++ go/vt/vtorc/db/generate_base.go | 1 + go/vt/vtorc/inst/analysis_dao_test.go | 8 +-- go/vt/vtorc/inst/instance.go | 1 + go/vt/vtorc/inst/instance_dao.go | 29 +++++++--- go/vt/vtorc/inst/instance_dao_test.go | 20 +++---- .../vttablet/tabletmanager/rpc_replication.go | 21 +++++++- go/vt/vttablet/tabletmanager/tm_init.go | 3 ++ proto/replicationdata.proto | 3 ++ web/vtadmin/src/proto/vtadmin.d.ts | 6 +++ web/vtadmin/src/proto/vtadmin.js | 28 ++++++++++ 12 files changed, 184 insertions(+), 36 deletions(-) diff --git a/go/vt/proto/replicationdata/replicationdata.pb.go b/go/vt/proto/replicationdata/replicationdata.pb.go index d99881e2cad..393894eb783 100644 --- a/go/vt/proto/replicationdata/replicationdata.pb.go +++ b/go/vt/proto/replicationdata/replicationdata.pb.go @@ -29,6 +29,7 @@ import ( reflect "reflect" sync "sync" unsafe "unsafe" + topodata "vitess.io/vitess/go/vt/proto/topodata" ) const ( @@ -504,6 +505,7 @@ type FullStatus struct { SuperReadOnly bool `protobuf:"varint,21,opt,name=super_read_only,json=superReadOnly,proto3" json:"super_read_only,omitempty"` ReplicationConfiguration *Configuration `protobuf:"bytes,22,opt,name=replication_configuration,json=replicationConfiguration,proto3" json:"replication_configuration,omitempty"` DiskStalled bool `protobuf:"varint,23,opt,name=disk_stalled,json=diskStalled,proto3" json:"disk_stalled,omitempty"` + SourceAlias *topodata.TabletAlias `protobuf:"bytes,24,opt,name=source_alias,json=sourceAlias,proto3" json:"source_alias,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -699,12 +701,20 @@ func (x *FullStatus) GetDiskStalled() bool { return false } +func (x *FullStatus) GetSourceAlias() *topodata.TabletAlias { + if x != nil { + return x.SourceAlias + } + return nil +} + var File_replicationdata_proto protoreflect.FileDescriptor var file_replicationdata_proto_rawDesc = string([]byte{ 0x0a, 0x15, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x64, 0x61, 0x74, 0x61, 0x22, 0xbd, 0x07, 0x0a, 0x06, 0x53, 0x74, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x0e, 0x74, 0x6f, 0x70, 0x6f, 0x64, 0x61, + 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xbd, 0x07, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x36, 0x0a, 0x17, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6c, @@ -786,7 +796,7 @@ var file_replicationdata_proto_rawDesc = string([]byte{ 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x66, 0x69, 0x6c, 0x65, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x75, 0x75, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x55, 0x75, 0x69, 0x64, 0x22, 0xeb, 0x08, 0x0a, 0x0a, 0x46, 0x75, 0x6c, 0x6c, 0x53, 0x74, 0x61, + 0x55, 0x75, 0x69, 0x64, 0x22, 0xa5, 0x09, 0x0a, 0x0a, 0x46, 0x75, 0x6c, 0x6c, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x75, 0x75, 0x69, 0x64, 0x18, @@ -857,14 +867,18 @@ var file_replicationdata_proto_rawDesc = string([]byte{ 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x0a, 0x0c, 0x64, 0x69, 0x73, 0x6b, 0x5f, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x18, 0x17, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x64, 0x69, 0x73, 0x6b, 0x53, 0x74, 0x61, 0x6c, 0x6c, - 0x65, 0x64, 0x2a, 0x3b, 0x0a, 0x13, 0x53, 0x74, 0x6f, 0x70, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x0e, 0x49, 0x4f, 0x41, - 0x4e, 0x44, 0x53, 0x51, 0x4c, 0x54, 0x48, 0x52, 0x45, 0x41, 0x44, 0x10, 0x00, 0x12, 0x10, 0x0a, - 0x0c, 0x49, 0x4f, 0x54, 0x48, 0x52, 0x45, 0x41, 0x44, 0x4f, 0x4e, 0x4c, 0x59, 0x10, 0x01, 0x42, - 0x2e, 0x5a, 0x2c, 0x76, 0x69, 0x74, 0x65, 0x73, 0x73, 0x2e, 0x69, 0x6f, 0x2f, 0x76, 0x69, 0x74, - 0x65, 0x73, 0x73, 0x2f, 0x67, 0x6f, 0x2f, 0x76, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, - 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x64, 0x61, 0x74, 0x61, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x64, 0x12, 0x38, 0x0a, 0x0c, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x61, 0x6c, 0x69, + 0x61, 0x73, 0x18, 0x18, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x74, 0x6f, 0x70, 0x6f, 0x64, + 0x61, 0x74, 0x61, 0x2e, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x74, 0x41, 0x6c, 0x69, 0x61, 0x73, 0x52, + 0x0b, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x41, 0x6c, 0x69, 0x61, 0x73, 0x2a, 0x3b, 0x0a, 0x13, + 0x53, 0x74, 0x6f, 0x70, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4d, + 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x0e, 0x49, 0x4f, 0x41, 0x4e, 0x44, 0x53, 0x51, 0x4c, 0x54, + 0x48, 0x52, 0x45, 0x41, 0x44, 0x10, 0x00, 0x12, 0x10, 0x0a, 0x0c, 0x49, 0x4f, 0x54, 0x48, 0x52, + 0x45, 0x41, 0x44, 0x4f, 0x4e, 0x4c, 0x59, 0x10, 0x01, 0x42, 0x2e, 0x5a, 0x2c, 0x76, 0x69, 0x74, + 0x65, 0x73, 0x73, 0x2e, 0x69, 0x6f, 0x2f, 0x76, 0x69, 0x74, 0x65, 0x73, 0x73, 0x2f, 0x67, 0x6f, + 0x2f, 0x76, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x64, 0x61, 0x74, 0x61, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, }) var ( @@ -888,6 +902,7 @@ var file_replicationdata_proto_goTypes = []any{ (*StopReplicationStatus)(nil), // 3: replicationdata.StopReplicationStatus (*PrimaryStatus)(nil), // 4: replicationdata.PrimaryStatus (*FullStatus)(nil), // 5: replicationdata.FullStatus + (*topodata.TabletAlias)(nil), // 6: topodata.TabletAlias } var file_replicationdata_proto_depIdxs = []int32{ 1, // 0: replicationdata.StopReplicationStatus.before:type_name -> replicationdata.Status @@ -895,11 +910,12 @@ var file_replicationdata_proto_depIdxs = []int32{ 1, // 2: replicationdata.FullStatus.replication_status:type_name -> replicationdata.Status 4, // 3: replicationdata.FullStatus.primary_status:type_name -> replicationdata.PrimaryStatus 2, // 4: replicationdata.FullStatus.replication_configuration:type_name -> replicationdata.Configuration - 5, // [5:5] is the sub-list for method output_type - 5, // [5:5] is the sub-list for method input_type - 5, // [5:5] is the sub-list for extension type_name - 5, // [5:5] is the sub-list for extension extendee - 0, // [0:5] is the sub-list for field type_name + 6, // 5: replicationdata.FullStatus.source_alias:type_name -> topodata.TabletAlias + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name } func init() { file_replicationdata_proto_init() } diff --git a/go/vt/proto/replicationdata/replicationdata_vtproto.pb.go b/go/vt/proto/replicationdata/replicationdata_vtproto.pb.go index 92f8e3074c3..556ea0dc532 100644 --- a/go/vt/proto/replicationdata/replicationdata_vtproto.pb.go +++ b/go/vt/proto/replicationdata/replicationdata_vtproto.pb.go @@ -12,6 +12,7 @@ import ( protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" math "math" + topodata "vitess.io/vitess/go/vt/proto/topodata" ) const ( @@ -143,6 +144,7 @@ func (m *FullStatus) CloneVT() *FullStatus { r.SuperReadOnly = m.SuperReadOnly r.ReplicationConfiguration = m.ReplicationConfiguration.CloneVT() r.DiskStalled = m.DiskStalled + r.SourceAlias = m.SourceAlias.CloneVT() if len(m.unknownFields) > 0 { r.unknownFields = make([]byte, len(m.unknownFields)) copy(r.unknownFields, m.unknownFields) @@ -553,6 +555,18 @@ func (m *FullStatus) MarshalToSizedBufferVT(dAtA []byte) (int, error) { i -= len(m.unknownFields) copy(dAtA[i:], m.unknownFields) } + if m.SourceAlias != nil { + size, err := m.SourceAlias.MarshalToSizedBufferVT(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = protohelpers.EncodeVarint(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xc2 + } if m.DiskStalled { i-- if m.DiskStalled { @@ -991,6 +1005,10 @@ func (m *FullStatus) SizeVT() (n int) { if m.DiskStalled { n += 3 } + if m.SourceAlias != nil { + l = m.SourceAlias.SizeVT() + n += 2 + l + protohelpers.SizeOfVarint(uint64(l)) + } n += len(m.unknownFields) return n } @@ -2587,6 +2605,42 @@ func (m *FullStatus) UnmarshalVT(dAtA []byte) error { } } m.DiskStalled = bool(v != 0) + case 24: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SourceAlias", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protohelpers.ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protohelpers.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protohelpers.ErrInvalidLength + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.SourceAlias == nil { + m.SourceAlias = &topodata.TabletAlias{} + } + if err := m.SourceAlias.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := protohelpers.Skip(dAtA[iNdEx:]) diff --git a/go/vt/vtorc/db/generate_base.go b/go/vt/vtorc/db/generate_base.go index 8baa9a12476..0e3efeebc89 100644 --- a/go/vt/vtorc/db/generate_base.go +++ b/go/vt/vtorc/db/generate_base.go @@ -53,6 +53,7 @@ CREATE TABLE database_instance ( log_replica_updates tinyint NOT NULL, binary_log_file varchar(128) NOT NULL, binary_log_pos bigint NOT NULL, + source_alias varchar(256) NOT NULL, source_host varchar(128) NOT NULL, source_port smallint NOT NULL, replica_net_timeout int NOT NULL, diff --git a/go/vt/vtorc/inst/analysis_dao_test.go b/go/vt/vtorc/inst/analysis_dao_test.go index baa1121b776..c468d3eb71b 100644 --- a/go/vt/vtorc/inst/analysis_dao_test.go +++ b/go/vt/vtorc/inst/analysis_dao_test.go @@ -34,10 +34,10 @@ var ( // The initialSQL is a set of insert commands copied from a dump of an actual running VTOrc instances. The relevant insert commands are here. // This is a dump taken from a test running 4 tablets, zone1-101 is the primary, zone1-100 is a replica, zone1-112 is a rdonly and zone2-200 is a cross-cell replica. initialSQL = []string{ - `INSERT INTO database_instance VALUES('zone1-0000000112','localhost',6747,'2022-12-28 07:26:04','2022-12-28 07:26:04',213696377,'8.0.31','ROW',1,1,'vt-0000000112-bin.000001',15963,'localhost',6714,8,4.0,1,1,'vt-0000000101-bin.000001',15583,'vt-0000000101-bin.000001',15583,0,0,1,'','',1,'vt-0000000112-relay-bin.000002',15815,1,0,'zone1','',0,0,0,1,'729a4cc4-8680-11ed-a104-47706090afbd:1-54','729a5138-8680-11ed-9240-92a06c3be3c2','2022-12-28 07:26:04','',1,0,0,'Homebrew','8.0','FULL',10816929,0,0,'ON',1,'729a4cc4-8680-11ed-a104-47706090afbd','','729a4cc4-8680-11ed-a104-47706090afbd,729a5138-8680-11ed-9240-92a06c3be3c2',1,1,'',1000000000000000000,1,0,0,0,false);`, - `INSERT INTO database_instance VALUES('zone1-0000000100','localhost',6711,'2022-12-28 07:26:04','2022-12-28 07:26:04',1094500338,'8.0.31','ROW',1,1,'vt-0000000100-bin.000001',15963,'localhost',6714,8,4.0,1,1,'vt-0000000101-bin.000001',15583,'vt-0000000101-bin.000001',15583,0,0,1,'','',1,'vt-0000000100-relay-bin.000002',15815,1,0,'zone1','',0,0,0,1,'729a4cc4-8680-11ed-a104-47706090afbd:1-54','729a5138-8680-11ed-acf8-d6b0ef9f4eaa','2022-12-28 07:26:04','',1,0,0,'Homebrew','8.0','FULL',10103920,0,1,'ON',1,'729a4cc4-8680-11ed-a104-47706090afbd','','729a4cc4-8680-11ed-a104-47706090afbd,729a5138-8680-11ed-acf8-d6b0ef9f4eaa',1,1,'',1000000000000000000,1,0,1,0,false);`, - `INSERT INTO database_instance VALUES('zone1-0000000101','localhost',6714,'2022-12-28 07:26:04','2022-12-28 07:26:04',390954723,'8.0.31','ROW',1,1,'vt-0000000101-bin.000001',15583,'',0,0,0,0,0,'',0,'',0,NULL,NULL,0,'','',0,'',0,0,0,'zone1','',0,0,0,1,'729a4cc4-8680-11ed-a104-47706090afbd:1-54','729a4cc4-8680-11ed-a104-47706090afbd','2022-12-28 07:26:04','',0,0,0,'Homebrew','8.0','FULL',11366095,1,1,'ON',1,'','','729a4cc4-8680-11ed-a104-47706090afbd',-1,-1,'',1000000000000000000,1,1,0,2,false);`, - `INSERT INTO database_instance VALUES('zone2-0000000200','localhost',6756,'2022-12-28 07:26:05','2022-12-28 07:26:05',444286571,'8.0.31','ROW',1,1,'vt-0000000200-bin.000001',15963,'localhost',6714,8,4.0,1,1,'vt-0000000101-bin.000001',15583,'vt-0000000101-bin.000001',15583,0,0,1,'','',1,'vt-0000000200-relay-bin.000002',15815,1,0,'zone2','',0,0,0,1,'729a4cc4-8680-11ed-a104-47706090afbd:1-54','729a497c-8680-11ed-8ad4-3f51d747db75','2022-12-28 07:26:05','',1,0,0,'Homebrew','8.0','FULL',10443112,0,1,'ON',1,'729a4cc4-8680-11ed-a104-47706090afbd','','729a4cc4-8680-11ed-a104-47706090afbd,729a497c-8680-11ed-8ad4-3f51d747db75',1,1,'',1000000000000000000,1,0,1,0,false);`, + `INSERT INTO database_instance VALUES('zone1-0000000112','localhost',6747,'2022-12-28 07:26:04','2022-12-28 07:26:04',213696377,'8.0.31','ROW',1,1,'vt-0000000112-bin.000001',15963,'zone1-0000000111','localhost',6714,8,4.0,1,1,'vt-0000000101-bin.000001',15583,'vt-0000000101-bin.000001',15583,0,0,1,'','',1,'vt-0000000112-relay-bin.000002',15815,1,0,'zone1','',0,0,0,1,'729a4cc4-8680-11ed-a104-47706090afbd:1-54','729a5138-8680-11ed-9240-92a06c3be3c2','2022-12-28 07:26:04','',1,0,0,'Homebrew','8.0','FULL',10816929,0,0,'ON',1,'729a4cc4-8680-11ed-a104-47706090afbd','','729a4cc4-8680-11ed-a104-47706090afbd,729a5138-8680-11ed-9240-92a06c3be3c2',1,1,'',1000000000000000000,1,0,0,0,false);`, + `INSERT INTO database_instance VALUES('zone1-0000000100','localhost',6711,'2022-12-28 07:26:04','2022-12-28 07:26:04',1094500338,'8.0.31','ROW',1,1,'vt-0000000100-bin.000001',15963,'zone1-0000000099','localhost',6714,8,4.0,1,1,'vt-0000000101-bin.000001',15583,'vt-0000000101-bin.000001',15583,0,0,1,'','',1,'vt-0000000100-relay-bin.000002',15815,1,0,'zone1','',0,0,0,1,'729a4cc4-8680-11ed-a104-47706090afbd:1-54','729a5138-8680-11ed-acf8-d6b0ef9f4eaa','2022-12-28 07:26:04','',1,0,0,'Homebrew','8.0','FULL',10103920,0,1,'ON',1,'729a4cc4-8680-11ed-a104-47706090afbd','','729a4cc4-8680-11ed-a104-47706090afbd,729a5138-8680-11ed-acf8-d6b0ef9f4eaa',1,1,'',1000000000000000000,1,0,1,0,false);`, + `INSERT INTO database_instance VALUES('zone1-0000000101','localhost',6714,'2022-12-28 07:26:04','2022-12-28 07:26:04',390954723,'8.0.31','ROW',1,1,'vt-0000000101-bin.000001',15583,'','',0,0,0,0,0,'',0,'',0,NULL,NULL,0,'','',0,'',0,0,0,'zone1','',0,0,0,1,'729a4cc4-8680-11ed-a104-47706090afbd:1-54','729a4cc4-8680-11ed-a104-47706090afbd','2022-12-28 07:26:04','',0,0,0,'Homebrew','8.0','FULL',11366095,1,1,'ON',1,'','','729a4cc4-8680-11ed-a104-47706090afbd',-1,-1,'',1000000000000000000,1,1,0,2,false);`, + `INSERT INTO database_instance VALUES('zone2-0000000200','localhost',6756,'2022-12-28 07:26:05','2022-12-28 07:26:05',444286571,'8.0.31','ROW',1,1,'vt-0000000200-bin.000001',15963,'zone1-0000000199','localhost',6714,8,4.0,1,1,'vt-0000000101-bin.000001',15583,'vt-0000000101-bin.000001',15583,0,0,1,'','',1,'vt-0000000200-relay-bin.000002',15815,1,0,'zone2','',0,0,0,1,'729a4cc4-8680-11ed-a104-47706090afbd:1-54','729a497c-8680-11ed-8ad4-3f51d747db75','2022-12-28 07:26:05','',1,0,0,'Homebrew','8.0','FULL',10443112,0,1,'ON',1,'729a4cc4-8680-11ed-a104-47706090afbd','','729a4cc4-8680-11ed-a104-47706090afbd,729a497c-8680-11ed-8ad4-3f51d747db75',1,1,'',1000000000000000000,1,0,1,0,false);`, `INSERT INTO vitess_tablet VALUES('zone1-0000000100','localhost',6711,'ks','0','zone1',2,'0001-01-01 00:00:00+00:00',X'616c6961733a7b63656c6c3a227a6f6e653122207569643a3130307d20686f73746e616d653a226c6f63616c686f73742220706f72745f6d61703a7b6b65793a2267727063222076616c75653a363731307d20706f72745f6d61703a7b6b65793a227674222076616c75653a363730397d206b657973706163653a226b73222073686172643a22302220747970653a5245504c494341206d7973716c5f686f73746e616d653a226c6f63616c686f737422206d7973716c5f706f72743a363731312064625f7365727665725f76657273696f6e3a22382e302e3331222064656661756c745f636f6e6e5f636f6c6c6174696f6e3a3435');`, `INSERT INTO vitess_tablet VALUES('zone1-0000000101','localhost',6714,'ks','0','zone1',1,'2022-12-28 07:23:25.129898+00:00',X'616c6961733a7b63656c6c3a227a6f6e653122207569643a3130317d20686f73746e616d653a226c6f63616c686f73742220706f72745f6d61703a7b6b65793a2267727063222076616c75653a363731337d20706f72745f6d61703a7b6b65793a227674222076616c75653a363731327d206b657973706163653a226b73222073686172643a22302220747970653a5052494d415259206d7973716c5f686f73746e616d653a226c6f63616c686f737422206d7973716c5f706f72743a36373134207072696d6172795f7465726d5f73746172745f74696d653a7b7365636f6e64733a31363732323132323035206e616e6f7365636f6e64733a3132393839383030307d2064625f7365727665725f76657273696f6e3a22382e302e3331222064656661756c745f636f6e6e5f636f6c6c6174696f6e3a3435');`, `INSERT INTO vitess_tablet VALUES('zone1-0000000112','localhost',6747,'ks','0','zone1',3,'0001-01-01 00:00:00+00:00',X'616c6961733a7b63656c6c3a227a6f6e653122207569643a3131327d20686f73746e616d653a226c6f63616c686f73742220706f72745f6d61703a7b6b65793a2267727063222076616c75653a363734367d20706f72745f6d61703a7b6b65793a227674222076616c75653a363734357d206b657973706163653a226b73222073686172643a22302220747970653a52444f4e4c59206d7973716c5f686f73746e616d653a226c6f63616c686f737422206d7973716c5f706f72743a363734372064625f7365727665725f76657273696f6e3a22382e302e3331222064656661756c745f636f6e6e5f636f6c6c6174696f6e3a3435');`, diff --git a/go/vt/vtorc/inst/instance.go b/go/vt/vtorc/inst/instance.go index b7b097bb14d..b35f9262f74 100644 --- a/go/vt/vtorc/inst/instance.go +++ b/go/vt/vtorc/inst/instance.go @@ -40,6 +40,7 @@ type Instance struct { LogBinEnabled bool LogReplicationUpdatesEnabled bool SelfBinlogCoordinates BinlogCoordinates + SourceAlias string SourceHost string SourcePort int SourceUUID string diff --git a/go/vt/vtorc/inst/instance_dao.go b/go/vt/vtorc/inst/instance_dao.go index 9e35e6e3e0b..c86660b51da 100644 --- a/go/vt/vtorc/inst/instance_dao.go +++ b/go/vt/vtorc/inst/instance_dao.go @@ -299,6 +299,7 @@ func ReadTopologyInstanceBufferable(tabletAlias string, latency *stopwatch.Named instance.SourceUUID = fs.ReplicationStatus.SourceUuid instance.HasReplicationFilters = fs.ReplicationStatus.HasReplicationFilters + instance.SourceAlias = topoproto.TabletAliasString(fs.SourceAlias) instance.SourceHost = fs.ReplicationStatus.SourceHost instance.SourcePort = int(fs.ReplicationStatus.SourcePort) @@ -478,7 +479,21 @@ func ReadInstanceClusterAttributes(instance *Instance) (err error) { var primaryExecutedGtidSet string primaryDataFound := false - query := `SELECT + primaryAlias := instance.SourceAlias + primaryHostname := instance.SourceHost + primaryPort := instance.SourcePort + + // Using alias is a primary-key read + whereCond := `alias = ?` + args := sqlutils.Args(primaryAlias) + + // Fallback to hostname + port query if no primaryAlias defined (added in v22) + if primaryAlias == "" { + whereCond = `hostname = ? AND port = ?` + args = sqlutils.Args(primaryHostname, primaryPort) + } + + query := fmt.Sprintf(`SELECT replication_depth, source_host, source_port, @@ -486,11 +501,10 @@ func ReadInstanceClusterAttributes(instance *Instance) (err error) { executed_gtid_set FROM database_instance WHERE - hostname = ? - AND port = ?` - primaryHostname := instance.SourceHost - primaryPort := instance.SourcePort - args := sqlutils.Args(primaryHostname, primaryPort) + %s`, + whereCond, + ) + err = db.QueryVTOrc(query, args, func(m sqlutils.RowMap) error { primaryReplicationDepth = m.GetUint("replication_depth") primaryHostname = m.GetString("source_host") @@ -536,6 +550,7 @@ func readInstanceRow(m sqlutils.RowMap) *Instance { instance.BinlogRowImage = m.GetString("binlog_row_image") instance.LogBinEnabled = m.GetBool("log_bin") instance.LogReplicationUpdatesEnabled = m.GetBool("log_replica_updates") + instance.SourceAlias = m.GetString("source_alias") instance.SourceHost = m.GetString("source_host") instance.SourcePort = m.GetInt("source_port") instance.ReplicaNetTimeout = m.GetInt32("replica_net_timeout") @@ -836,6 +851,7 @@ func mkInsertForInstances(instances []*Instance, instanceWasActuallyFound bool, "log_replica_updates", "binary_log_file", "binary_log_pos", + "source_alias", "source_host", "source_port", "replica_net_timeout", @@ -916,6 +932,7 @@ func mkInsertForInstances(instances []*Instance, instanceWasActuallyFound bool, args = append(args, instance.LogReplicationUpdatesEnabled) args = append(args, instance.SelfBinlogCoordinates.LogFile) args = append(args, instance.SelfBinlogCoordinates.LogPos) + args = append(args, instance.SourceAlias) args = append(args, instance.SourceHost) args = append(args, instance.SourcePort) args = append(args, instance.ReplicaNetTimeout) diff --git a/go/vt/vtorc/inst/instance_dao_test.go b/go/vt/vtorc/inst/instance_dao_test.go index c3b99455741..7e5ec4d6826 100644 --- a/go/vt/vtorc/inst/instance_dao_test.go +++ b/go/vt/vtorc/inst/instance_dao_test.go @@ -62,14 +62,14 @@ func TestMkInsertSingle(t *testing.T) { s1 := `INSERT OR IGNORE INTO database_instance (alias, hostname, port, last_checked, last_attempted_check, last_check_partial_success, server_id, server_uuid, version, major_version, version_comment, binlog_server, read_only, binlog_format, - binlog_row_image, log_bin, log_replica_updates, binary_log_file, binary_log_pos, source_host, source_port, replica_net_timeout, heartbeat_interval, + binlog_row_image, log_bin, log_replica_updates, binary_log_file, binary_log_pos, source_alias, source_host, source_port, replica_net_timeout, heartbeat_interval, replica_sql_running, replica_io_running, replication_sql_thread_state, replication_io_thread_state, has_replication_filters, supports_oracle_gtid, oracle_gtid, source_uuid, ancestry_uuid, executed_gtid_set, gtid_mode, gtid_purged, gtid_errant, source_log_file, read_source_log_pos, relay_source_log_file, exec_source_log_pos, relay_log_file, relay_log_pos, last_sql_error, last_io_error, replication_lag_seconds, replica_lag_seconds, sql_delay, data_center, region, physical_environment, replication_depth, is_co_primary, has_replication_credentials, allow_tls, semi_sync_enforced, semi_sync_primary_enabled, semi_sync_primary_timeout, semi_sync_primary_wait_for_replica_count, semi_sync_replica_enabled, semi_sync_primary_status, semi_sync_primary_clients, semi_sync_replica_status, last_discovery_latency, is_disk_stalled, last_seen) VALUES - (?, ?, ?, DATETIME('now'), DATETIME('now'), 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, DATETIME('now')) + (?, ?, ?, DATETIME('now'), DATETIME('now'), 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, DATETIME('now')) ` a1 := `zone1-i710, i710, 3306, 710, , 5.6.7, 5.6, MySQL, false, false, STATEMENT, - FULL, false, false, , 0, , 0, 0, 0, + FULL, false, false, , 0, , , 0, 0, 0, false, false, 0, 0, false, false, false, , , , , , , , 0, mysql.000007, 10, , 0, , , {0 false}, {0 false}, 0, , , , 0, false, false, false, false, false, 0, 0, false, false, 0, false, 0, false,` sql1, args1, err := mkInsertForInstances(instances[:1], false, true) @@ -85,18 +85,18 @@ func TestMkInsertThree(t *testing.T) { s3 := `REPLACE INTO database_instance (alias, hostname, port, last_checked, last_attempted_check, last_check_partial_success, server_id, server_uuid, version, major_version, version_comment, binlog_server, read_only, binlog_format, - binlog_row_image, log_bin, log_replica_updates, binary_log_file, binary_log_pos, source_host, source_port, replica_net_timeout, heartbeat_interval, + binlog_row_image, log_bin, log_replica_updates, binary_log_file, binary_log_pos, source_alias, source_host, source_port, replica_net_timeout, heartbeat_interval, replica_sql_running, replica_io_running, replication_sql_thread_state, replication_io_thread_state, has_replication_filters, supports_oracle_gtid, oracle_gtid, source_uuid, ancestry_uuid, executed_gtid_set, gtid_mode, gtid_purged, gtid_errant, source_log_file, read_source_log_pos, relay_source_log_file, exec_source_log_pos, relay_log_file, relay_log_pos, last_sql_error, last_io_error, replication_lag_seconds, replica_lag_seconds, sql_delay, data_center, region, physical_environment, replication_depth, is_co_primary, has_replication_credentials, allow_tls, semi_sync_enforced, semi_sync_primary_enabled, semi_sync_primary_timeout, semi_sync_primary_wait_for_replica_count, semi_sync_replica_enabled, semi_sync_primary_status, semi_sync_primary_clients, semi_sync_replica_status, last_discovery_latency, is_disk_stalled, last_seen) VALUES - (?, ?, ?, DATETIME('now'), DATETIME('now'), 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, DATETIME('now')), - (?, ?, ?, DATETIME('now'), DATETIME('now'), 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, DATETIME('now')), - (?, ?, ?, DATETIME('now'), DATETIME('now'), 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, DATETIME('now')) + (?, ?, ?, DATETIME('now'), DATETIME('now'), 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, DATETIME('now')), + (?, ?, ?, DATETIME('now'), DATETIME('now'), 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, DATETIME('now')), + (?, ?, ?, DATETIME('now'), DATETIME('now'), 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, DATETIME('now')) ` a3 := ` - zone1-i710, i710, 3306, 710, , 5.6.7, 5.6, MySQL, false, false, STATEMENT, FULL, false, false, , 0, , 0, 0, 0, false, false, 0, 0, false, false, false, , , , , , , , 0, mysql.000007, 10, , 0, , , {0 false}, {0 false}, 0, , , , 0, false, false, false, false, false, 0, 0, false, false, 0, false, 0, false, - zone1-i720, i720, 3306, 720, , 5.6.7, 5.6, MySQL, false, false, STATEMENT, FULL, false, false, , 0, , 0, 0, 0, false, false, 0, 0, false, false, false, , , , , , , , 0, mysql.000007, 20, , 0, , , {0 false}, {0 false}, 0, , , , 0, false, false, false, false, false, 0, 0, false, false, 0, false, 0, false, - zone1-i730, i730, 3306, 730, , 5.6.7, 5.6, MySQL, false, false, STATEMENT, FULL, false, false, , 0, , 0, 0, 0, false, false, 0, 0, false, false, false, , , , , , , , 0, mysql.000007, 30, , 0, , , {0 false}, {0 false}, 0, , , , 0, false, false, false, false, false, 0, 0, false, false, 0, false, 0, false, + zone1-i710, i710, 3306, 710, , 5.6.7, 5.6, MySQL, false, false, STATEMENT, FULL, false, false, , 0, , , 0, 0, 0, false, false, 0, 0, false, false, false, , , , , , , , 0, mysql.000007, 10, , 0, , , {0 false}, {0 false}, 0, , , , 0, false, false, false, false, false, 0, 0, false, false, 0, false, 0, false, + zone1-i720, i720, 3306, 720, , 5.6.7, 5.6, MySQL, false, false, STATEMENT, FULL, false, false, , 0, , , 0, 0, 0, false, false, 0, 0, false, false, false, , , , , , , , 0, mysql.000007, 20, , 0, , , {0 false}, {0 false}, 0, , , , 0, false, false, false, false, false, 0, 0, false, false, 0, false, 0, false, + zone1-i730, i730, 3306, 730, , 5.6.7, 5.6, MySQL, false, false, STATEMENT, FULL, false, false, , 0, , , 0, 0, 0, false, false, 0, 0, false, false, false, , , , , , , , 0, mysql.000007, 30, , 0, , , {0 false}, {0 false}, 0, , , , 0, false, false, false, false, false, 0, 0, false, false, 0, false, 0, false, ` sql3, args3, err := mkInsertForInstances(instances[:3], true, true) diff --git a/go/vt/vttablet/tabletmanager/rpc_replication.go b/go/vt/vttablet/tabletmanager/rpc_replication.go index 7ac37515b67..3d883360fb5 100644 --- a/go/vt/vttablet/tabletmanager/rpc_replication.go +++ b/go/vt/vttablet/tabletmanager/rpc_replication.go @@ -155,17 +155,24 @@ func (tm *TabletManager) FullStatus(ctx context.Context) (*replicationdatapb.Ful // Semi sync status - "show status like 'Rpl_semi_sync_%_status'" primarySemiSyncStatus, replicaSemiSyncStatus := tm.MysqlDaemon.SemiSyncStatus(ctx) - // Semi sync clients count - "show status like 'semi_sync_source_clients'" + // Semi sync clients count - "show status like 'semi_sync_source_clients'" semiSyncClients := tm.MysqlDaemon.SemiSyncClients(ctx) // Semi sync settings - "show status like 'rpl_semi_sync_%' semiSyncTimeout, semiSyncNumReplicas := tm.MysqlDaemon.SemiSyncSettings(ctx) + // Replication configuration replConfiguration, err := tm.MysqlDaemon.ReplicationConfiguration(ctx) if err != nil { return nil, err } + // Replication source tablet alias + sourceAlias, err := tm.getReplicationSourceAlias(ctx) + if err != nil { + return nil, err + } + return &replicationdatapb.FullStatus{ ServerId: serverID, ServerUuid: serverUUID, @@ -189,6 +196,7 @@ func (tm *TabletManager) FullStatus(ctx context.Context) (*replicationdatapb.Ful SemiSyncWaitForReplicaCount: semiSyncNumReplicas, SuperReadOnly: superReadOnly, ReplicationConfiguration: replConfiguration, + SourceAlias: sourceAlias, }, nil } @@ -731,6 +739,14 @@ func (tm *TabletManager) SetReplicationSource(ctx context.Context, parentAlias * return tm.setReplicationSourceLocked(ctx, parentAlias, timeCreatedNS, waitPosition, forceStartReplication, semiSyncAction, heartbeatInterval) } +func (tm *TabletManager) getReplicationSourceAlias(ctx context.Context) (*topodatapb.TabletAlias, error) { + if err := tm.lock(ctx); err != nil { + return nil, err + } + defer tm.unlock() + return tm.sourceAlias, nil +} + func (tm *TabletManager) setReplicationSourceSemiSyncNoAction(ctx context.Context, parentAlias *topodatapb.TabletAlias, timeCreatedNS int64, waitPosition string, forceStartReplication bool) error { log.Infof("SetReplicationSource: parent: %v position: %v force: %v", parentAlias, waitPosition, forceStartReplication) if err := tm.lock(ctx); err != nil { @@ -883,6 +899,9 @@ func (tm *TabletManager) setReplicationSourceLocked(ctx context.Context, parentA } } + // Store the current primary alias + tm.sourceAlias = parentAlias + return nil } diff --git a/go/vt/vttablet/tabletmanager/tm_init.go b/go/vt/vttablet/tabletmanager/tm_init.go index fbef04de357..6f8cf9c7601 100644 --- a/go/vt/vttablet/tabletmanager/tm_init.go +++ b/go/vt/vttablet/tabletmanager/tm_init.go @@ -174,6 +174,9 @@ type TabletManager struct { // tabletAlias is saved away from tablet for read-only access tabletAlias *topodatapb.TabletAlias + // sourceAlias is the current replication source. + sourceAlias *topodatapb.TabletAlias + // baseTabletType is the tablet type we revert back to // when we transition back from something like PRIMARY. baseTabletType topodatapb.TabletType diff --git a/proto/replicationdata.proto b/proto/replicationdata.proto index eba4d323ee6..4c4f5ed9fb9 100644 --- a/proto/replicationdata.proto +++ b/proto/replicationdata.proto @@ -19,6 +19,8 @@ limitations under the License. syntax = "proto3"; option go_package = "vitess.io/vitess/go/vt/proto/replicationdata"; +import "topodata.proto"; + package replicationdata; // Status is the replication status for MySQL/MariaDB/File-based. Returned by a @@ -106,4 +108,5 @@ message FullStatus { bool super_read_only = 21; replicationdata.Configuration replication_configuration = 22; bool disk_stalled = 23; + topodata.TabletAlias source_alias = 24; } diff --git a/web/vtadmin/src/proto/vtadmin.d.ts b/web/vtadmin/src/proto/vtadmin.d.ts index 527adc01326..710966dee07 100644 --- a/web/vtadmin/src/proto/vtadmin.d.ts +++ b/web/vtadmin/src/proto/vtadmin.d.ts @@ -48801,6 +48801,9 @@ export namespace replicationdata { /** FullStatus disk_stalled */ disk_stalled?: (boolean|null); + + /** FullStatus source_alias */ + source_alias?: (topodata.ITabletAlias|null); } /** Represents a FullStatus. */ @@ -48881,6 +48884,9 @@ export namespace replicationdata { /** FullStatus disk_stalled. */ public disk_stalled: boolean; + /** FullStatus source_alias. */ + public source_alias?: (topodata.ITabletAlias|null); + /** * Creates a new FullStatus instance using the specified properties. * @param [properties] Properties to set diff --git a/web/vtadmin/src/proto/vtadmin.js b/web/vtadmin/src/proto/vtadmin.js index 1209c59cbe9..c867bda3e6e 100644 --- a/web/vtadmin/src/proto/vtadmin.js +++ b/web/vtadmin/src/proto/vtadmin.js @@ -118503,6 +118503,7 @@ export const replicationdata = $root.replicationdata = (() => { * @property {boolean|null} [super_read_only] FullStatus super_read_only * @property {replicationdata.IConfiguration|null} [replication_configuration] FullStatus replication_configuration * @property {boolean|null} [disk_stalled] FullStatus disk_stalled + * @property {topodata.ITabletAlias|null} [source_alias] FullStatus source_alias */ /** @@ -118704,6 +118705,14 @@ export const replicationdata = $root.replicationdata = (() => { */ FullStatus.prototype.disk_stalled = false; + /** + * FullStatus source_alias. + * @member {topodata.ITabletAlias|null|undefined} source_alias + * @memberof replicationdata.FullStatus + * @instance + */ + FullStatus.prototype.source_alias = null; + /** * Creates a new FullStatus instance using the specified properties. * @function create @@ -118774,6 +118783,8 @@ export const replicationdata = $root.replicationdata = (() => { $root.replicationdata.Configuration.encode(message.replication_configuration, writer.uint32(/* id 22, wireType 2 =*/178).fork()).ldelim(); if (message.disk_stalled != null && Object.hasOwnProperty.call(message, "disk_stalled")) writer.uint32(/* id 23, wireType 0 =*/184).bool(message.disk_stalled); + if (message.source_alias != null && Object.hasOwnProperty.call(message, "source_alias")) + $root.topodata.TabletAlias.encode(message.source_alias, writer.uint32(/* id 24, wireType 2 =*/194).fork()).ldelim(); return writer; }; @@ -118900,6 +118911,10 @@ export const replicationdata = $root.replicationdata = (() => { message.disk_stalled = reader.bool(); break; } + case 24: { + message.source_alias = $root.topodata.TabletAlias.decode(reader, reader.uint32()); + break; + } default: reader.skipType(tag & 7); break; @@ -119010,6 +119025,11 @@ export const replicationdata = $root.replicationdata = (() => { if (message.disk_stalled != null && message.hasOwnProperty("disk_stalled")) if (typeof message.disk_stalled !== "boolean") return "disk_stalled: boolean expected"; + if (message.source_alias != null && message.hasOwnProperty("source_alias")) { + let error = $root.topodata.TabletAlias.verify(message.source_alias); + if (error) + return "source_alias." + error; + } return null; }; @@ -119087,6 +119107,11 @@ export const replicationdata = $root.replicationdata = (() => { } if (object.disk_stalled != null) message.disk_stalled = Boolean(object.disk_stalled); + if (object.source_alias != null) { + if (typeof object.source_alias !== "object") + throw TypeError(".replicationdata.FullStatus.source_alias: object expected"); + message.source_alias = $root.topodata.TabletAlias.fromObject(object.source_alias); + } return message; }; @@ -119131,6 +119156,7 @@ export const replicationdata = $root.replicationdata = (() => { object.super_read_only = false; object.replication_configuration = null; object.disk_stalled = false; + object.source_alias = null; } if (message.server_id != null && message.hasOwnProperty("server_id")) object.server_id = message.server_id; @@ -119181,6 +119207,8 @@ export const replicationdata = $root.replicationdata = (() => { object.replication_configuration = $root.replicationdata.Configuration.toObject(message.replication_configuration, options); if (message.disk_stalled != null && message.hasOwnProperty("disk_stalled")) object.disk_stalled = message.disk_stalled; + if (message.source_alias != null && message.hasOwnProperty("source_alias")) + object.source_alias = $root.topodata.TabletAlias.toObject(message.source_alias, options); return object; }; From 510971fab7b238cb04c0a456c36a48828e73e25e Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Fri, 21 Feb 2025 21:48:04 +0100 Subject: [PATCH 2/3] set sourceAlias in more cases Signed-off-by: Tim Vaillancourt --- go/vt/vttablet/tabletmanager/rpc_replication.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/go/vt/vttablet/tabletmanager/rpc_replication.go b/go/vt/vttablet/tabletmanager/rpc_replication.go index 3d883360fb5..908f86af4a1 100644 --- a/go/vt/vttablet/tabletmanager/rpc_replication.go +++ b/go/vt/vttablet/tabletmanager/rpc_replication.go @@ -506,6 +506,9 @@ func (tm *TabletManager) InitReplica(ctx context.Context, parent *topodatapb.Tab return err } + // Store the new source alias + tm.sourceAlias = parent + // wait until we get the replicated row, or our context times out return tm.MysqlDaemon.WaitForReparentJournal(ctx, timeCreatedNS) } @@ -922,6 +925,10 @@ func (tm *TabletManager) ReplicaWasRestarted(ctx context.Context, parent *topoda if tablet.Type != topodatapb.TabletType_PRIMARY { return nil } + + // Store the new primary alias + tm.sourceAlias = parent + return tm.tmState.ChangeTabletType(ctx, topodatapb.TabletType_REPLICA, DBActionNone) } @@ -1047,6 +1054,10 @@ func (tm *TabletManager) PromoteReplica(ctx context.Context, semiSync bool) (str if err := tm.changeTypeLocked(ctx, topodatapb.TabletType_PRIMARY, DBActionSetReadWrite, SemiSyncActionNone); err != nil { return "", err } + + // Set the source alias to nil + tm.sourceAlias = nil + return replication.EncodePosition(pos), nil } From 1b3970fe5a6b320e3e7b57d403442bdadccc10bd Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Fri, 21 Feb 2025 22:25:42 +0100 Subject: [PATCH 3/3] more cases Signed-off-by: Tim Vaillancourt --- go/vt/vttablet/tabletmanager/rpc_replication.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/go/vt/vttablet/tabletmanager/rpc_replication.go b/go/vt/vttablet/tabletmanager/rpc_replication.go index 908f86af4a1..cd043ea08a6 100644 --- a/go/vt/vttablet/tabletmanager/rpc_replication.go +++ b/go/vt/vttablet/tabletmanager/rpc_replication.go @@ -415,6 +415,9 @@ func (tm *TabletManager) InitPrimary(ctx context.Context, semiSync bool) (string return "", err } + // Set source alias to nil + tm.sourceAlias = nil + return replication.EncodePosition(pos), nil } @@ -681,6 +684,10 @@ func (tm *TabletManager) UndoDemotePrimary(ctx context.Context, semiSync bool) e if err := tm.QueryServiceControl.SetServingType(tablet.Type, protoutil.TimeFromProto(tablet.PrimaryTermStartTime).UTC(), true, ""); err != nil { return vterrors.Wrap(err, "SetServingType(serving=true) failed") } + + // Set source alias to nil + tm.sourceAlias = nil + return nil } @@ -694,6 +701,7 @@ func (tm *TabletManager) ReplicaWasPromoted(ctx context.Context) error { return err } defer tm.unlock() + tm.sourceAlias = nil return tm.changeTypeLocked(ctx, topodatapb.TabletType_PRIMARY, DBActionNone, SemiSyncActionNone) } @@ -772,6 +780,7 @@ func (tm *TabletManager) setReplicationSourceLocked(ctx context.Context, parentA if err := tm.tmState.ChangeTabletType(ctx, topodatapb.TabletType_REPLICA, DBActionNone); err != nil { return err } + tm.sourceAlias = nil } // See if we were replicating at all, and should be replicating. @@ -826,6 +835,9 @@ func (tm *TabletManager) setReplicationSourceLocked(ctx context.Context, parentA return err } + // Store the current primary alias + tm.sourceAlias = parentAlias + host := parent.Tablet.MysqlHostname port := parent.Tablet.MysqlPort // If host is empty, then we shouldn't even attempt the reparent. That tablet has already shutdown. @@ -902,9 +914,6 @@ func (tm *TabletManager) setReplicationSourceLocked(ctx context.Context, parentA } } - // Store the current primary alias - tm.sourceAlias = parentAlias - return nil }