Skip to content

Commit

Permalink
RHINENG-10032: extend repack admin API with columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Dugowitch authored and psegedy committed Sep 12, 2024
1 parent a7fdd22 commit 34a6037
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
16 changes: 12 additions & 4 deletions docs/admin/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@
},
"/repack/{table_name}": {
"get": {
"summary": "Reindex DB with pg_repack",
"description": "Reindex DB with pg_repack",
"summary": "Reindex and cluster DB with pg_repack",
"description": "Reindex the table from `table_name`. If `columns` are provided, clustering is performed as well.",
"operationId": "repack",
"parameters": [
{
Expand All @@ -371,6 +371,14 @@
"schema": {
"type": "string"
}
},
{
"name": "columns",
"in": "query",
"description": "Comma-separated columns to cluster by (optional)",
"schema": {
"type": "string"
}
}
],
"responses": {
Expand All @@ -384,8 +392,8 @@
}
}
},
"409": {
"description": "Conflict",
"400": {
"description": "Bad Request",
"content": {
"application/json": {
"schema": {
Expand Down
22 changes: 15 additions & 7 deletions turnpike/controllers/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"net/http"
"regexp"
"strconv"
"time"

Expand Down Expand Up @@ -199,27 +200,34 @@ func TerminateSessionHandler(c *gin.Context) {
c.JSON(http.StatusOK, fmt.Sprintf("pid: %s terminated", param))
}

// @Summary Reindex DB with pg_repack
// @Description Reindex DB with pg_repack
// @Summary Reindex and cluster DB with pg_repack
// @Description Reindex the table from `table_name`. If `columns` are provided, clustering is performed as well.
// @ID repack
// @Security RhIdentity
// @Accept json
// @Produce json
// @Param table_name path string true "Table to reindex"
// @Param columns query string false "Comma-separated columns to cluster by (optional)"
// @Success 200 {object} string
// @Failure 409 {object} string
// @Failure 400 {object} string
// @Failure 500 {object} map[string]interface{}
// @Router /repack/{table_name} [get]
func RepackHandler(c *gin.Context) {
utils.LogInfo("manual repack called...")

param := c.Param("table_name")
if param == "" {
c.JSON(http.StatusBadRequest, utils.ErrorResponse{Error: "table_name param not found"})
tableName := c.Param("table_name")
if ok, _ := regexp.MatchString(`^\w+$`, tableName); !ok {
c.JSON(http.StatusBadRequest, utils.ErrorResponse{Error: "invalid table_name"})
return
}

columns := c.Query("columns")
if ok, _ := regexp.MatchString(`^[\w,]*$`, columns); !ok {
c.JSON(http.StatusBadRequest, utils.ErrorResponse{Error: "invalid columns"})
return
}

err := repack.Repack(param)
err := repack.Repack(tableName, columns)
if err != nil {
utils.LogError("err", err.Error(), "manual repack call failed")
c.JSON(http.StatusInternalServerError, gin.H{"err": err.Error()})
Expand Down

0 comments on commit 34a6037

Please sign in to comment.