Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctl: replace gc_safepoint call with PD HTTP SDK #8501

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const (
Status = "/pd/api/v1/status"
Version = "/pd/api/v1/version"
operators = "/pd/api/v1/operators"
safepoint = "pd/api/v1/gc/safepoint"
// Micro Service
microServicePrefix = "/pd/api/v2/ms"
// Keyspace
Expand Down
28 changes: 28 additions & 0 deletions client/http/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ type Client interface {
/* Other interfaces */
GetMinResolvedTSByStoresIDs(context.Context, []uint64) (uint64, map[uint64]uint64, error)
GetPDVersion(context.Context) (string, error)
GetGCSafePoint(context.Context) (ListServiceGCSafepoint, error)
DeleteGCSafePoint(context.Context, string) (string, error)
/* Micro Service interfaces */
GetMicroServiceMembers(context.Context, string) ([]MicroServiceMember, error)
GetMicroServicePrimary(context.Context, string) (string, error)
Expand Down Expand Up @@ -1024,3 +1026,29 @@ func (c *client) GetKeyspaceMetaByName(ctx context.Context, keyspaceName string)
}
return &keyspaceMetaPB, nil
}

func (c *client) GetGCSafePoint(ctx context.Context) (ListServiceGCSafepoint, error) {
var gcsafepoint ListServiceGCSafepoint
err := c.request(ctx, newRequestInfo().
WithName(GetGCSafePointName).
WithURI(safepoint).
WithMethod(http.MethodGet).
WithResp(&gcsafepoint))
if err != nil {
return gcsafepoint, err
}
return gcsafepoint, nil
}

func (c *client) DeleteGCSafePoint(ctx context.Context, service_id string) (string, error) {
var msg string
err := c.request(ctx, newRequestInfo().
WithName(DeleteGCSafePointName).
WithURI(safepoint+"/"+service_id).
WithMethod(http.MethodDelete).
WithResp(&msg))
if err != nil {
return msg, err
}
return msg, nil
}
2 changes: 2 additions & 0 deletions client/http/request_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ const (
deleteOperators = "DeleteOperators"
UpdateKeyspaceGCManagementTypeName = "UpdateKeyspaceGCManagementType"
GetKeyspaceMetaByNameName = "GetKeyspaceMetaByName"
GetGCSafePointName = "GetGCSafePoint"
DeleteGCSafePointName = "DeleteGCSafePoint"
)

