diff --git a/docs/admin/openapi.json b/docs/admin/openapi.json index ff37d47e5..4b837b2bf 100644 --- a/docs/admin/openapi.json +++ b/docs/admin/openapi.json @@ -357,10 +357,10 @@ ] } }, - "/repack/{table_name}": { + "/repack/{table_name}/{columns}": { "get": { - "summary": "Reindex DB with pg_repack", - "description": "Reindex DB with pg_repack", + "summary": "Reindex and cluster DB with pg_repack", + "description": "Reindex and cluster DB with pg_repack", "operationId": "repack", "parameters": [ { @@ -371,6 +371,15 @@ "schema": { "type": "string" } + }, + { + "name": "columns", + "in": "path", + "description": "Comma-separated columns to cluster by (optional)", + "required": true, + "schema": { + "type": "string" + } } ], "responses": { diff --git a/manager/routes/routes.go b/manager/routes/routes.go index 7dfed261b..ac9350893 100644 --- a/manager/routes/routes.go +++ b/manager/routes/routes.go @@ -113,7 +113,7 @@ func InitAdmin(app *gin.Engine, enableTurnpikeAuth bool) { api.GET("/sessions", admin.GetActiveSessionsHandler) api.GET("/sessions/:search", admin.GetActiveSessionsHandler) api.DELETE("/sessions/:pid", admin.TerminateSessionHandler) - api.GET("/repack/:table_name", admin.RepackHandler) + api.GET("/repack/:table_name/*columns", admin.RepackHandler) pprof := api.Group("/pprof") pprof.GET("/evaluator_upload/:param", admin.GetEvaluatorUploadPprof) diff --git a/turnpike/controllers/admin.go b/turnpike/controllers/admin.go index 950c8963e..22bf2fcab 100644 --- a/turnpike/controllers/admin.go +++ b/turnpike/controllers/admin.go @@ -199,27 +199,29 @@ 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 not omitted, cluster gets performed too. // @ID repack // @Security RhIdentity // @Accept json // @Produce json // @Param table_name path string true "Table to reindex" +// @Param columns path string false "Comma-separated columns to cluster by (optional)" // @Success 200 {object} string // @Failure 409 {object} string // @Failure 500 {object} map[string]interface{} -// @Router /repack/{table_name} [get] +// @Router /repack/{table_name}/{columns} [get] func RepackHandler(c *gin.Context) { utils.LogInfo("manual repack called...") - param := c.Param("table_name") - if param == "" { + tableName := c.Param("table_name") + if tableName == "" { c.JSON(http.StatusBadRequest, utils.ErrorResponse{Error: "table_name param not found"}) return } + columns := c.Param("columns") - err := repack.Repack(param) + err := repack.Repack(tableName, columns[1:]) // skip the initial '/' if err != nil { utils.LogError("err", err.Error(), "manual repack call failed") c.JSON(http.StatusInternalServerError, gin.H{"err": err.Error()})