diff --git a/go/cmd/mysqlctld/mysqlctld.go b/go/cmd/mysqlctld/mysqlctld.go index 4fbef020f9f..1dee0fa35af 100644 --- a/go/cmd/mysqlctld/mysqlctld.go +++ b/go/cmd/mysqlctld/mysqlctld.go @@ -98,7 +98,7 @@ func main() { } mysqld.OnTerm(onTermFunc) - err = mysqld.RefreshConfig() + err = mysqld.RefreshConfig(ctx) if err != nil { log.Errorf("failed to refresh config: %v", err) exit.Return(1) diff --git a/go/vt/mysqlctl/backup.go b/go/vt/mysqlctl/backup.go index b5828c22b4d..6dc38639506 100644 --- a/go/vt/mysqlctl/backup.go +++ b/go/vt/mysqlctl/backup.go @@ -321,7 +321,7 @@ func backup(ctx context.Context, mysqld MysqlDaemon, logger logutil.Logger, bh b usable := backupErr == nil // Try to restart mysqld - err = mysqld.RefreshConfig() + err = mysqld.RefreshConfig(ctx) if err != nil { return usable, fmt.Errorf("can't refresh mysqld config: %v", err) } diff --git a/go/vt/mysqlctl/fakemysqldaemon/fakemysqldaemon.go b/go/vt/mysqlctl/fakemysqldaemon/fakemysqldaemon.go index 41430b7657a..72ba70face4 100644 --- a/go/vt/mysqlctl/fakemysqldaemon/fakemysqldaemon.go +++ b/go/vt/mysqlctl/fakemysqldaemon/fakemysqldaemon.go @@ -190,7 +190,7 @@ func (fmd *FakeMysqlDaemon) ReinitConfig(ctx context.Context) error { } // RefreshConfig is part of the MysqlDaemon interface -func (fmd *FakeMysqlDaemon) RefreshConfig() error { +func (fmd *FakeMysqlDaemon) RefreshConfig(ctx context.Context) error { return nil } diff --git a/go/vt/mysqlctl/grpcmysqlctlclient/client.go b/go/vt/mysqlctl/grpcmysqlctlclient/client.go index 09e54093df0..3db377ae0ef 100644 --- a/go/vt/mysqlctl/grpcmysqlctlclient/client.go +++ b/go/vt/mysqlctl/grpcmysqlctlclient/client.go @@ -91,6 +91,14 @@ func (c *client) ReinitConfig(ctx context.Context) error { }) } +// RefreshConfig is part of the MysqlctlClient interface. +func (c *client) RefreshConfig(ctx context.Context) error { + return c.withRetry(ctx, func() error { + _, err := c.c.RefreshConfig(ctx, &mysqlctlpb.RefreshConfigRequest{}) + return err + }) +} + // Close is part of the MysqlctlClient interface. func (c *client) Close() { c.cc.Close() diff --git a/go/vt/mysqlctl/grpcmysqlctlserver/server.go b/go/vt/mysqlctl/grpcmysqlctlserver/server.go index a5898a03e73..1948cc59480 100644 --- a/go/vt/mysqlctl/grpcmysqlctlserver/server.go +++ b/go/vt/mysqlctl/grpcmysqlctlserver/server.go @@ -54,6 +54,11 @@ func (s *server) ReinitConfig(ctx context.Context, request *mysqlctlpb.ReinitCon return &mysqlctlpb.ReinitConfigResponse{}, s.mysqld.ReinitConfig(ctx) } +// RefreshConfig implements the server side of the MysqlctlClient interface. +func (s *server) RefreshConfig(ctx context.Context, request *mysqlctlpb.RefreshConfigRequest) (*mysqlctlpb.RefreshConfigResponse, error) { + return &mysqlctlpb.RefreshConfigResponse{}, s.mysqld.RefreshConfig(ctx) +} + // StartServer registers the Server for RPCs. func StartServer(s *grpc.Server, mysqld *mysqlctl.Mysqld) { mysqlctlpb.RegisterMysqlCtlServer(s, &server{mysqld}) diff --git a/go/vt/mysqlctl/mysql_daemon.go b/go/vt/mysqlctl/mysql_daemon.go index a08f20df9f5..8c9bcde062c 100644 --- a/go/vt/mysqlctl/mysql_daemon.go +++ b/go/vt/mysqlctl/mysql_daemon.go @@ -39,7 +39,7 @@ type MysqlDaemon interface { Shutdown(ctx context.Context, waitForMysqld bool) error RunMysqlUpgrade() error ReinitConfig(ctx context.Context) error - RefreshConfig() error + RefreshConfig(ctx context.Context) error Wait(ctx context.Context) error // GetMysqlPort returns the current port mysql is listening on. diff --git a/go/vt/mysqlctl/mysqlctlclient/interface.go b/go/vt/mysqlctl/mysqlctlclient/interface.go index 5a0c8d27ffe..eb24e5c9757 100644 --- a/go/vt/mysqlctl/mysqlctlclient/interface.go +++ b/go/vt/mysqlctl/mysqlctlclient/interface.go @@ -42,6 +42,9 @@ type MysqlctlClient interface { // ReinitConfig calls Mysqld.ReinitConfig remotely. ReinitConfig(ctx context.Context) error + // RefreshConfig calls Mysqld.RefreshConfig remotely. + RefreshConfig(ctx context.Context) error + // Close will terminate the connection. This object won't be used anymore. Close() } diff --git a/go/vt/mysqlctl/mysqld.go b/go/vt/mysqlctl/mysqld.go index 081eda91d07..fcd219a04d6 100644 --- a/go/vt/mysqlctl/mysqld.go +++ b/go/vt/mysqlctl/mysqld.go @@ -637,7 +637,18 @@ func getMycnfTemplates(root string) []string { // RefreshConfig attempts to recreate the my.cnf from templates, and log and // swap in to place if it's updated. It keeps a copy of the last version in case fallback is required. // Should be called from a stable replica, server_id is not regenerated. -func (mysqld *Mysqld) RefreshConfig() error { +func (mysqld *Mysqld) RefreshConfig(ctx context.Context) error { + // Execute as remote action on mysqlctld if requested. + if *socketFile != "" { + log.Infof("executing Mysqld.RefreshConfig() remotely via mysqlctld server: %v", *socketFile) + client, err := mysqlctlclient.New("unix", *socketFile) + if err != nil { + return fmt.Errorf("can't dial mysqlctld: %v", err) + } + defer client.Close() + return client.RefreshConfig(ctx) + } + log.Info("Checking for updates to my.cnf") root, err := vtenv.VtRoot() if err != nil { diff --git a/go/vt/proto/mysqlctl/mysqlctl.pb.go b/go/vt/proto/mysqlctl/mysqlctl.pb.go index b1a19793625..c96a2f9926d 100644 --- a/go/vt/proto/mysqlctl/mysqlctl.pb.go +++ b/go/vt/proto/mysqlctl/mysqlctl.pb.go @@ -16,6 +16,8 @@ It has these top-level messages: RunMysqlUpgradeResponse ReinitConfigRequest ReinitConfigResponse + RefreshConfigRequest + RefreshConfigResponse */ package mysqlctl @@ -119,6 +121,22 @@ func (m *ReinitConfigResponse) String() string { return proto.Compact func (*ReinitConfigResponse) ProtoMessage() {} func (*ReinitConfigResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} } +type RefreshConfigRequest struct { +} + +func (m *RefreshConfigRequest) Reset() { *m = RefreshConfigRequest{} } +func (m *RefreshConfigRequest) String() string { return proto.CompactTextString(m) } +func (*RefreshConfigRequest) ProtoMessage() {} +func (*RefreshConfigRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} } + +type RefreshConfigResponse struct { +} + +func (m *RefreshConfigResponse) Reset() { *m = RefreshConfigResponse{} } +func (m *RefreshConfigResponse) String() string { return proto.CompactTextString(m) } +func (*RefreshConfigResponse) ProtoMessage() {} +func (*RefreshConfigResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{9} } + func init() { proto.RegisterType((*StartRequest)(nil), "mysqlctl.StartRequest") proto.RegisterType((*StartResponse)(nil), "mysqlctl.StartResponse") @@ -128,6 +146,8 @@ func init() { proto.RegisterType((*RunMysqlUpgradeResponse)(nil), "mysqlctl.RunMysqlUpgradeResponse") proto.RegisterType((*ReinitConfigRequest)(nil), "mysqlctl.ReinitConfigRequest") proto.RegisterType((*ReinitConfigResponse)(nil), "mysqlctl.ReinitConfigResponse") + proto.RegisterType((*RefreshConfigRequest)(nil), "mysqlctl.RefreshConfigRequest") + proto.RegisterType((*RefreshConfigResponse)(nil), "mysqlctl.RefreshConfigResponse") } // Reference imports to suppress errors if they are not otherwise used. @@ -145,6 +165,7 @@ type MysqlCtlClient interface { Shutdown(ctx context.Context, in *ShutdownRequest, opts ...grpc.CallOption) (*ShutdownResponse, error) RunMysqlUpgrade(ctx context.Context, in *RunMysqlUpgradeRequest, opts ...grpc.CallOption) (*RunMysqlUpgradeResponse, error) ReinitConfig(ctx context.Context, in *ReinitConfigRequest, opts ...grpc.CallOption) (*ReinitConfigResponse, error) + RefreshConfig(ctx context.Context, in *RefreshConfigRequest, opts ...grpc.CallOption) (*RefreshConfigResponse, error) } type mysqlCtlClient struct { @@ -191,6 +212,15 @@ func (c *mysqlCtlClient) ReinitConfig(ctx context.Context, in *ReinitConfigReque return out, nil } +func (c *mysqlCtlClient) RefreshConfig(ctx context.Context, in *RefreshConfigRequest, opts ...grpc.CallOption) (*RefreshConfigResponse, error) { + out := new(RefreshConfigResponse) + err := grpc.Invoke(ctx, "/mysqlctl.MysqlCtl/RefreshConfig", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for MysqlCtl service type MysqlCtlServer interface { @@ -198,6 +228,7 @@ type MysqlCtlServer interface { Shutdown(context.Context, *ShutdownRequest) (*ShutdownResponse, error) RunMysqlUpgrade(context.Context, *RunMysqlUpgradeRequest) (*RunMysqlUpgradeResponse, error) ReinitConfig(context.Context, *ReinitConfigRequest) (*ReinitConfigResponse, error) + RefreshConfig(context.Context, *RefreshConfigRequest) (*RefreshConfigResponse, error) } func RegisterMysqlCtlServer(s *grpc.Server, srv MysqlCtlServer) { @@ -276,6 +307,24 @@ func _MysqlCtl_ReinitConfig_Handler(srv interface{}, ctx context.Context, dec fu return interceptor(ctx, in, info, handler) } +func _MysqlCtl_RefreshConfig_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RefreshConfigRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MysqlCtlServer).RefreshConfig(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/mysqlctl.MysqlCtl/RefreshConfig", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MysqlCtlServer).RefreshConfig(ctx, req.(*RefreshConfigRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _MysqlCtl_serviceDesc = grpc.ServiceDesc{ ServiceName: "mysqlctl.MysqlCtl", HandlerType: (*MysqlCtlServer)(nil), @@ -296,6 +345,10 @@ var _MysqlCtl_serviceDesc = grpc.ServiceDesc{ MethodName: "ReinitConfig", Handler: _MysqlCtl_ReinitConfig_Handler, }, + { + MethodName: "RefreshConfig", + Handler: _MysqlCtl_RefreshConfig_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "mysqlctl.proto", @@ -304,24 +357,25 @@ var _MysqlCtl_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("mysqlctl.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 289 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xc1, 0x4b, 0xfb, 0x30, - 0x1c, 0xc5, 0x7f, 0xfd, 0x89, 0x52, 0xbf, 0x6e, 0x56, 0xa2, 0x76, 0x5d, 0x41, 0xad, 0x39, 0xc8, - 0x4e, 0x13, 0xf4, 0xa4, 0x37, 0x29, 0x78, 0x13, 0x21, 0x43, 0xf0, 0x56, 0xaa, 0xcd, 0x6a, 0xa1, - 0x26, 0x5d, 0x92, 0x32, 0xfc, 0xc7, 0xfc, 0xfb, 0xc4, 0x34, 0xe9, 0x3a, 0x3b, 0x3d, 0xf6, 0x7d, - 0xdf, 0xfb, 0x94, 0xf7, 0x08, 0xec, 0xbf, 0x7f, 0xc8, 0x45, 0xf9, 0xaa, 0xca, 0x69, 0x25, 0xb8, - 0xe2, 0xc8, 0xb5, 0xdf, 0xf8, 0x12, 0x06, 0x33, 0x95, 0x0a, 0x45, 0xe8, 0xa2, 0xa6, 0x52, 0xa1, - 0x33, 0xd8, 0xd3, 0xb7, 0x2c, 0x49, 0x45, 0x2e, 0x03, 0x27, 0xda, 0x9a, 0xec, 0x12, 0x68, 0xa4, - 0x3b, 0x91, 0x4b, 0xec, 0xc1, 0xd0, 0x04, 0x64, 0xc5, 0x99, 0xa4, 0xf8, 0x06, 0xbc, 0xd9, 0x5b, - 0xad, 0x32, 0xbe, 0x64, 0x16, 0x72, 0x01, 0xde, 0x32, 0x2d, 0x54, 0x32, 0xe7, 0x22, 0x69, 0xa2, - 0x81, 0x13, 0x39, 0x13, 0x97, 0x0c, 0xbf, 0xe5, 0x7b, 0x2e, 0x1e, 0xb4, 0x88, 0x11, 0x1c, 0xac, - 0xa2, 0x06, 0x17, 0x80, 0x4f, 0x6a, 0xa6, 0x0d, 0x4f, 0x55, 0x2e, 0xd2, 0x8c, 0x1a, 0x2a, 0x1e, - 0xc3, 0xa8, 0x77, 0x31, 0xa1, 0x63, 0x38, 0x24, 0xb4, 0x60, 0x85, 0x8a, 0x39, 0x9b, 0x17, 0xb9, - 0x4d, 0xf8, 0x70, 0xb4, 0x2e, 0x37, 0xf6, 0xab, 0xcf, 0xff, 0xe0, 0x6a, 0x4e, 0xac, 0x4a, 0x74, - 0x0b, 0xdb, 0xba, 0x10, 0xf2, 0xa7, 0xed, 0x4a, 0xdd, 0x49, 0xc2, 0x51, 0x4f, 0x37, 0x7f, 0xfd, - 0x87, 0x62, 0x70, 0x6d, 0x01, 0x34, 0xee, 0xd8, 0xd6, 0xf7, 0x08, 0xc3, 0x4d, 0xa7, 0x16, 0xf2, - 0x0c, 0xde, 0x8f, 0x5e, 0x28, 0x5a, 0x05, 0x36, 0x8f, 0x11, 0x9e, 0xff, 0xe1, 0x68, 0xc9, 0x8f, - 0x30, 0xe8, 0xf6, 0x47, 0x27, 0x9d, 0x50, 0x7f, 0xae, 0xf0, 0xf4, 0xb7, 0xb3, 0x05, 0xbe, 0xec, - 0xe8, 0xe7, 0x73, 0xfd, 0x15, 0x00, 0x00, 0xff, 0xff, 0xb9, 0x5e, 0x84, 0xed, 0x50, 0x02, 0x00, - 0x00, + // 313 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0x4d, 0x4f, 0x83, 0x30, + 0x18, 0xc7, 0x5d, 0x16, 0x0d, 0x3e, 0x6e, 0x62, 0xaa, 0x1b, 0xac, 0x89, 0x0e, 0x39, 0x98, 0x9d, + 0x66, 0xa2, 0x27, 0xbd, 0x19, 0x12, 0x6f, 0xc6, 0xa4, 0x8b, 0x89, 0x37, 0x82, 0x52, 0x18, 0x09, + 0x52, 0xd6, 0x96, 0x2c, 0x7e, 0x05, 0x3f, 0xb5, 0xb1, 0x14, 0x06, 0x63, 0xf3, 0xc8, 0xff, 0xed,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0x8c, 0x77, 0x59, 0xf5, 0xc8, 0x3b, 0x98, 0x5b, 0x20, 0x90, 0xb3, + 0x29, 0xec, 0xa6, 0x87, 0xaf, 0xff, 0x49, 0xd4, 0xcb, 0xaf, 0x30, 0x68, 0x02, 0x43, 0x97, 0x8d, + 0x52, 0x97, 0x2f, 0xbe, 0xda, 0x67, 0xd7, 0x83, 0x04, 0x86, 0x2d, 0xa2, 0xa8, 0x55, 0xe9, 0x7e, + 0x02, 0x3c, 0xdd, 0xeb, 0x57, 0x9b, 0x1f, 0x47, 0xea, 0x1f, 0xbe, 0xff, 0x0d, 0x00, 0x00, 0xff, + 0xff, 0x81, 0x96, 0x68, 0x13, 0xd5, 0x02, 0x00, 0x00, } diff --git a/proto/mysqlctl.proto b/proto/mysqlctl.proto index f0410373bad..eecce332897 100644 --- a/proto/mysqlctl.proto +++ b/proto/mysqlctl.proto @@ -41,10 +41,15 @@ message ReinitConfigRequest{} message ReinitConfigResponse{} +message RefreshConfigRequest{} + +message RefreshConfigResponse{} + // MysqlCtl is the service definition service MysqlCtl { rpc Start(StartRequest) returns (StartResponse) {}; rpc Shutdown(ShutdownRequest) returns (ShutdownResponse) {}; rpc RunMysqlUpgrade(RunMysqlUpgradeRequest) returns (RunMysqlUpgradeResponse) {}; rpc ReinitConfig(ReinitConfigRequest) returns (ReinitConfigResponse) {}; + rpc RefreshConfig(RefreshConfigRequest) returns (RefreshConfigResponse) {}; } diff --git a/test/tablet.py b/test/tablet.py index f064298c7ff..5b06a4db2e5 100644 --- a/test/tablet.py +++ b/test/tablet.py @@ -571,11 +571,15 @@ def start_vttablet( # When vttablet restores from backup, it will re-generate the .cnf file. # So we need to have EXTRA_MY_CNF set properly. - all_extra_my_cnf = get_all_extra_my_cnf(None) - if all_extra_my_cnf: - if not extra_env: - extra_env = {} - extra_env['EXTRA_MY_CNF'] = ':'.join(all_extra_my_cnf) + # When using mysqlctld, only mysqlctld should need EXTRA_MY_CNF. + # If any test fails without giving EXTRA_MY_CNF to vttablet, + # it means we missed some call that should run remotely on mysqlctld. + if not self.use_mysqlctld: + all_extra_my_cnf = get_all_extra_my_cnf(None) + if all_extra_my_cnf: + if not extra_env: + extra_env = {} + extra_env['EXTRA_MY_CNF'] = ':'.join(all_extra_my_cnf) if extra_args: args.extend(extra_args)