type requestInfo struct {
Expand Down
14 changes: 14 additions & 0 deletions client/http/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ import (
pd "github.com/tikv/pd/client"
)

// NOTE: This type is in sync with pd/pkg/storage/endpoint/gc_safe_point.go
type ServiceSafePoint struct {
ServiceID string `json:"service_id"`
ExpiredAt int64 `json:"expired_at"`
SafePoint uint64 `json:"safe_point"`
}

// NOTE: This type is in sync with pd/server/spi/service_gc_safepoint.go
type ListServiceGCSafepoint struct {
ServiceGCSafepoints []*ServiceSafePoint `json:"service_gc_safe_points"`
MinServiceGcSafepoint uint64 `json:"min_service_gc_safe_point,omitempty"`
GCSafePoint uint64 `json:"gc_safe_point"`
}

// ClusterState saves some cluster state information.
// NOTE: This type sync with https://github.com/tikv/pd/blob/5eae459c01a797cbd0c416054c6f0cad16b8740a/server/cluster/cluster.go#L173
type ClusterState struct {
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ require (
github.com/aws/smithy-go v1.13.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch // indirect
// github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch // indirect
github.com/breeswish/gin-jwt/v2 v2.6.5-0.20211112114546-24b7fddb24dc // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cenkalti/backoff/v4 v4.0.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkN
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch h1:KLE/YeX+9FNaGVW5MtImRVPhjDpfpgJhvkuYWBmOYbo=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch/go.mod h1:KjBLriHXe7L6fGceqWzTod8HUB/TP1WWDtfuSYtYXaI=
github.com/breeswish/gin-jwt/v2 v2.6.5-0.20211112114546-24b7fddb24dc h1:25r4N907v+x57iMFeGIHKQfKtB1aQAm7R5aoPsTP9wI=
github.com/breeswish/gin-jwt/v2 v2.6.5-0.20211112114546-24b7fddb24dc/go.mod h1:KjBLriHXe7L6fGceqWzTod8HUB/TP1WWDtfuSYtYXaI=
github.com/brianvoe/gofakeit/v6 v6.26.3 h1:3ljYrjPwsUNAUFdUIr2jVg5EhKdcke/ZLop7uVg1Er8=
github.com/brianvoe/gofakeit/v6 v6.26.3/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
Expand Down
1 change: 1 addition & 0 deletions pkg/storage/endpoint/gc_safe_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

// ServiceSafePoint is the safepoint for a specific service
// NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.
// this type is in sync with client/http/types.go
type ServiceSafePoint struct {
ServiceID string `json:"service_id"`
ExpiredAt int64 `json:"expired_at"`
Expand Down
1 change: 1 addition & 0 deletions server/api/service_gc_safepoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func newServiceGCSafepointHandler(svr *server.Server, rd *render.Render) *servic

// ListServiceGCSafepoint is the response for list service GC safepoint.
// NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.
// this type is now in sync with pd/client/http/types.go ListServiceGCSafepoint
type ListServiceGCSafepoint struct {
ServiceGCSafepoints []*endpoint.ServiceSafePoint `json:"service_gc_safe_points"`
MinServiceGcSafepoint uint64 `json:"min_service_gc_safe_point,omitempty"`
Expand Down
3 changes: 2 additions & 1 deletion tests/integrations/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ require (
github.com/aws/smithy-go v1.13.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch // indirect
// github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch // indirect
github.com/breeswish/gin-jwt/v2 v2.6.5-0.20211112114546-24b7fddb24dc // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5 // indirect
github.com/cenkalti/backoff/v4 v4.0.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkN
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch h1:KLE/YeX+9FNaGVW5MtImRVPhjDpfpgJhvkuYWBmOYbo=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch/go.mod h1:KjBLriHXe7L6fGceqWzTod8HUB/TP1WWDtfuSYtYXaI=
github.com/breeswish/gin-jwt/v2 v2.6.5-0.20211112114546-24b7fddb24dc h1:25r4N907v+x57iMFeGIHKQfKtB1aQAm7R5aoPsTP9wI=
github.com/breeswish/gin-jwt/v2 v2.6.5-0.20211112114546-24b7fddb24dc/go.mod h1:KjBLriHXe7L6fGceqWzTod8HUB/TP1WWDtfuSYtYXaI=
github.com/brianvoe/gofakeit/v6 v6.26.3 h1:3ljYrjPwsUNAUFdUIr2jVg5EhKdcke/ZLop7uVg1Er8=
github.com/brianvoe/gofakeit/v6 v6.26.3/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
Expand Down
3 changes: 2 additions & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ require (
github.com/aws/smithy-go v1.13.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch // indirect
// github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch // indirect
github.com/breeswish/gin-jwt/v2 v2.6.5-0.20211112114546-24b7fddb24dc // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cenkalti/backoff/v4 v4.0.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkN
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch h1:KLE/YeX+9FNaGVW5MtImRVPhjDpfpgJhvkuYWBmOYbo=
github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch/go.mod h1:KjBLriHXe7L6fGceqWzTod8HUB/TP1WWDtfuSYtYXaI=
github.com/breeswish/gin-jwt/v2 v2.6.5-0.20211112114546-24b7fddb24dc h1:25r4N907v+x57iMFeGIHKQfKtB1aQAm7R5aoPsTP9wI=
github.com/breeswish/gin-jwt/v2 v2.6.5-0.20211112114546-24b7fddb24dc/go.mod h1:KjBLriHXe7L6fGceqWzTod8HUB/TP1WWDtfuSYtYXaI=
github.com/brianvoe/gofakeit/v6 v6.26.3 h1:3ljYrjPwsUNAUFdUIr2jVg5EhKdcke/ZLop7uVg1Er8=
github.com/brianvoe/gofakeit/v6 v6.26.3/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
Expand Down
21 changes: 4 additions & 17 deletions tools/pd-ctl/pdctl/command/gc_safepoint_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ package command

import (
"encoding/json"
"net/http"
"sort"

"github.com/spf13/cobra"
"github.com/tikv/pd/server/api"
)

var (
serviceGCSafepointPrefix = "pd/api/v1/gc/safepoint"
)

// NewServiceGCSafepointCommand return a service gc safepoint subcommand of rootCmd
Expand All @@ -50,16 +44,11 @@ func NewDeleteServiceGCSafepointCommand() *cobra.Command {
}

func showSSPs(cmd *cobra.Command, _ []string) {
r, err := doRequest(cmd, serviceGCSafepointPrefix, http.MethodGet, http.Header{})
safepoint, err := PDCli.GetGCSafePoint(cmd.Context())
if err != nil {
cmd.Printf("Failed to get service GC safepoint: %s\n", err)
return
}
var safepoint api.ListServiceGCSafepoint
if err := json.Unmarshal([]byte(r), &safepoint); err != nil {
cmd.Printf("Failed to unmarshal service GC safepoint: %s\n", err)
return
}
sort.Slice(safepoint.ServiceGCSafepoints, func(i, j int) bool {
return safepoint.ServiceGCSafepoints[i].SafePoint < safepoint.ServiceGCSafepoints[j].SafePoint
})
Expand All @@ -68,20 +57,18 @@ func showSSPs(cmd *cobra.Command, _ []string) {
cmd.Printf("Failed to marshal service GC safepoint: %s\n", err)
return
}
cmd.Println(string(data))
jsonPrint(cmd, string(data))
}

func deleteSSP(cmd *cobra.Command, args []string) {
if len(args) != 1 {
cmd.Usage()
return
}
serviceID := args[0]
deleteURL := serviceGCSafepointPrefix + "/" + serviceID
r, err := doRequest(cmd, deleteURL, http.MethodDelete, http.Header{})
r, err := PDCli.DeleteGCSafePoint(cmd.Context(), args[0])
if err != nil {
cmd.Printf("Failed to delete service GC safepoint: %s\n", err)
return
}
cmd.Println(r)
jsonPrint(cmd, r)
}
28 changes: 15 additions & 13 deletions tools/pd-ut/ut.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ go tool cover --func=xxx`
}

var (
modulePath = "github.com/tikv/pd"
modulePath = filepath.Join("github.com", "tikv", "pd")
integrationsTestPath = filepath.Join("tests", "integrations")
)

Expand Down Expand Up @@ -414,7 +414,7 @@ func runExistingTestCases(pkgs []string) (tasks []task, err error) {
wg := &sync.WaitGroup{}
tasksChannel := make(chan []task, len(pkgs))
for _, pkg := range pkgs {
_, ok := existPkgs[fmt.Sprintf("%s/%s", modulePath, pkg)]
_, ok := existPkgs[filepath.Join(modulePath, pkg)]
if !ok {
fmt.Println("no test case in ", pkg)
continue
Expand Down Expand Up @@ -528,7 +528,8 @@ func filterTestCases(tasks []task, arg1 string) ([]task, error) {
}

func listPackages() ([]string, error) {
cmd := exec.Command("go", "list", "./...")
listPath := strings.Join([]string{".", "..."}, string(filepath.Separator))
cmd := exec.Command("go", "list", listPath)
cmd.Dir = workDir
ss, err := cmdToLines(cmd)
if err != nil {
Expand Down Expand Up @@ -677,7 +678,7 @@ func (*numa) testCommand(pkg string, fn string) *exec.Cmd {
args = append(args, "-test.v")
exe := strings.Join([]string{".", testFileName(pkg)}, string(filepath.Separator))
if coverProfile != "" {
fileName := strings.ReplaceAll(pkg, "/", "_") + "." + fn
fileName := strings.ReplaceAll(pkg, string(filepath.Separator), "_") + "." + fn
tmpFile := filepath.Join(coverFileTempDir, fileName)
args = append(args, "-test.coverprofile", tmpFile)
}
Expand Down Expand Up @@ -720,12 +721,12 @@ func generateBuildCache() error {
fmt.Println("generate build cache")
// cd cmd/pd-server && go test -tags=tso_function_test,deadlock -exec-=true -vet=off -toolexec=go-compile-without-link
cmd := exec.Command("go", "test", "-exec=true", "-vet", "off", "--tags=tso_function_test,deadlock")
goCompileWithoutLink := fmt.Sprintf("-toolexec=%s/tools/pd-ut/go-compile-without-link.sh", workDir)
cmd.Dir = fmt.Sprintf("%s/cmd/pd-server", workDir)
goCompileWithoutLink := fmt.Sprintf("-toolexec=%s", filepath.Join(workDir, "tools", "pd-ut", "go-compile-without-link.sh"))
cmd.Dir = filepath.Join(workDir, "cmd", "pd-server")
if strings.Contains(workDir, integrationsTestPath) {
cmd.Dir = fmt.Sprintf("%s/cmd/pd-server", workDir[:strings.LastIndex(workDir, integrationsTestPath)])
goCompileWithoutLink = fmt.Sprintf("-toolexec=%s/tools/pd-ut/go-compile-without-link.sh",
workDir[:strings.LastIndex(workDir, integrationsTestPath)])
cmd.Dir = filepath.Join(workDir[:strings.LastIndex(workDir, integrationsTestPath)], "cmd", "pd-server")
goCompileWithoutLink = fmt.Sprintf("-toolexec=%s", filepath.Join(workDir[:strings.LastIndex(workDir, integrationsTestPath)],
"tools", "pd-ut", "go-compile-without-link.sh"))
}
cmd.Args = append(cmd.Args, goCompileWithoutLink)
cmd.Stdout = os.Stdout
Expand Down Expand Up @@ -759,11 +760,11 @@ func buildTestBinaryMulti(pkgs []string) ([]byte, error) {
p := strconv.Itoa(parallel * 2)
cmd := exec.Command("go", "test", "-p", p, "--exec", xprogPath, "-vet", "off", "--tags=tso_function_test,deadlock")
if coverProfile != "" {
coverpkg := "./..."
coverPkg := strings.Join([]string{".", "..."}, string(filepath.Separator))
if strings.Contains(workDir, integrationsTestPath) {
coverpkg = "../../..."
coverPkg = filepath.Join("..", "..", "...")
}
cmd.Args = append(cmd.Args, "-cover", fmt.Sprintf("-coverpkg=%s", coverpkg))
cmd.Args = append(cmd.Args, "-cover", fmt.Sprintf("-coverpkg=%s", coverPkg))
}
cmd.Args = append(cmd.Args, packages...)
if race {
Expand Down Expand Up @@ -794,7 +795,8 @@ func buildTestBinary(pkg string) error {
//nolint:gosec
cmd := exec.Command("go", "test", "-c", "-vet", "off", "--tags=tso_function_test,deadlock", "-o", testFileName(pkg), "-v")
if coverProfile != "" {
cmd.Args = append(cmd.Args, "-cover", "-coverpkg=./...")
coverPkg := strings.Join([]string{".", "..."}, string(filepath.Separator))
cmd.Args = append(cmd.Args, "-cover", fmt.Sprintf("-coverpkg=%s", coverPkg))
}
if race {
cmd.Args = append(cmd.Args, "-race")
Expand Down
4 changes: 2 additions & 2 deletions tools/pd-ut/xprog.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ func main() {

// Extract the current work directory
cwd := os.Args[0]
cwd = cwd[:len(cwd)-len("bin/xprog")]
cwd = cwd[:len(cwd)-len(filepath.Join("bin", "xprog"))]

testBinaryPath := os.Args[1]
dir, _ := filepath.Split(testBinaryPath)

// Extract the package info from /tmp/go-build2662369829/b1382/importcfg.link
pkg := getPackageInfo(dir)

const prefix = "github.com/tikv/pd/"
var prefix = filepath.Join("github.com", "tikv", "pd")
if !strings.HasPrefix(pkg, prefix) {
os.Exit(-3)
}
Expand Down
Loading