diff --git a/client/client.go b/client/client.go index ecb228a10ec..ecb4b134263 100644 --- a/client/client.go +++ b/client/client.go @@ -35,7 +35,7 @@ import ( "github.com/tikv/pd/client/clients/metastorage" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/opt" - "github.com/tikv/pd/client/sd" + sd "github.com/tikv/pd/client/servicediscovery" "github.com/tikv/pd/client/utils" "github.com/tikv/pd/client/utils/tlsutil" "go.uber.org/zap" diff --git a/client/http/client.go b/client/http/client.go index 8c24efce0f2..9c522d87286 100644 --- a/client/http/client.go +++ b/client/http/client.go @@ -28,7 +28,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/retry" - "github.com/tikv/pd/client/sd" + sd "github.com/tikv/pd/client/servicediscovery" "go.uber.org/zap" ) diff --git a/client/inner_client.go b/client/inner_client.go index 2d81d469afd..279d8d1383b 100644 --- a/client/inner_client.go +++ b/client/inner_client.go @@ -11,7 +11,7 @@ import ( "github.com/pingcap/log" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/opt" - "github.com/tikv/pd/client/sd" + sd "github.com/tikv/pd/client/servicediscovery" "go.uber.org/zap" "google.golang.org/grpc" ) diff --git a/client/sd/mock_pd_service_discovery.go b/client/servicediscovery/mock_pd_service_discovery.go similarity index 99% rename from client/sd/mock_pd_service_discovery.go rename to client/servicediscovery/mock_pd_service_discovery.go index 41fb5235649..87b74ae2136 100644 --- a/client/sd/mock_pd_service_discovery.go +++ b/client/servicediscovery/mock_pd_service_discovery.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package sd +package servicediscovery import ( "crypto/tls" diff --git a/client/sd/pd_service_discovery.go b/client/servicediscovery/pd_service_discovery.go similarity index 99% rename from client/sd/pd_service_discovery.go rename to client/servicediscovery/pd_service_discovery.go index c01442c16c7..879f838bf5e 100644 --- a/client/sd/pd_service_discovery.go +++ b/client/servicediscovery/pd_service_discovery.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package sd +package servicediscovery import ( "context" diff --git a/client/sd/pd_service_discovery_test.go b/client/servicediscovery/pd_service_discovery_test.go similarity index 97% rename from client/sd/pd_service_discovery_test.go rename to client/servicediscovery/pd_service_discovery_test.go index d7bd42d48d9..45faf2aa7f1 100644 --- a/client/sd/pd_service_discovery_test.go +++ b/client/servicediscovery/pd_service_discovery_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package sd +package servicediscovery import ( "context" @@ -190,12 +190,12 @@ func (suite *serviceClientTestSuite) TestServiceClient() { re.False(follower.IsConnectedToLeader()) re.True(leader.IsConnectedToLeader()) - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/unreachableNetwork1", "return(true)")) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/unreachableNetwork1", "return(true)")) follower.(*pdServiceClient).checkNetworkAvailable(suite.ctx) leader.(*pdServiceClient).checkNetworkAvailable(suite.ctx) re.False(follower.Available()) re.False(leader.Available()) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/unreachableNetwork1")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/unreachableNetwork1")) follower.(*pdServiceClient).checkNetworkAvailable(suite.ctx) leader.(*pdServiceClient).checkNetworkAvailable(suite.ctx) @@ -237,7 +237,7 @@ func (suite *serviceClientTestSuite) TestServiceClient() { followerAPIClient := newPDServiceAPIClient(follower, regionAPIErrorFn) leaderAPIClient := newPDServiceAPIClient(leader, regionAPIErrorFn) - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/fastCheckAvailable", "return(true)")) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/fastCheckAvailable", "return(true)")) re.True(followerAPIClient.Available()) re.True(leaderAPIClient.Available()) @@ -269,7 +269,7 @@ func (suite *serviceClientTestSuite) TestServiceClient() { re.True(followerAPIClient.Available()) re.True(leaderAPIClient.Available()) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/fastCheckAvailable")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/fastCheckAvailable")) } func (suite *serviceClientTestSuite) TestServiceClientBalancer() { diff --git a/client/sd/tso_service_discovery.go b/client/servicediscovery/tso_service_discovery.go similarity index 99% rename from client/sd/tso_service_discovery.go rename to client/servicediscovery/tso_service_discovery.go index 73e078e6c4a..f2b67f54133 100644 --- a/client/sd/tso_service_discovery.go +++ b/client/servicediscovery/tso_service_discovery.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package sd +package servicediscovery import ( "context" diff --git a/client/tso_client.go b/client/tso_client.go index b4024f61117..ec3676b5b14 100644 --- a/client/tso_client.go +++ b/client/tso_client.go @@ -27,7 +27,7 @@ import ( "github.com/pingcap/log" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/opt" - "github.com/tikv/pd/client/sd" + sd "github.com/tikv/pd/client/servicediscovery" "github.com/tikv/pd/client/utils/grpcutil" "github.com/tikv/pd/client/utils/tlsutil" "go.uber.org/zap" diff --git a/client/tso_dispatcher.go b/client/tso_dispatcher.go index 5f162a68971..714d9e8be54 100644 --- a/client/tso_dispatcher.go +++ b/client/tso_dispatcher.go @@ -31,7 +31,7 @@ import ( "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/opt" "github.com/tikv/pd/client/retry" - "github.com/tikv/pd/client/sd" + sd "github.com/tikv/pd/client/servicediscovery" "github.com/tikv/pd/client/utils/timerutil" "github.com/tikv/pd/client/utils/tsoutil" "go.uber.org/zap" diff --git a/client/tso_dispatcher_test.go b/client/tso_dispatcher_test.go index c3b4f6e4031..6cb963df3df 100644 --- a/client/tso_dispatcher_test.go +++ b/client/tso_dispatcher_test.go @@ -27,7 +27,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "github.com/tikv/pd/client/opt" - "github.com/tikv/pd/client/sd" + sd "github.com/tikv/pd/client/servicediscovery" "go.uber.org/zap/zapcore" ) diff --git a/tests/integrations/client/client_test.go b/tests/integrations/client/client_test.go index 0640b36cb50..615745a15ea 100644 --- a/tests/integrations/client/client_test.go +++ b/tests/integrations/client/client_test.go @@ -41,7 +41,7 @@ import ( "github.com/tikv/pd/client/caller" "github.com/tikv/pd/client/opt" "github.com/tikv/pd/client/retry" - "github.com/tikv/pd/client/sd" + sd "github.com/tikv/pd/client/servicediscovery" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/mock/mockid" @@ -325,7 +325,7 @@ func TestTSOFollowerProxy(t *testing.T) { func TestTSOFollowerProxyWithTSOService(t *testing.T) { re := require.New(t) - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/fastUpdateServiceMode", `return(true)`)) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/fastUpdateServiceMode", `return(true)`)) ctx, cancel := context.WithCancel(context.Background()) defer cancel() cluster, err := tests.NewTestAPICluster(ctx, 1) @@ -347,7 +347,7 @@ func TestTSOFollowerProxyWithTSOService(t *testing.T) { // TSO service does not support the follower proxy, so enabling it should fail. err = cli.UpdateOption(opt.EnableTSOFollowerProxy, true) re.Error(err) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/fastUpdateServiceMode")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/fastUpdateServiceMode")) } // TestUnavailableTimeAfterLeaderIsReady is used to test https://github.com/tikv/pd/issues/5207 @@ -498,13 +498,13 @@ func (suite *followerForwardAndHandleTestSuite) TestGetRegionByFollowerForwardin cli := setupCli(ctx, re, suite.endpoints, opt.WithForwardingOption(true)) defer cli.Close() - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/unreachableNetwork1", "return(true)")) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/unreachableNetwork1", "return(true)")) time.Sleep(200 * time.Millisecond) r, err := cli.GetRegion(context.Background(), []byte("a")) re.NoError(err) re.NotNil(r) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/unreachableNetwork1")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/unreachableNetwork1")) time.Sleep(200 * time.Millisecond) r, err = cli.GetRegion(context.Background(), []byte("a")) re.NoError(err) @@ -720,7 +720,7 @@ func (suite *followerForwardAndHandleTestSuite) TestGetRegionFromFollower() { // because we can't check whether this request is processed by followers from response, // we can disable forward and make network problem for leader. - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/unreachableNetwork1", fmt.Sprintf("return(\"%s\")", leader.GetAddr()))) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/unreachableNetwork1", fmt.Sprintf("return(\"%s\")", leader.GetAddr()))) time.Sleep(150 * time.Millisecond) cnt = 0 for range 100 { @@ -731,11 +731,11 @@ func (suite *followerForwardAndHandleTestSuite) TestGetRegionFromFollower() { re.Equal(resp.Meta.Id, suite.regionID) } re.Equal(100, cnt) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/unreachableNetwork1")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/unreachableNetwork1")) // make network problem for follower. follower := cluster.GetServer(cluster.GetFollower()) - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/unreachableNetwork1", fmt.Sprintf("return(\"%s\")", follower.GetAddr()))) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/unreachableNetwork1", fmt.Sprintf("return(\"%s\")", follower.GetAddr()))) time.Sleep(100 * time.Millisecond) cnt = 0 for range 100 { @@ -746,7 +746,7 @@ func (suite *followerForwardAndHandleTestSuite) TestGetRegionFromFollower() { re.Equal(resp.Meta.Id, suite.regionID) } re.Equal(100, cnt) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/unreachableNetwork1")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/unreachableNetwork1")) // follower client failed will retry by leader service client. re.NoError(failpoint.Enable("github.com/tikv/pd/server/followerHandleError", "return(true)")) @@ -762,8 +762,8 @@ func (suite *followerForwardAndHandleTestSuite) TestGetRegionFromFollower() { re.NoError(failpoint.Disable("github.com/tikv/pd/server/followerHandleError")) // test after being healthy - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/unreachableNetwork1", fmt.Sprintf("return(\"%s\")", leader.GetAddr()))) - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/fastCheckAvailable", "return(true)")) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/unreachableNetwork1", fmt.Sprintf("return(\"%s\")", leader.GetAddr()))) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/fastCheckAvailable", "return(true)")) time.Sleep(100 * time.Millisecond) cnt = 0 for range 100 { @@ -774,8 +774,8 @@ func (suite *followerForwardAndHandleTestSuite) TestGetRegionFromFollower() { re.Equal(resp.Meta.Id, suite.regionID) } re.Equal(100, cnt) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/unreachableNetwork1")) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/fastCheckAvailable")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/unreachableNetwork1")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/fastCheckAvailable")) } func (suite *followerForwardAndHandleTestSuite) TestGetTSFuture() { diff --git a/tests/integrations/mcs/resourcemanager/resource_manager_test.go b/tests/integrations/mcs/resourcemanager/resource_manager_test.go index 10bd4b21c53..15bec8ea8fd 100644 --- a/tests/integrations/mcs/resourcemanager/resource_manager_test.go +++ b/tests/integrations/mcs/resourcemanager/resource_manager_test.go @@ -34,7 +34,7 @@ import ( pd "github.com/tikv/pd/client" "github.com/tikv/pd/client/caller" "github.com/tikv/pd/client/resource_group/controller" - "github.com/tikv/pd/client/sd" + sd "github.com/tikv/pd/client/servicediscovery" "github.com/tikv/pd/pkg/mcs/resourcemanager/server" "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/pkg/utils/typeutil" diff --git a/tests/integrations/mcs/tso/server_test.go b/tests/integrations/mcs/tso/server_test.go index 3a95ac8d9a5..a78d61bf429 100644 --- a/tests/integrations/mcs/tso/server_test.go +++ b/tests/integrations/mcs/tso/server_test.go @@ -245,7 +245,7 @@ func NewAPIServerForward(re *require.Assertions) APIServerForward { re.NoError(suite.pdLeader.BootstrapCluster()) suite.addRegions() - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/usePDServiceMode", "return(true)")) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/usePDServiceMode", "return(true)")) suite.pdClient, err = pd.NewClientWithContext(context.Background(), caller.TestComponent, []string{suite.backendEndpoints}, pd.SecurityOption{}, opt.WithMaxErrorRetry(1)) @@ -267,7 +267,7 @@ func (suite *APIServerForward) ShutDown() { } suite.cluster.Destroy() suite.cancel() - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/usePDServiceMode")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/usePDServiceMode")) } func TestForwardTSORelated(t *testing.T) { @@ -593,7 +593,7 @@ func (suite *CommonTestSuite) TestBootstrapDefaultKeyspaceGroup() { // If `EnableTSODynamicSwitching` is disabled, the PD should not provide TSO service after the TSO server is stopped. func TestTSOServiceSwitch(t *testing.T) { re := require.New(t) - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/fastUpdateServiceMode", `return(true)`)) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/fastUpdateServiceMode", `return(true)`)) ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -666,7 +666,7 @@ func TestTSOServiceSwitch(t *testing.T) { // Verify PD is now providing TSO service and timestamps are monotonically increasing re.NoError(checkTSOMonotonic(ctx, pdClient, &globalLastTS, 10)) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/fastUpdateServiceMode")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/fastUpdateServiceMode")) } func checkTSOMonotonic(ctx context.Context, pdClient pd.Client, globalLastTS *uint64, count int) error { diff --git a/tests/integrations/tso/client_test.go b/tests/integrations/tso/client_test.go index 3741975afa0..422d578326a 100644 --- a/tests/integrations/tso/client_test.go +++ b/tests/integrations/tso/client_test.go @@ -31,7 +31,7 @@ import ( pd "github.com/tikv/pd/client" "github.com/tikv/pd/client/caller" "github.com/tikv/pd/client/opt" - "github.com/tikv/pd/client/sd" + sd "github.com/tikv/pd/client/servicediscovery" "github.com/tikv/pd/client/utils/testutil" bs "github.com/tikv/pd/pkg/basicserver" "github.com/tikv/pd/pkg/mcs/utils/constant" @@ -267,11 +267,11 @@ func (suite *tsoClientTestSuite) TestDiscoverTSOServiceWithLegacyPath() { failpointValue := fmt.Sprintf(`return(%d)`, keyspaceID) // Simulate the case that the server has lower version than the client and returns no tso addrs // in the GetClusterInfo RPC. - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/serverReturnsNoTSOAddrs", `return(true)`)) - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/unexpectedCallOfFindGroupByKeyspaceID", failpointValue)) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/serverReturnsNoTSOAddrs", `return(true)`)) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/unexpectedCallOfFindGroupByKeyspaceID", failpointValue)) defer func() { - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/serverReturnsNoTSOAddrs")) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/unexpectedCallOfFindGroupByKeyspaceID")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/serverReturnsNoTSOAddrs")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/unexpectedCallOfFindGroupByKeyspaceID")) }() ctx, cancel := context.WithCancel(suite.ctx) @@ -321,14 +321,14 @@ func (suite *tsoClientTestSuite) TestGetMinTS() { } wg.Wait() - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/unreachableNetwork1", "return(true)")) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/unreachableNetwork1", "return(true)")) time.Sleep(time.Second) testutil.Eventually(re, func() bool { var err error _, _, err = suite.clients[0].GetMinTS(suite.ctx) return err == nil }) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/unreachableNetwork1")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/unreachableNetwork1")) } // More details can be found in this issue: https://github.com/tikv/pd/issues/4884 @@ -488,10 +488,10 @@ func TestMixedTSODeployment(t *testing.T) { re := require.New(t) re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/tso/fastUpdatePhysicalInterval", "return(true)")) - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/skipUpdateServiceMode", "return(true)")) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/skipUpdateServiceMode", "return(true)")) defer func() { re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/tso/fastUpdatePhysicalInterval")) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/skipUpdateServiceMode")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/skipUpdateServiceMode")) }() ctx, cancel := context.WithCancel(context.Background()) @@ -551,7 +551,7 @@ func TestUpgradingAPIandTSOClusters(t *testing.T) { backendEndpoints := pdLeader.GetAddr() // Create a pd client in PD mode to let the API leader to forward requests to the TSO cluster. - re.NoError(failpoint.Enable("github.com/tikv/pd/client/sd/usePDServiceMode", "return(true)")) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/servicediscovery/usePDServiceMode", "return(true)")) pdClient, err := pd.NewClientWithContext(context.Background(), caller.TestComponent, []string{backendEndpoints}, pd.SecurityOption{}, opt.WithMaxErrorRetry(1)) @@ -580,7 +580,7 @@ func TestUpgradingAPIandTSOClusters(t *testing.T) { tsoCluster.Destroy() apiCluster.Destroy() cancel() - re.NoError(failpoint.Disable("github.com/tikv/pd/client/sd/usePDServiceMode")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/servicediscovery/usePDServiceMode")) } func checkTSO( diff --git a/tools/pd-simulator/simulator/client.go b/tools/pd-simulator/simulator/client.go index b92e6609764..4de2ea52f88 100644 --- a/tools/pd-simulator/simulator/client.go +++ b/tools/pd-simulator/simulator/client.go @@ -27,7 +27,7 @@ import ( "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" pdHttp "github.com/tikv/pd/client/http" - "github.com/tikv/pd/client/sd" + sd "github.com/tikv/pd/client/servicediscovery" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/utils/typeutil" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" diff --git a/tools/pd-simulator/simulator/drive.go b/tools/pd-simulator/simulator/drive.go index 8a1e33ecac2..c8c325cfca6 100644 --- a/tools/pd-simulator/simulator/drive.go +++ b/tools/pd-simulator/simulator/drive.go @@ -31,7 +31,7 @@ import ( "github.com/pingcap/kvproto/pkg/pdpb" "github.com/prometheus/client_golang/prometheus/promhttp" pdHttp "github.com/tikv/pd/client/http" - "github.com/tikv/pd/client/sd" + sd "github.com/tikv/pd/client/servicediscovery" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/utils/typeutil" "github.com/tikv/pd/tools/pd-simulator/simulator/cases"