Add --bucket-bandwidth flag to mc admin replicate update (#4687)

to allow default bucket bandwidth to be set in site replication
This commit is contained in:
Poorna
2023-10-23 15:46:02 -07:00
committed by GitHub
parent eb6f304e2e
commit 2c6ae7d1f7
2 changed files with 44 additions and 8 deletions
+21 -2
View File
@@ -18,8 +18,10 @@
package cmd
import (
"fmt"
"strings"
humanize "github.com/dustin/go-humanize"
"github.com/fatih/color"
"github.com/minio/cli"
json "github.com/minio/colorjson"
@@ -72,19 +74,36 @@ func (i srInfo) String() string {
Field{"Name", 15},
Field{"Endpoint", 46},
Field{"Sync", 4},
).buildRow("Deployment ID", "Site Name", "Endpoint", "Sync"))
Field{"Bandwidth", 10},
).buildRow("Deployment ID", "Site Name", "Endpoint", "Sync", "Bandwidth"))
messages = append(messages, r)
r = console.Colorize("THeaders", newPrettyTable(" | ",
Field{"Deployment ID", 36},
Field{"Name", 15},
Field{"Endpoint", 46},
Field{"Sync", 4},
Field{"Bandwidth", 10},
).buildRow("", "", "", "", "Per Bucket"))
messages = append(messages, r)
for _, peer := range info.Sites {
var chk string
if peer.SyncState == madmin.SyncEnabled {
chk = check
}
limit := "N/A" // N/A means cluster bandwidth is not configured
if peer.DefaultBandwidth.Limit > 0 {
limit = humanize.Bytes(uint64(peer.DefaultBandwidth.Limit * 8))
limit = fmt.Sprintf("%sb/s", limit[:len(limit)-1])
}
r := console.Colorize("TDetail", newPrettyTable(" | ",
Field{"Deployment ID", 36},
Field{"Name", 15},
Field{"Endpoint", 46},
Field{"Sync", 4},
).buildRow(peer.DeploymentID, peer.Name, peer.Endpoint, chk))
Field{"Bandwidth", 10},
).buildRow(peer.DeploymentID, peer.Name, peer.Endpoint, chk, limit))
messages = append(messages, r)
}
} else {
+23 -6
View File
@@ -48,7 +48,10 @@ var adminReplicateUpdateFlags = []cli.Flag{
Usage: "enable synchronous replication for this target, valid values are ['enable', 'disable'].",
Value: "disable",
Hidden: true, // deprecated Jul 2023
},
cli.StringFlag{
Name: "bucket-bandwidth",
Usage: "Set default bandwidth limit for bucket in bits per second (K,B,G,T for metric and Ki,Bi,Gi,Ti for IEC units)",
},
}
@@ -74,6 +77,9 @@ FLAGS:
EXAMPLES:
1. Edit a site endpoint participating in cluster-level replication:
{{.Prompt}} {{.HelpName}} myminio --deployment-id c1758167-4426-454f-9aae-5c3dfdf6df64 --endpoint https://minio2:9000
2. Edit a site in cluster-level replication to set default bandwidth limit for bucket:
{{.Prompt}} {{.HelpName}} myminio --deployment-id c1758167-4426-454f-9aae-5c3dfdf6df64 --bucket-bandwidth "2G"
`,
}
@@ -122,8 +128,8 @@ func mainAdminReplicateUpdate(ctx *cli.Context) error {
if !ctx.IsSet("deployment-id") {
fatalIf(errInvalidArgument(), "--deployment-id is a required flag")
}
if !ctx.IsSet("endpoint") && !ctx.IsSet("mode") && !ctx.IsSet("sync") {
fatalIf(errInvalidArgument(), "--endpoint or --mode is a required flag")
if !ctx.IsSet("endpoint") && !ctx.IsSet("mode") && !ctx.IsSet("sync") && !ctx.IsSet("bucket-bandwidth") {
fatalIf(errInvalidArgument(), "--endpoint, --mode or --bucket-bandwidth is a required flag")
}
if ctx.IsSet("mode") && ctx.IsSet("sync") {
fatalIf(errInvalidArgument(), "either --sync or --mode flag should be specified")
@@ -150,6 +156,16 @@ func mainAdminReplicateUpdate(ctx *cli.Context) error {
fatalIf(errInvalidArgument().Trace(args...), "--mode can be either [sync|async]")
}
}
var bwDefaults madmin.BucketBandwidth
if ctx.IsSet("bucket-bandwidth") {
bandwidthStr := ctx.String("bucket-bandwidth")
bandwidth, e := getBandwidthInBytes(bandwidthStr)
fatalIf(probe.NewError(e).Trace(bandwidthStr), "invalid bandwidth value")
bwDefaults.Limit = bandwidth
bwDefaults.IsSet = true
}
var ep string
if ctx.IsSet("endpoint") {
parsedURL := ctx.String("endpoint")
@@ -160,9 +176,10 @@ func mainAdminReplicateUpdate(ctx *cli.Context) error {
ep = u.String()
}
res, e := client.SiteReplicationEdit(globalContext, madmin.PeerInfo{
DeploymentID: ctx.String("deployment-id"),
Endpoint: ep,
SyncState: madmin.SyncStatus(syncState),
DeploymentID: ctx.String("deployment-id"),
Endpoint: ep,
SyncState: madmin.SyncStatus(syncState),
DefaultBandwidth: bwDefaults,
})
fatalIf(probe.NewError(e).Trace(args...), "Unable to edit cluster replication site endpoint")