From 9963920b813e4ff776aba1538917a31cb552c41c Mon Sep 17 00:00:00 2001 From: Boyang Lyu Date: Wed, 31 Jul 2024 11:26:24 +0800 Subject: [PATCH 1/2] changed log.Error to log.Warn Signed-off-by: Boyang Lyu --- pkg/mcs/resourcemanager/server/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/mcs/resourcemanager/server/manager.go b/pkg/mcs/resourcemanager/server/manager.go index 13e46ea0bba..8588c22b9ae 100644 --- a/pkg/mcs/resourcemanager/server/manager.go +++ b/pkg/mcs/resourcemanager/server/manager.go @@ -121,7 +121,7 @@ func (m *Manager) Init(ctx context.Context) error { return err } if err = json.Unmarshal([]byte(v), &m.controllerConfig); err != nil { - log.Error("un-marshall controller config failed, fallback to default", zap.Error(err), zap.String("v", v)) + log.Warn("un-marshall controller config failed, fallback to default", zap.Error(err), zap.String("v", v)) } // re-save the config to make sure the config has been persisted. From 66c0b740b4ed3f671ab80c0614b34381fabdd526 Mon Sep 17 00:00:00 2001 From: Boyang Lyu Date: Mon, 5 Aug 2024 17:07:34 +0800 Subject: [PATCH 2/2] update gc_safepoint call with PD HTTP SDK Signed-off-by: Boyang Lyu --- client/http/api.go | 2 ++ client/http/interface.go | 30 +++++++++++++++++++ client/http/request_info.go | 2 ++ client/http/types.go | 6 ++++ server/api/service_gc_safepoint.go | 1 + .../pdctl/command/gc_safepoint_command.go | 16 +++++----- 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/client/http/api.go b/client/http/api.go index 3376a48770d..8dbbff4bcce 100644 --- a/client/http/api.go +++ b/client/http/api.go @@ -84,6 +84,8 @@ const ( // Keyspace KeyspaceConfig = "/pd/api/v2/keyspaces/%s/config" GetKeyspaceMetaByName = "/pd/api/v2/keyspaces/%s" + // safepoint + GCSafepoint = "pd/api/v1/gc/safepoint" ) // RegionByID returns the path of PD HTTP API to get region by ID. diff --git a/client/http/interface.go b/client/http/interface.go index f90ab19624f..0be3186adbc 100644 --- a/client/http/interface.go +++ b/client/http/interface.go @@ -128,6 +128,10 @@ type Client interface { WithTargetURL(string) Client // Close gracefully closes the HTTP client. Close() + + //safepoint + GetGCSafePoint(context.Context) (Safepoint, error) + DeleteGCSafePoint(context.Context, string) (string, error) } var _ Client = (*client)(nil) @@ -1024,3 +1028,29 @@ func (c *client) GetKeyspaceMetaByName(ctx context.Context, keyspaceName string) } return &keyspaceMetaPB, nil } + +func (c *client) GetGCSafePoint(ctx context.Context) (Safepoint ,error) { + var sfp Safepoint + err := c.request(ctx, newRequestInfo(). + WithName(GetGCSafePointName). + WithURI(GCSafepoint). + WithMethod(http.MethodGet). + WithResp(&sfp)) + if err != nil { + return nil, err + } + return sfp, nil +} + +func (c *client) DeleteGCSafePoint(ctx context.Context, serviceID string) (string ,error) { + var msg string + err := c.request(ctx, newRequestInfo(). + WithName(DeleteGCSafePointName). + WithURI(GCSafepoint + "/" + serviceID). + WithMethod(http.MethodDelete). + WithResp(&msg)) + if err != nil { + return nil, 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..6f191153631 100644 --- a/client/http/types.go +++ b/client/http/types.go @@ -643,3 +643,9 @@ type Health struct { ClientUrls []string `json:"client_urls"` Health bool `json:"health"` } + +type Safepoint struct { + ServiceGCSafepoints []*endpoint.ServiceSafePoint `json:"service_gc_safe_points"` + MinServiceGcSafepoint uint64 `json:"min_service_gc_safe_point,omitempty"` + GCSafePoint uint64 `json:"gc_safe_point"` +} \ No newline at end of file diff --git a/server/api/service_gc_safepoint.go b/server/api/service_gc_safepoint.go index d6bb153eb6f..b6b5326e288 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. +// - Need to sync with client/http/types.go#Safepoint 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..e5ae67cfcf1 100644 --- a/tools/pd-ctl/pdctl/command/gc_safepoint_command.go +++ b/tools/pd-ctl/pdctl/command/gc_safepoint_command.go @@ -23,10 +23,6 @@ import ( "github.com/tikv/pd/server/api" ) -var ( - serviceGCSafepointPrefix = "pd/api/v1/gc/safepoint" -) - // NewServiceGCSafepointCommand return a service gc safepoint subcommand of rootCmd func NewServiceGCSafepointCommand() *cobra.Command { l := &cobra.Command{ @@ -50,12 +46,13 @@ func NewDeleteServiceGCSafepointCommand() *cobra.Command { } func showSSPs(cmd *cobra.Command, _ []string) { - r, err := doRequest(cmd, serviceGCSafepointPrefix, http.MethodGet, http.Header{}) + // r, err := doRequest(cmd, serviceGCSafepointPrefix, http.MethodGet, http.Header{}) + r, err := PDCli.GetGCSafePoint(cmd.Context()) if err != nil { cmd.Printf("Failed to get service GC safepoint: %s\n", err) return } - var safepoint api.ListServiceGCSafepoint + var safepoint Safepoint if err := json.Unmarshal([]byte(r), &safepoint); err != nil { cmd.Printf("Failed to unmarshal service GC safepoint: %s\n", err) return @@ -76,9 +73,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{}) + // 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