Skip to content

Commit

Permalink
add pdms name
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Jul 31, 2024
1 parent 9af28fc commit cc0f049
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions pkg/mcs/discovery/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
3 changes: 3 additions & 0 deletions pkg/mcs/discovery/registry_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions pkg/mcs/resourcemanager/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion pkg/mcs/resourcemanager/server/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions pkg/mcs/scheduling/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions pkg/mcs/scheduling/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/mcs/tso/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions pkg/mcs/tso/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions pkg/mcs/tso/server/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions tests/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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.
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit cc0f049

Please sign in to comment.