Skip to content

Commit

Permalink
replace more
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Nov 12, 2024
1 parent e252d4c commit e7daf0e
Show file tree
Hide file tree
Showing 24 changed files with 101 additions and 101 deletions.
20 changes: 10 additions & 10 deletions cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
)

const (
apiMode = "api"
keyspaceMode = "api"
tsoMode = "tso"
rmMode = "resource-manager"
serviceModeEnv = "PD_SERVICE_MODE"
Expand Down Expand Up @@ -83,7 +83,7 @@ func NewServiceCommand() *cobra.Command {
cmd.AddCommand(NewTSOServiceCommand())
cmd.AddCommand(NewResourceManagerServiceCommand())
cmd.AddCommand(NewSchedulingServiceCommand())
cmd.AddCommand(NewAPIServiceCommand())
cmd.AddCommand(NewPDWithKeyspaceCommand())
return cmd
}

Expand Down Expand Up @@ -150,12 +150,12 @@ func NewResourceManagerServiceCommand() *cobra.Command {
return cmd
}

// NewAPIServiceCommand returns the API service command.
func NewAPIServiceCommand() *cobra.Command {
// NewPDWithKeyspaceCommand returns the PD with keyspace command.
func NewPDWithKeyspaceCommand() *cobra.Command {
cmd := &cobra.Command{
Use: apiMode,
Short: "Run the API service",
Run: createAPIServerWrapper,
Use: keyspaceMode,
Short: "Placement Driver server with keyspace",
Run: createServerWrapperWithKeyspace,
}
addFlags(cmd)
return cmd
Expand All @@ -182,14 +182,14 @@ func addFlags(cmd *cobra.Command) {
cmd.Flags().BoolP("force-new-cluster", "", false, "force to create a new one-member cluster")
}

func createAPIServerWrapper(cmd *cobra.Command, args []string) {
func createServerWrapperWithKeyspace(cmd *cobra.Command, args []string) {
start(cmd, args, cmd.CalledAs())
}

func createServerWrapper(cmd *cobra.Command, args []string) {
mode := os.Getenv(serviceModeEnv)
if len(mode) != 0 && strings.ToLower(mode) == apiMode {
start(cmd, args, apiMode)
if len(mode) != 0 && strings.ToLower(mode) == keyspaceMode {
start(cmd, args, keyspaceMode)
} else {
start(cmd, args)
}
Expand Down
26 changes: 13 additions & 13 deletions tests/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func NewTestServer(ctx context.Context, cfg *config.Config) (*TestServer, error)
return createTestServer(ctx, cfg, nil)
}

// NewTestAPIServer creates a new TestServer.
func NewTestAPIServer(ctx context.Context, cfg *config.Config) (*TestServer, error) {
// NewTestServerWithKeyspace creates a new TestServer.
func NewTestServerWithKeyspace(ctx context.Context, cfg *config.Config) (*TestServer, error) {
return createTestServer(ctx, cfg, []string{constant.APIServiceName})
}

Expand Down Expand Up @@ -471,12 +471,12 @@ func NewTestCluster(ctx context.Context, initialServerCount int, opts ...ConfigO
return createTestCluster(ctx, initialServerCount, false, opts...)
}

// NewTestAPICluster creates a new TestCluster with API service.
func NewTestAPICluster(ctx context.Context, initialServerCount int, opts ...ConfigOption) (*TestCluster, error) {
// NewTestClusterWithKeyspace creates a new TestCluster with keyspace.
func NewTestClusterWithKeyspace(ctx context.Context, initialServerCount int, opts ...ConfigOption) (*TestCluster, error) {
return createTestCluster(ctx, initialServerCount, true, opts...)
}

func createTestCluster(ctx context.Context, initialServerCount int, isAPIServiceMode bool, opts ...ConfigOption) (*TestCluster, error) {
func createTestCluster(ctx context.Context, initialServerCount int, isKeyspaceEnabled bool, opts ...ConfigOption) (*TestCluster, error) {
schedulers.Register()
config := newClusterConfig(initialServerCount)
servers := make(map[string]*TestServer)
Expand All @@ -486,8 +486,8 @@ func createTestCluster(ctx context.Context, initialServerCount int, isAPIService
return nil, err
}
var s *TestServer
if isAPIServiceMode {
s, err = NewTestAPIServer(ctx, serverConf)
if isKeyspaceEnabled {
s, err = NewTestServerWithKeyspace(ctx, serverConf)
} else {
s, err = NewTestServer(ctx, serverConf)
}
Expand All @@ -514,7 +514,7 @@ func RestartTestAPICluster(ctx context.Context, cluster *TestCluster) (*TestClus
}

func restartTestCluster(
ctx context.Context, cluster *TestCluster, isAPIServiceMode bool,
ctx context.Context, cluster *TestCluster, isKeyspaceEnabled bool,
) (newTestCluster *TestCluster, err error) {
schedulers.Register()
newTestCluster = &TestCluster{
Expand All @@ -541,8 +541,8 @@ func restartTestCluster(
newServer *TestServer
serverErr error
)
if isAPIServiceMode {
newServer, serverErr = NewTestAPIServer(ctx, serverCfg)
if isKeyspaceEnabled {
newServer, serverErr = NewTestServerWithKeyspace(ctx, serverCfg)
} else {
newServer, serverErr = NewTestServer(ctx, serverCfg)
}
Expand Down Expand Up @@ -826,13 +826,13 @@ func (c *TestCluster) Join(ctx context.Context, opts ...ConfigOption) (*TestServ
return s, nil
}

// JoinAPIServer is used to add a new TestAPIServer into the cluster.
func (c *TestCluster) JoinAPIServer(ctx context.Context, opts ...ConfigOption) (*TestServer, error) {
// JoinServerWithKeyspace is used to add a new TestServerWithKeyspace into the cluster.
func (c *TestCluster) JoinServerWithKeyspace(ctx context.Context, opts ...ConfigOption) (*TestServer, error) {
conf, err := c.config.join().Generate(opts...)
if err != nil {
return nil, err
}
s, err := NewTestAPIServer(ctx, conf)
s, err := NewTestServerWithKeyspace(ctx, conf)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func TestTSOFollowerProxyWithTSOService(t *testing.T) {
re.NoError(failpoint.Enable("github.com/tikv/pd/client/fastUpdateServiceMode", `return(true)`))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := tests.NewTestAPICluster(ctx, 1)
cluster, err := tests.NewTestClusterWithKeyspace(ctx, 1)
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/discovery/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (suite *serverRegisterTestSuite) SetupSuite() {
re := suite.Require()

suite.ctx, suite.cancel = context.WithCancel(context.Background())
suite.cluster, err = tests.NewTestAPICluster(suite.ctx, 1)
suite.cluster, err = tests.NewTestClusterWithKeyspace(suite.ctx, 1)
re.NoError(err)

err = suite.cluster.RunInitialServers()
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/keyspace/tso_keyspace_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (suite *keyspaceGroupTestSuite) SetupTest() {
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/keyspace/acceleratedAllocNodes", `return(true)`))
ctx, cancel := context.WithCancel(context.Background())
suite.ctx = ctx
cluster, err := tests.NewTestAPICluster(suite.ctx, 1)
cluster, err := tests.NewTestClusterWithKeyspace(suite.ctx, 1)
suite.cluster = cluster
re.NoError(err)
re.NoError(cluster.RunInitialServers())
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/members/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (suite *memberTestSuite) SetupTest() {
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/keyspace/acceleratedAllocNodes", `return(true)`))
ctx, cancel := context.WithCancel(context.Background())
suite.ctx = ctx
cluster, err := tests.NewTestAPICluster(suite.ctx, 1)
cluster, err := tests.NewTestClusterWithKeyspace(suite.ctx, 1)
suite.cluster = cluster
re.NoError(err)
re.NoError(cluster.RunInitialServers())
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/resourcemanager/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestResourceManagerServer(t *testing.T) {

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := tests.NewTestAPICluster(ctx, 1)
cluster, err := tests.NewTestClusterWithKeyspace(ctx, 1)
defer cluster.Destroy()
re.NoError(err)

Expand Down
22 changes: 11 additions & 11 deletions tests/integrations/mcs/scheduling/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (suite *apiTestSuite) TearDownSuite() {
}

func (suite *apiTestSuite) TestGetCheckerByName() {
suite.env.RunTestInAPIMode(suite.checkGetCheckerByName)
suite.env.RunTestInKeyspaceMode(suite.checkGetCheckerByName)
}

func (suite *apiTestSuite) checkGetCheckerByName(cluster *tests.TestCluster) {
Expand Down Expand Up @@ -99,7 +99,7 @@ func (suite *apiTestSuite) checkGetCheckerByName(cluster *tests.TestCluster) {
}

func (suite *apiTestSuite) TestAPIForward() {
suite.env.RunTestInAPIMode(suite.checkAPIForward)
suite.env.RunTestInKeyspaceMode(suite.checkAPIForward)
}

func (suite *apiTestSuite) checkAPIForward(cluster *tests.TestCluster) {
Expand Down Expand Up @@ -375,7 +375,7 @@ func (suite *apiTestSuite) checkAPIForward(cluster *tests.TestCluster) {
}

func (suite *apiTestSuite) TestConfig() {
suite.env.RunTestInAPIMode(suite.checkConfig)
suite.env.RunTestInKeyspaceMode(suite.checkConfig)
}

func (suite *apiTestSuite) checkConfig(cluster *tests.TestCluster) {
Expand All @@ -398,7 +398,7 @@ func (suite *apiTestSuite) checkConfig(cluster *tests.TestCluster) {
}

func (suite *apiTestSuite) TestConfigForward() {
suite.env.RunTestInAPIMode(suite.checkConfigForward)
suite.env.RunTestInKeyspaceMode(suite.checkConfigForward)
}

func (suite *apiTestSuite) checkConfigForward(cluster *tests.TestCluster) {
Expand Down Expand Up @@ -449,7 +449,7 @@ func (suite *apiTestSuite) checkConfigForward(cluster *tests.TestCluster) {
}

func (suite *apiTestSuite) TestAdminRegionCache() {
suite.env.RunTestInAPIMode(suite.checkAdminRegionCache)
suite.env.RunTestInKeyspaceMode(suite.checkAdminRegionCache)
}

func (suite *apiTestSuite) checkAdminRegionCache(cluster *tests.TestCluster) {
Expand All @@ -476,7 +476,7 @@ func (suite *apiTestSuite) checkAdminRegionCache(cluster *tests.TestCluster) {
}

func (suite *apiTestSuite) TestAdminRegionCacheForward() {
suite.env.RunTestInAPIMode(suite.checkAdminRegionCacheForward)
suite.env.RunTestInKeyspaceMode(suite.checkAdminRegionCacheForward)
}

func (suite *apiTestSuite) checkAdminRegionCacheForward(cluster *tests.TestCluster) {
Expand Down Expand Up @@ -515,7 +515,7 @@ func (suite *apiTestSuite) checkFollowerForward(cluster *tests.TestCluster) {
leaderAddr := cluster.GetLeaderServer().GetAddr()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
follower, err := cluster.JoinAPIServer(ctx)
follower, err := cluster.JoinServerWithKeyspace(ctx)
re.NoError(err)
defer func() {
leader := cluster.GetLeaderServer()
Expand Down Expand Up @@ -567,7 +567,7 @@ func (suite *apiTestSuite) checkFollowerForward(cluster *tests.TestCluster) {
}

func (suite *apiTestSuite) TestMetrics() {
suite.env.RunTestInAPIMode(suite.checkMetrics)
suite.env.RunTestInKeyspaceMode(suite.checkMetrics)
}

func (suite *apiTestSuite) checkMetrics(cluster *tests.TestCluster) {
Expand All @@ -586,7 +586,7 @@ func (suite *apiTestSuite) checkMetrics(cluster *tests.TestCluster) {
}

func (suite *apiTestSuite) TestStatus() {
suite.env.RunTestInAPIMode(suite.checkStatus)
suite.env.RunTestInKeyspaceMode(suite.checkStatus)
}

func (suite *apiTestSuite) checkStatus(cluster *tests.TestCluster) {
Expand All @@ -609,7 +609,7 @@ func (suite *apiTestSuite) checkStatus(cluster *tests.TestCluster) {
}

func (suite *apiTestSuite) TestStores() {
suite.env.RunTestInAPIMode(suite.checkStores)
suite.env.RunTestInKeyspaceMode(suite.checkStores)
}

func (suite *apiTestSuite) checkStores(cluster *tests.TestCluster) {
Expand Down Expand Up @@ -691,7 +691,7 @@ func (suite *apiTestSuite) checkStores(cluster *tests.TestCluster) {
}

func (suite *apiTestSuite) TestRegions() {
suite.env.RunTestInAPIMode(suite.checkRegions)
suite.env.RunTestInKeyspaceMode(suite.checkRegions)
}

func (suite *apiTestSuite) checkRegions(cluster *tests.TestCluster) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/scheduling/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (suite *configTestSuite) SetupSuite() {
schedulers.Register()
var err error
suite.ctx, suite.cancel = context.WithCancel(context.Background())
suite.cluster, err = tests.NewTestAPICluster(suite.ctx, 1)
suite.cluster, err = tests.NewTestClusterWithKeyspace(suite.ctx, 1)
re.NoError(err)
err = suite.cluster.RunInitialServers()
re.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/scheduling/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (suite *metaTestSuite) SetupSuite() {
re.NoError(failpoint.Enable("github.com/tikv/pd/server/cluster/highFrequencyClusterJobs", `return(true)`))
var err error
suite.ctx, suite.cancel = context.WithCancel(context.Background())
suite.cluster, err = tests.NewTestAPICluster(suite.ctx, 1)
suite.cluster, err = tests.NewTestClusterWithKeyspace(suite.ctx, 1)
re.NoError(err)
err = suite.cluster.RunInitialServers()
re.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/scheduling/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (suite *ruleTestSuite) SetupSuite() {

var err error
suite.ctx, suite.cancel = context.WithCancel(context.Background())
suite.cluster, err = tests.NewTestAPICluster(suite.ctx, 1)
suite.cluster, err = tests.NewTestClusterWithKeyspace(suite.ctx, 1)
re.NoError(err)
err = suite.cluster.RunInitialServers()
re.NoError(err)
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/mcs/scheduling/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (suite *serverTestSuite) SetupSuite() {
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/mcs/scheduling/server/changeRunCollectWaitTime", `return(true)`))
re.NoError(failpoint.Enable("github.com/tikv/pd/server/cluster/highFrequencyClusterJobs", `return(true)`))
suite.ctx, suite.cancel = context.WithCancel(context.Background())
suite.cluster, err = tests.NewTestAPICluster(suite.ctx, 1)
suite.cluster, err = tests.NewTestClusterWithKeyspace(suite.ctx, 1)
re.NoError(err)

err = suite.cluster.RunInitialServers()
Expand Down Expand Up @@ -632,7 +632,7 @@ func (suite *multipleServerTestSuite) SetupSuite() {
re := suite.Require()
re.NoError(failpoint.Enable("github.com/tikv/pd/server/cluster/highFrequencyClusterJobs", `return(true)`))
suite.ctx, suite.cancel = context.WithCancel(context.Background())
suite.cluster, err = tests.NewTestAPICluster(suite.ctx, 2)
suite.cluster, err = tests.NewTestClusterWithKeyspace(suite.ctx, 2)
re.NoError(err)

err = suite.cluster.RunInitialServers()
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/mcs/tso/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (suite *tsoAPITestSuite) SetupTest() {

var err error
suite.ctx, suite.cancel = context.WithCancel(context.Background())
suite.pdCluster, err = tests.NewTestAPICluster(suite.ctx, 1)
suite.pdCluster, err = tests.NewTestClusterWithKeyspace(suite.ctx, 1)
re.NoError(err)
err = suite.pdCluster.RunInitialServers()
re.NoError(err)
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestTSOServerStartFirst(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

apiCluster, err := tests.NewTestAPICluster(ctx, 1, func(conf *config.Config, _ string) {
apiCluster, err := tests.NewTestClusterWithKeyspace(ctx, 1, func(conf *config.Config, _ string) {
conf.Keyspace.PreAlloc = []string{"k1", "k2"}
})
defer apiCluster.Destroy()
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestForwardOnlyTSONoScheduling(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
tc, err := tests.NewTestAPICluster(ctx, 1)
tc, err := tests.NewTestClusterWithKeyspace(ctx, 1)
defer tc.Destroy()
re.NoError(err)
err = tc.RunInitialServers()
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/mcs/tso/keyspace_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (suite *tsoKeyspaceGroupManagerTestSuite) SetupSuite() {

var err error
suite.ctx, suite.cancel = context.WithCancel(context.Background())
suite.cluster, err = tests.NewTestAPICluster(suite.ctx, 1)
suite.cluster, err = tests.NewTestClusterWithKeyspace(suite.ctx, 1)
re.NoError(err)
err = suite.cluster.RunInitialServers()
re.NoError(err)
Expand Down Expand Up @@ -534,7 +534,7 @@ func TestTwiceSplitKeyspaceGroup(t *testing.T) {
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/tso/fastGroupSplitPatroller", `return(true)`))

// Init api server config but not start.
tc, err := tests.NewTestAPICluster(ctx, 1, func(conf *config.Config, _ string) {
tc, err := tests.NewTestClusterWithKeyspace(ctx, 1, func(conf *config.Config, _ string) {
conf.Keyspace.PreAlloc = []string{
"keyspace_a", "keyspace_b",
}
Expand Down Expand Up @@ -731,7 +731,7 @@ func TestGetTSOImmediately(t *testing.T) {
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/tso/fastGroupSplitPatroller", `return(true)`))

// Init api server config but not start.
tc, err := tests.NewTestAPICluster(ctx, 1, func(conf *config.Config, _ string) {
tc, err := tests.NewTestClusterWithKeyspace(ctx, 1, func(conf *config.Config, _ string) {
conf.Keyspace.PreAlloc = []string{
"keyspace_a", "keyspace_b",
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/tso/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *tsoProxyTestSuite) SetupSuite() {
var err error
s.ctx, s.cancel = context.WithCancel(context.Background())
// Create an API cluster with 1 server
s.apiCluster, err = tests.NewTestAPICluster(s.ctx, 1)
s.apiCluster, err = tests.NewTestClusterWithKeyspace(s.ctx, 1)
re.NoError(err)
err = s.apiCluster.RunInitialServers()
re.NoError(err)
Expand Down
Loading

0 comments on commit e7daf0e

Please sign in to comment.