From 14d387ab9a5482e01c88205ad3788b87d3054b34 Mon Sep 17 00:00:00 2001 From: Boyang Lyu Date: Wed, 7 Aug 2024 12:58:43 +0800 Subject: [PATCH 1/4] changed the version of a package in go.mod and go.sum Signed-off-by: Boyang Lyu --- go.mod | 3 ++- go.sum | 4 ++-- scripts/embed-dashboard-ui.sh | 26 +++++++++++++------------- tests/integrations/go.mod | 3 ++- tests/integrations/go.sum | 4 ++-- tools/go.mod | 3 ++- tools/go.sum | 4 ++-- 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index aee8cc7afad..960f6c43fb0 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 3bbddb05476..f124072ec42 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/scripts/embed-dashboard-ui.sh b/scripts/embed-dashboard-ui.sh index c5e28df9cb2..8343f647b7c 100755 --- a/scripts/embed-dashboard-ui.sh +++ b/scripts/embed-dashboard-ui.sh @@ -55,19 +55,19 @@ function download_embed_asset { DOWNLOAD_URL="https://github.com/pingcap/tidb-dashboard/releases/download/v${DASHBOARD_RELEASE_VERSION}/embedded-assets-golang.zip" DOWNLOAD_FILE=${CACHE_DIR}/embedded-assets-golang.zip echo " - Download ${DOWNLOAD_URL}" - if ! curl -L "${DOWNLOAD_URL}" --fail --output "${DOWNLOAD_FILE}"; then - echo - echo -e "${RED}Error: Failed to download assets of TiDB Dashboard release version ${DASHBOARD_RELEASE_VERSION}.${NC}" - if [ "${DASHBOARD_RELEASE_VERSION}" == "nightly" ]; then - echo 'This project is using the nightly version of TiDB Dashboard, which does not have any release.' - else - echo 'This may be caused by using a non-release version of TiDB Dashboard, or the release is still in progress.' - fi - echo - echo -e "To compile PD without TiDB Dashboard: ${YELLOW}DASHBOARD=0 make${NC}" - echo -e "To compile PD by building TiDB Dashboard assets on-the-fly: ${YELLOW}DASHBOARD=COMPILE make${NC} or ${YELLOW}NO_MINIMIZE=1 DASHBOARD=COMPILE make${NC}" - exit 1 - fi + # if ! curl -L "${DOWNLOAD_URL}" --fail --output "${DOWNLOAD_FILE}"; then + # echo + # echo -e "${RED}Error: Failed to download assets of TiDB Dashboard release version ${DASHBOARD_RELEASE_VERSION}.${NC}" + # if [ "${DASHBOARD_RELEASE_VERSION}" == "nightly" ]; then + # echo 'This project is using the nightly version of TiDB Dashboard, which does not have any release.' + # else + # echo 'This may be caused by using a non-release version of TiDB Dashboard, or the release is still in progress.' + # fi + # echo + # echo -e "To compile PD without TiDB Dashboard: ${YELLOW}DASHBOARD=0 make${NC}" + # echo -e "To compile PD by building TiDB Dashboard assets on-the-fly: ${YELLOW}DASHBOARD=COMPILE make${NC} or ${YELLOW}NO_MINIMIZE=1 DASHBOARD=COMPILE make${NC}" + # exit 1 + # fi echo " - Save archive to cache: ${CACHE_FILE}" mv "${DOWNLOAD_FILE}" "${CACHE_FILE}" diff --git a/tests/integrations/go.mod b/tests/integrations/go.mod index f56b1cdc32a..4d2399a4435 100644 --- a/tests/integrations/go.mod +++ b/tests/integrations/go.mod @@ -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 diff --git a/tests/integrations/go.sum b/tests/integrations/go.sum index e23f71d41ce..d776349ac23 100644 --- a/tests/integrations/go.sum +++ b/tests/integrations/go.sum @@ -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= diff --git a/tools/go.mod b/tools/go.mod index aef95dfa660..b88bdc4d9ff 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -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 diff --git a/tools/go.sum b/tools/go.sum index d9bc29aebff..15f30beabff 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -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= From 3c4c4278acf49b0f7a8974f7205623341a4c31dc Mon Sep 17 00:00:00 2001 From: Hu# Date: Tue, 6 Aug 2024 19:42:40 +0800 Subject: [PATCH 2/4] tools/ut: replace path with filepath (#8498) ref tikv/pd#7969, ref tikv/pd#8475 Signed-off-by: husharp Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> Signed-off-by: Boyang Lyu --- tools/pd-ut/ut.go | 28 +++++++++++++++------------- tools/pd-ut/xprog.go | 4 ++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/tools/pd-ut/ut.go b/tools/pd-ut/ut.go index e0312272310..6b366a137a2 100644 --- a/tools/pd-ut/ut.go +++ b/tools/pd-ut/ut.go @@ -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") ) @@ -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 @@ -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 { @@ -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) } @@ -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 @@ -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 { @@ -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") diff --git a/tools/pd-ut/xprog.go b/tools/pd-ut/xprog.go index cf3e9b295e2..4a593be8f31 100644 --- a/tools/pd-ut/xprog.go +++ b/tools/pd-ut/xprog.go @@ -34,7 +34,7 @@ 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) @@ -42,7 +42,7 @@ func main() { // 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) } From 4caa8d99bb672419ba00717d7d81183922976972 Mon Sep 17 00:00:00 2001 From: Boyang Lyu Date: Wed, 7 Aug 2024 15:07:58 +0800 Subject: [PATCH 3/4] change gc_safepoint call to PD HTTP SDK Signed-off-by: Boyang Lyu --- client/http/api.go | 1 + client/http/interface.go | 28 +++++++++++++++++++ client/http/request_info.go | 2 ++ client/http/types.go | 14 ++++++++++ pkg/storage/endpoint/gc_safe_point.go | 1 + server/api/service_gc_safepoint.go | 1 + .../pdctl/command/gc_safepoint_command.go | 21 +++----------- 7 files changed, 51 insertions(+), 17 deletions(-) diff --git a/client/http/api.go b/client/http/api.go index 3376a48770d..38eb792d9b4 100644 --- a/client/http/api.go +++ b/client/http/api.go @@ -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 diff --git a/client/http/interface.go b/client/http/interface.go index cd9fc22702e..9f2903525ae 100644 --- a/client/http/interface.go +++ b/client/http/interface.go @@ -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) @@ -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 +} \ No newline at end of file diff --git a/client/http/request_info.go b/client/http/request_info.go index 783220bcc60..fea9bdd332f 100644 --- a/client/http/request_info.go +++ b/client/http/request_info.go @@ -85,6 +85,8 @@ const ( deleteOperators = "DeleteOperators" UpdateKeyspaceGCManagementTypeName = "UpdateKeyspaceGCManagementType" GetKeyspaceMetaByNameName = "GetKeyspaceMetaByName" + GetGCSafePointName = "GetGCSafePoint" + DeleteGCSafePointName = "DeleteGCSafePoint" ) type requestInfo struct { diff --git a/client/http/types.go b/client/http/types.go index 55f9b65caad..bbc7a02f710 100644 --- a/client/http/types.go +++ b/client/http/types.go @@ -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 { diff --git a/pkg/storage/endpoint/gc_safe_point.go b/pkg/storage/endpoint/gc_safe_point.go index 85b29e0b47e..137d2abd680 100644 --- a/pkg/storage/endpoint/gc_safe_point.go +++ b/pkg/storage/endpoint/gc_safe_point.go @@ -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"` diff --git a/server/api/service_gc_safepoint.go b/server/api/service_gc_safepoint.go index d6bb153eb6f..06d7f174a5a 100644 --- a/server/api/service_gc_safepoint.go +++ b/server/api/service_gc_safepoint.go @@ -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"` diff --git a/tools/pd-ctl/pdctl/command/gc_safepoint_command.go b/tools/pd-ctl/pdctl/command/gc_safepoint_command.go index f4a6b6fcfd0..496c870d9e1 100644 --- a/tools/pd-ctl/pdctl/command/gc_safepoint_command.go +++ b/tools/pd-ctl/pdctl/command/gc_safepoint_command.go @@ -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 @@ -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 }) @@ -68,7 +57,7 @@ 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) { @@ -76,12 +65,10 @@ func deleteSSP(cmd *cobra.Command, args []string) { 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) } From e22092462594cbd0cba71e3c50201e195e5f22c0 Mon Sep 17 00:00:00 2001 From: Boyang Lyu Date: Wed, 7 Aug 2024 15:32:49 +0800 Subject: [PATCH 4/4] change the shell scripts back Signed-off-by: Boyang Lyu --- scripts/embed-dashboard-ui.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/embed-dashboard-ui.sh b/scripts/embed-dashboard-ui.sh index 8343f647b7c..c5e28df9cb2 100755 --- a/scripts/embed-dashboard-ui.sh +++ b/scripts/embed-dashboard-ui.sh @@ -55,19 +55,19 @@ function download_embed_asset { DOWNLOAD_URL="https://github.com/pingcap/tidb-dashboard/releases/download/v${DASHBOARD_RELEASE_VERSION}/embedded-assets-golang.zip" DOWNLOAD_FILE=${CACHE_DIR}/embedded-assets-golang.zip echo " - Download ${DOWNLOAD_URL}" - # if ! curl -L "${DOWNLOAD_URL}" --fail --output "${DOWNLOAD_FILE}"; then - # echo - # echo -e "${RED}Error: Failed to download assets of TiDB Dashboard release version ${DASHBOARD_RELEASE_VERSION}.${NC}" - # if [ "${DASHBOARD_RELEASE_VERSION}" == "nightly" ]; then - # echo 'This project is using the nightly version of TiDB Dashboard, which does not have any release.' - # else - # echo 'This may be caused by using a non-release version of TiDB Dashboard, or the release is still in progress.' - # fi - # echo - # echo -e "To compile PD without TiDB Dashboard: ${YELLOW}DASHBOARD=0 make${NC}" - # echo -e "To compile PD by building TiDB Dashboard assets on-the-fly: ${YELLOW}DASHBOARD=COMPILE make${NC} or ${YELLOW}NO_MINIMIZE=1 DASHBOARD=COMPILE make${NC}" - # exit 1 - # fi + if ! curl -L "${DOWNLOAD_URL}" --fail --output "${DOWNLOAD_FILE}"; then + echo + echo -e "${RED}Error: Failed to download assets of TiDB Dashboard release version ${DASHBOARD_RELEASE_VERSION}.${NC}" + if [ "${DASHBOARD_RELEASE_VERSION}" == "nightly" ]; then + echo 'This project is using the nightly version of TiDB Dashboard, which does not have any release.' + else + echo 'This may be caused by using a non-release version of TiDB Dashboard, or the release is still in progress.' + fi + echo + echo -e "To compile PD without TiDB Dashboard: ${YELLOW}DASHBOARD=0 make${NC}" + echo -e "To compile PD by building TiDB Dashboard assets on-the-fly: ${YELLOW}DASHBOARD=COMPILE make${NC} or ${YELLOW}NO_MINIMIZE=1 DASHBOARD=COMPILE make${NC}" + exit 1 + fi echo " - Save archive to cache: ${CACHE_FILE}" mv "${DOWNLOAD_FILE}" "${CACHE_FILE}"