-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebalance.go
117 lines (99 loc) · 3.26 KB
/
rebalance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// MinIO Inc [madmin-go]
// Copyright (c) 2014-2025 MinIO.
// All rights reserved. No warranty, explicit or implicit, provided.
//
package madmin
import (
"context"
"encoding/json"
"io"
"net/http"
"time"
)
// RebalPoolProgress contains metrics like number of objects, versions, etc rebalanced so far.
type RebalPoolProgress struct {
NumObjects uint64 `json:"objects"`
NumVersions uint64 `json:"versions"`
Bytes uint64 `json:"bytes"`
Bucket string `json:"bucket"`
Object string `json:"object"`
Elapsed time.Duration `json:"elapsed"`
ETA time.Duration `json:"eta"`
}
// RebalancePoolStatus contains metrics of a rebalance operation on a given pool
type RebalancePoolStatus struct {
ID int `json:"id"` // Pool index (zero-based)
Status string `json:"status"` // Active if rebalance is running, empty otherwise
Used float64 `json:"used"` // Percentage used space
Progress RebalPoolProgress `json:"progress,omitempty"` // is empty when rebalance is not running
}
// RebalanceStatus contains metrics and progress related information on all pools
type RebalanceStatus struct {
ID string // identifies the ongoing rebalance operation by a uuid
StoppedAt time.Time `json:"stoppedAt,omitempty"`
Pools []RebalancePoolStatus `json:"pools"` // contains all pools, including inactive
}
// RebalanceStart starts a rebalance operation if one isn't in progress already
func (adm *AdminClient) RebalanceStart(ctx context.Context) (id string, err error) {
// Execute POST on /minio/admin/v3/rebalance/start to start a rebalance operation.
var resp *http.Response
resp, err = adm.executeMethod(ctx,
http.MethodPost,
requestData{relPath: adminAPIPrefix + "/rebalance/start"})
defer closeResponse(resp)
if err != nil {
return id, err
}
if resp.StatusCode != http.StatusOK {
return id, httpRespToErrorResponse(resp)
}
var rebalInfo struct {
ID string `json:"id"`
}
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return id, err
}
err = json.Unmarshal(respBytes, &rebalInfo)
if err != nil {
return id, err
}
return rebalInfo.ID, nil
}
func (adm *AdminClient) RebalanceStatus(ctx context.Context) (r RebalanceStatus, err error) {
// Execute GET on /minio/admin/v3/rebalance/status to get status of an ongoing rebalance operation.
resp, err := adm.executeMethod(ctx,
http.MethodGet,
requestData{relPath: adminAPIPrefix + "/rebalance/status"})
defer closeResponse(resp)
if err != nil {
return r, err
}
if resp.StatusCode != http.StatusOK {
return r, httpRespToErrorResponse(resp)
}
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return r, err
}
err = json.Unmarshal(respBytes, &r)
if err != nil {
return r, err
}
return r, nil
}
func (adm *AdminClient) RebalanceStop(ctx context.Context) error {
// Execute POST on /minio/admin/v3/rebalance/stop to stop an ongoing rebalance operation.
resp, err := adm.executeMethod(ctx,
http.MethodPost,
requestData{relPath: adminAPIPrefix + "/rebalance/stop"})
defer closeResponse(resp)
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK {
return httpRespToErrorResponse(resp)
}
return nil
}