diff --git a/cmd/pd-server/main.go b/cmd/pd-server/main.go index 553b93ed0efa..459b18605e9a 100644 --- a/cmd/pd-server/main.go +++ b/cmd/pd-server/main.go @@ -94,6 +94,7 @@ func NewTSOServiceCommand() *cobra.Command { Short: "Run the TSO service", Run: tso.CreateServerWrapper, } + cmd.Flags().StringP("name", "", "", "human-readable name for this tso member") cmd.Flags().BoolP("version", "V", false, "print version information and exit") cmd.Flags().StringP("config", "", "", "config file") cmd.Flags().StringP("backend-endpoints", "", "", "url for etcd client") @@ -114,6 +115,7 @@ func NewSchedulingServiceCommand() *cobra.Command { Short: "Run the scheduling service", Run: scheduling.CreateServerWrapper, } + cmd.Flags().StringP("name", "", "", "human-readable name for this scheduling member") cmd.Flags().BoolP("version", "V", false, "print version information and exit") cmd.Flags().StringP("config", "", "", "config file") cmd.Flags().StringP("backend-endpoints", "", "", "url for etcd client") @@ -134,6 +136,7 @@ func NewResourceManagerServiceCommand() *cobra.Command { Short: "Run the resource manager service", Run: resource_manager.CreateServerWrapper, } + cmd.Flags().StringP("name", "", "", "human-readable name for this resource manager member") cmd.Flags().BoolP("version", "V", false, "print version information and exit") cmd.Flags().StringP("config", "", "", "config file") cmd.Flags().StringP("backend-endpoints", "", "", "url for etcd client") diff --git a/pkg/mcs/discovery/discover.go b/pkg/mcs/discovery/discover.go index 1ce5ecda51dd..3e1d678cffbb 100644 --- a/pkg/mcs/discovery/discover.go +++ b/pkg/mcs/discovery/discover.go @@ -45,14 +45,14 @@ func Discover(cli *clientv3.Client, clusterID, serviceName string) ([]string, er } // GetMSMembers returns all the members of the specified service name. -func GetMSMembers(name string, client *clientv3.Client) ([]ServiceRegistryEntry, error) { - switch name { +func GetMSMembers(serviceName string, client *clientv3.Client) ([]ServiceRegistryEntry, error) { + switch serviceName { case utils.TSOServiceName, utils.SchedulingServiceName, utils.ResourceManagerServiceName: clusterID, err := etcdutil.GetClusterID(client, utils.ClusterIDPath) if err != nil { return nil, err } - servicePath := ServicePath(strconv.FormatUint(clusterID, 10), name) + servicePath := ServicePath(strconv.FormatUint(clusterID, 10), serviceName) resps, err := kv.NewSlowLogTxn(client).Then(clientv3.OpGet(servicePath, clientv3.WithPrefix())).Commit() if err != nil { return nil, errs.ErrEtcdKVGet.Wrap(err).GenWithStackByCause() @@ -75,5 +75,5 @@ func GetMSMembers(name string, client *clientv3.Client) ([]ServiceRegistryEntry, return entries, nil } - return nil, errors.Errorf("unknown service name %s", name) + return nil, errors.Errorf("unknown service name %s", serviceName) } diff --git a/pkg/mcs/discovery/registry_entry.go b/pkg/mcs/discovery/registry_entry.go index bf11ae5c8a40..db4ac44a2ccf 100644 --- a/pkg/mcs/discovery/registry_entry.go +++ b/pkg/mcs/discovery/registry_entry.go @@ -23,6 +23,9 @@ import ( // ServiceRegistryEntry is the registry entry of a service type ServiceRegistryEntry struct { + // The specific value will be assigned only if the startup parameter is added. + // If not assigned, the default value(service-hostname) will be used. + Name string `json:"name"` ServiceAddr string `json:"service-addr"` Version string `json:"version"` GitHash string `json:"git-hash"` diff --git a/pkg/mcs/resourcemanager/server/config.go b/pkg/mcs/resourcemanager/server/config.go index 2ccdfb05cc48..03fc67189268 100644 --- a/pkg/mcs/resourcemanager/server/config.go +++ b/pkg/mcs/resourcemanager/server/config.go @@ -202,6 +202,7 @@ func (c *Config) Parse(flagSet *pflag.FlagSet) error { } // Ignore the error check here + configutil.AdjustCommandLineString(flagSet, &c.Name, "name") configutil.AdjustCommandLineString(flagSet, &c.Log.Level, "log-level") configutil.AdjustCommandLineString(flagSet, &c.Log.File.Filename, "log-file") configutil.AdjustCommandLineString(flagSet, &c.Metric.PushAddress, "metrics-addr") diff --git a/pkg/mcs/resourcemanager/server/testutil.go b/pkg/mcs/resourcemanager/server/testutil.go index 0277e5e8a8f9..3577301258cd 100644 --- a/pkg/mcs/resourcemanager/server/testutil.go +++ b/pkg/mcs/resourcemanager/server/testutil.go @@ -49,16 +49,18 @@ func NewTestServer(ctx context.Context, re *require.Assertions, cfg *Config) (*S // GenerateConfig generates a new config with the given options. func GenerateConfig(c *Config) (*Config, error) { arguments := []string{ + "--name=" + c.Name, "--listen-addr=" + c.ListenAddr, "--advertise-listen-addr=" + c.AdvertiseListenAddr, "--backend-endpoints=" + c.BackendEndpoints, } flagSet := pflag.NewFlagSet("test", pflag.ContinueOnError) + flagSet.StringP("name", "", "", "human-readable name for this resource manager member") flagSet.BoolP("version", "V", false, "print version information and exit") flagSet.StringP("config", "", "", "config file") flagSet.StringP("backend-endpoints", "", "", "url for etcd client") - flagSet.StringP("listen-addr", "", "", "listen address for tso service") + flagSet.StringP("listen-addr", "", "", "listen address for resource manager service") flagSet.StringP("advertise-listen-addr", "", "", "advertise urls for listen address (default '${listen-addr}')") flagSet.StringP("cacert", "", "", "path of file that contains list of trusted TLS CAs") flagSet.StringP("cert", "", "", "path of file that contains X509 certificate in PEM format") diff --git a/pkg/mcs/scheduling/server/config/config.go b/pkg/mcs/scheduling/server/config/config.go index 2111aa3ddcce..b08308ee9e8a 100644 --- a/pkg/mcs/scheduling/server/config/config.go +++ b/pkg/mcs/scheduling/server/config/config.go @@ -104,6 +104,7 @@ func (c *Config) Parse(flagSet *pflag.FlagSet) error { } // Ignore the error check here + configutil.AdjustCommandLineString(flagSet, &c.Name, "name") configutil.AdjustCommandLineString(flagSet, &c.Log.Level, "log-level") configutil.AdjustCommandLineString(flagSet, &c.Log.File.Filename, "log-file") configutil.AdjustCommandLineString(flagSet, &c.Metric.PushAddress, "metrics-addr") diff --git a/pkg/mcs/scheduling/server/server.go b/pkg/mcs/scheduling/server/server.go index 8eb9e49d9646..50936325f458 100644 --- a/pkg/mcs/scheduling/server/server.go +++ b/pkg/mcs/scheduling/server/server.go @@ -427,6 +427,7 @@ func (s *Server) startServer() (err error) { GitHash: versioninfo.PDGitHash, DeployPath: deployPath, StartTimestamp: s.StartTimestamp(), + Name: s.Name(), } uniqueName := s.cfg.GetAdvertiseListenAddr() uniqueID := memberutil.GenerateUniqueID(uniqueName) diff --git a/pkg/mcs/tso/server/config.go b/pkg/mcs/tso/server/config.go index 8cfef98ebaf3..82ac777ad060 100644 --- a/pkg/mcs/tso/server/config.go +++ b/pkg/mcs/tso/server/config.go @@ -167,6 +167,7 @@ func (c *Config) Parse(flagSet *pflag.FlagSet) error { } // Ignore the error check here + configutil.AdjustCommandLineString(flagSet, &c.Name, "name") configutil.AdjustCommandLineString(flagSet, &c.Log.Level, "log-level") configutil.AdjustCommandLineString(flagSet, &c.Log.File.Filename, "log-file") configutil.AdjustCommandLineString(flagSet, &c.Metric.PushAddress, "metrics-addr") diff --git a/pkg/mcs/tso/server/server.go b/pkg/mcs/tso/server/server.go index 60ce2917ed5c..a120cbc9868e 100644 --- a/pkg/mcs/tso/server/server.go +++ b/pkg/mcs/tso/server/server.go @@ -382,6 +382,7 @@ func (s *Server) startServer() (err error) { GitHash: versioninfo.PDGitHash, DeployPath: deployPath, StartTimestamp: s.StartTimestamp(), + Name: s.Name(), } s.keyspaceGroupManager = tso.NewKeyspaceGroupManager( s.serverLoopCtx, s.serviceID, s.GetClient(), s.GetHTTPClient(), s.cfg.AdvertiseListenAddr, diff --git a/pkg/mcs/tso/server/testutil.go b/pkg/mcs/tso/server/testutil.go index cf5d45e7754a..5dcfd4759b96 100644 --- a/pkg/mcs/tso/server/testutil.go +++ b/pkg/mcs/tso/server/testutil.go @@ -34,12 +34,14 @@ func MustNewGrpcClient(re *require.Assertions, addr string) (*grpc.ClientConn, t // GenerateConfig generates a new config with the given options. func GenerateConfig(c *Config) (*Config, error) { arguments := []string{ + "--name=" + c.Name, "--listen-addr=" + c.ListenAddr, "--advertise-listen-addr=" + c.AdvertiseListenAddr, "--backend-endpoints=" + c.BackendEndpoints, } flagSet := pflag.NewFlagSet("test", pflag.ContinueOnError) + flagSet.StringP("name", "", "", "human-readable name for this tso member") flagSet.BoolP("version", "V", false, "print version information and exit") flagSet.StringP("config", "", "", "config file") flagSet.StringP("backend-endpoints", "", "", "url for etcd client") diff --git a/tests/testutil.go b/tests/testutil.go index 2fc87298d074..c895d206c05f 100644 --- a/tests/testutil.go +++ b/tests/testutil.go @@ -110,6 +110,7 @@ func StartSingleResourceManagerTestServer(ctx context.Context, re *require.Asser cfg := rm.NewConfig() cfg.BackendEndpoints = backendEndpoints cfg.ListenAddr = listenAddrs + cfg.Name = cfg.ListenAddr cfg, err := rm.GenerateConfig(cfg) re.NoError(err) @@ -127,6 +128,7 @@ func StartSingleTSOTestServerWithoutCheck(ctx context.Context, re *require.Asser cfg := tso.NewConfig() cfg.BackendEndpoints = backendEndpoints cfg.ListenAddr = listenAddrs + cfg.Name = cfg.ListenAddr cfg, err := tso.GenerateConfig(cfg) re.NoError(err) // Setup the logger. @@ -164,6 +166,7 @@ func StartSingleSchedulingTestServer(ctx context.Context, re *require.Assertions cfg := sc.NewConfig() cfg.BackendEndpoints = backendEndpoints cfg.ListenAddr = listenAddrs + cfg.Name = cfg.ListenAddr cfg, err := scheduling.GenerateConfig(cfg) re.NoError(err)