Skip to content

Commit

Permalink
mcs: Refactor ServicePath to make caller's life easier (#6799)
Browse files Browse the repository at this point in the history
close #6800

Signed-off-by: Xiaoguang Sun <sunxiaoguang@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
sunxiaoguang and ti-chi-bot[bot] authored Jul 14, 2023
1 parent 42ce6a1 commit a621fcb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/mcs/discovery/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

// Discover is used to get all the service instances of the specified service name.
func Discover(cli *clientv3.Client, clusterID, serviceName string) ([]string, error) {
key := ServicePath(clusterID, serviceName) + "/"
key := ServicePath(clusterID, serviceName)
endKey := clientv3.GetPrefixRangeEnd(key)

withRange := clientv3.WithRange(endKey)
Expand Down
4 changes: 2 additions & 2 deletions pkg/mcs/discovery/key_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func RegistryPath(clusterID, serviceName, serviceAddr string) string {

// ServicePath returns the path to store microservice addresses.
func ServicePath(clusterID, serviceName string) string {
return strings.Join([]string{utils.MicroserviceRootPath, clusterID, serviceName, registryKey}, "/")
return strings.Join([]string{utils.MicroserviceRootPath, clusterID, serviceName, registryKey, ""}, "/")
}

// TSOPath returns the path to store TSO addresses.
func TSOPath(clusterID uint64) string {
return ServicePath(strconv.FormatUint(clusterID, 10), "tso") + "/"
return ServicePath(strconv.FormatUint(clusterID, 10), "tso")
}
4 changes: 2 additions & 2 deletions pkg/tso/keyspace_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (suite *keyspaceGroupManagerTestSuite) TestNewKeyspaceGroupManager() {

tsoServiceID := &discovery.ServiceRegistryEntry{ServiceAddr: suite.cfg.AdvertiseListenAddr}
guid := uuid.New().String()
tsoServiceKey := discovery.ServicePath(guid, "tso") + "/"
tsoServiceKey := discovery.ServicePath(guid, "tso")
legacySvcRootPath := path.Join("/pd", guid)
tsoSvcRootPath := path.Join(mcsutils.MicroserviceRootPath, guid, "tso")
electionNamePrefix := "tso-server-" + guid
Expand Down Expand Up @@ -817,7 +817,7 @@ func (suite *keyspaceGroupManagerTestSuite) newKeyspaceGroupManager(
cfg *TestServiceConfig,
) *KeyspaceGroupManager {
tsoServiceID := &discovery.ServiceRegistryEntry{ServiceAddr: cfg.GetAdvertiseListenAddr()}
tsoServiceKey := discovery.ServicePath(uniqueStr, "tso") + "/"
tsoServiceKey := discovery.ServicePath(uniqueStr, "tso")
legacySvcRootPath := path.Join("/pd", uniqueStr)
tsoSvcRootPath := path.Join(mcsutils.MicroserviceRootPath, uniqueStr, "tso")
electionNamePrefix := "kgm-test-" + cfg.GetAdvertiseListenAddr()
Expand Down

0 comments on commit a621fcb

Please sign in to comment.