Skip to content

Commit

Permalink
Add flush and garbagecollect methods, sync and async
Browse files Browse the repository at this point in the history
  • Loading branch information
burmanm committed Oct 11, 2023
1 parent 34e2ae6 commit 8963678
Showing 1 changed file with 71 additions and 1 deletion.
72 changes: 71 additions & 1 deletion pkg/httphelper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ const (
FullQuerySupport Feature = "full_query_logging"
Rebuild Feature = "rebuild"
Move Feature = "async_move_task"
AsyncGarbageCollect Feature = "async_gc_task"
AsyncFlush Feature = "async_flush_task"
)

func (f *FeatureSet) UnmarshalJSON(b []byte) error {
Expand Down Expand Up @@ -593,7 +595,6 @@ type ScrubRequest struct {
Tables []string `json:"tables"`
}

// TODO This, keyspaceRequest and compactRequest are all pretty much the same..
func createScrubRequest(pod *corev1.Pod, scrubRequest *ScrubRequest, endpoint string) (*nodeMgmtRequest, error) {
body, err := json.Marshal(scrubRequest)
if err != nil {
Expand Down Expand Up @@ -1263,5 +1264,74 @@ func (client *NodeMgmtClient) CallSetFullQueryLog(pod *corev1.Pod, enableFullQue
)

_, err = callNodeMgmtEndpoint(client, request, "")

return err
}

func (client *NodeMgmtClient) CallFlush(pod *corev1.Pod, keyspaceName string, tables []string) (string, error) {
client.Log.Info(
"calling Management API keyspace flush - POST /api/v1/ops/tables/flush",
"pod", pod.Name,
)

req, err := createKeySpaceRequest(pod, -1, keyspaceName, tables, "/api/v1/ops/tables/flush")
if err != nil {
return "", err
}

req.timeout = 20 * time.Second

jobId, err := callNodeMgmtEndpoint(client, *req, "application/json")
return string(jobId), err
}

func (client *NodeMgmtClient) CallFlushEndpoint(pod *corev1.Pod, keyspaceName string, tables []string) error {
client.Log.Info(
"calling Management API keyspace flush - POST /api/v0/ops/tables/flush",
"pod", pod.Name,
)

req, err := createKeySpaceRequest(pod, -1, keyspaceName, tables, "/api/v0/ops/tables/flush")
if err != nil {
return err
}

req.timeout = 60 * time.Second

_, err = callNodeMgmtEndpoint(client, *req, "application/json")
return err
}

func (client *NodeMgmtClient) CallGarbageCollect(pod *corev1.Pod, keyspaceName string, tables []string) (string, error) {
client.Log.Info(
"calling Management API keyspace flush - POST /api/v1/ops/tables/garbagecollect",
"pod", pod.Name,
)

req, err := createKeySpaceRequest(pod, -1, keyspaceName, tables, "/api/v1/ops/tables/garbagecollect")
if err != nil {
return "", err
}

req.timeout = 20 * time.Second

jobId, err := callNodeMgmtEndpoint(client, *req, "application/json")
return string(jobId), err
}

func (client *NodeMgmtClient) CallGarbageCollectEndpoint(pod *corev1.Pod, keyspaceName string, tables []string) error {
client.Log.Info(
"calling Management API keyspace flush - POST /api/v0/ops/tables/garbagecollect",
"pod", pod.Name,
)

req, err := createKeySpaceRequest(pod, -1, keyspaceName, tables, "/api/v0/ops/tables/garbagecollect")
if err != nil {
return err
}

req.timeout = 60 * time.Second

_, err = callNodeMgmtEndpoint(client, *req, "application/json")
return err
}

0 comments on commit 8963678

Please sign in to comment.