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 committed Sep 11, 2024
1 parent 13d04f0 commit 3a7030f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
15 changes: 12 additions & 3 deletions docs/admin/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion manager/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions turnpike/controllers/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()})
Expand Down

0 comments on commit 3a7030f

Please sign in to comment.