Skip to content

Commit 785a1b7

Browse files
committed
cli: 'start rebalance [--cleanup]' to show ID; add formatted action helpers
* report the started rebalance ID - both regular and cleanup mode * add formatted action helpers and replace repeated fmt.Sprintf wrappers around actionDone/actionWarn calls Signed-off-by: Alex Aizman <alex.aizman@gmail.com>
1 parent 0cab3b8 commit 785a1b7

13 files changed

Lines changed: 65 additions & 42 deletions

cmd/cli/cli/cluster_hdlr.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ func psetForce(c *cli.Context, pid, sname, toURL string) error {
645645
if toURL != "" {
646646
s = " (at " + toURL + ")"
647647
}
648-
actionDone(c, fmt.Sprintf("%s%s is now a new primary (set with force)", sname, s))
648+
actionDonef(c, "%s%s is now a new primary (set with force)", sname, s)
649649
return nil
650650
}
651651

@@ -658,7 +658,13 @@ func startRebHandler(c *cli.Context) (err error) {
658658
xargs := xact.ArgsMsg{Kind: apc.ActRebalance}
659659

660660
cleanup := flagIsSet(c, rebalanceCleanupModeFlag)
661-
if cleanup && flagIsSet(c, rebalanceForceFlag) {
661+
662+
// --force is meaningful only in cleanup mode. Without it, an object whose HRW peer
663+
// has a diverged copy (size/checksum/version mismatch) is kept locally; with it,
664+
// the local (misplaced) copy is removed.
665+
// See reb/cleanup.go (keepDiverged vs removeDiverged).
666+
667+
if !cleanup && flagIsSet(c, rebalanceForceFlag) {
662668
return fmt.Errorf("%s is only valid with %s", qflprn(rebalanceForceFlag), qflprn(rebalanceCleanupModeFlag))
663669
}
664670
if cleanup {
@@ -739,7 +745,7 @@ func stopReb(c *cli.Context, xid string) error {
739745
if err := xstop(&xargs); err != nil {
740746
return V(err)
741747
}
742-
actionDone(c, fmt.Sprintf("Stopped %s[%s]\n", apc.ActRebalance, xid))
748+
actionDonef(c, "Stopped %s[%s]\n", apc.ActRebalance, xid)
743749
return nil
744750
}
745751

cmd/cli/cli/etl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ func etlObjectHandler(c *cli.Context) error {
844844
cos.Close(wfh)
845845
if err != nil {
846846
if e := cos.RemoveFile(outputDest); e != nil {
847-
actionWarn(c, fmt.Sprintf("failed to delete %s: %v", outputDest, e))
847+
actionWarnf(c, "failed to delete %s: %v", outputDest, e)
848848
}
849849
}
850850
}

cmd/cli/cli/flag.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ func parseRetriesFlag(c *cli.Context, flag cli.IntFlag, warn bool) (retries int)
186186
retries = parseIntFlag(c, flag)
187187
if retries < 0 {
188188
if warn {
189-
actionWarn(c, fmt.Sprintf(efmt, flprn(flag), retries))
189+
actionWarnf(c, efmt, flprn(flag), retries)
190190
}
191191
return 0
192192
}
193193
if retries > maxr {
194194
if warn {
195-
actionWarn(c, fmt.Sprintf(efmt, flprn(flag), retries))
195+
actionWarnf(c, efmt, flprn(flag), retries)
196196
}
197197
return maxr
198198
}

cmd/cli/cli/job_do_hdlr.go

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -473,17 +473,22 @@ func startXaction(c *cli.Context, xargs *xact.ArgsMsg, extra string) error {
473473

474474
switch xargs.Kind {
475475
case apc.ActRebalance:
476-
actionDone(c, "Started global rebalance. To monitor the progress, run 'ais show rebalance'")
476+
var s string
477+
if xargs.Flags&xact.FlagRemoveMisplaced != 0 {
478+
s = " (cleanup mode)"
479+
}
480+
actionDonef(c, "Started rebalance[%s]%s. To monitor the progress, run 'ais show rebalance'", xid, s)
481+
477482
case apc.ActResilver:
478483
const add = " To monitor the progress, run 'ais show job " + apc.ActResilver + "'"
479484
var s string
480485
if xid != "" {
481486
s = "[" + xid + "]"
482487
}
483488
if xargs.DaemonID != "" {
484-
actionDone(c, fmt.Sprintf("Started %s%s on %s."+add, apc.ActResilver, s, meta.Tname(xargs.DaemonID)))
489+
actionDonef(c, "Started %s%s on %s."+add, apc.ActResilver, s, meta.Tname(xargs.DaemonID))
485490
} else {
486-
actionDone(c, fmt.Sprintf("Started %s%s simultaneously on all targets."+add, apc.ActResilver, s))
491+
actionDonef(c, "Started %s%s simultaneously on all targets."+add, apc.ActResilver, s)
487492
}
488493
default:
489494
actionX(c, xargs, "")
@@ -792,9 +797,9 @@ func newHFDownloadJobDef(c *cli.Context, req *downloadRequest) (*HFDownloadJobDe
792797
}
793798

794799
if isDataset {
795-
actionDone(c, fmt.Sprintf("Found %d parquet files in dataset '%s'", len(files), identifier))
800+
actionDonef(c, "Found %d parquet files in dataset '%s'", len(files), identifier)
796801
} else {
797-
actionDone(c, fmt.Sprintf("Found %d files in model '%s'", len(files), identifier))
802+
actionDonef(c, "Found %d files in model '%s'", len(files), identifier)
798803
}
799804

800805
return &HFDownloadJobDef{
@@ -1034,7 +1039,7 @@ func singleJobProgress(c *cli.Context, id string) error {
10341039
func checkJobCompletion(c *cli.Context, jobID string, completed map[string]struct{}) {
10351040
resp, err := api.DownloadStatus(apiBP, jobID, false /*onlyActive*/)
10361041
if err != nil {
1037-
actionWarn(c, fmt.Sprintf("Failed to check status for job %s: %v", jobID, err))
1042+
actionWarnf(c, "Failed to check status for job %s: %v", jobID, err)
10381043
return
10391044
}
10401045

@@ -1177,7 +1182,7 @@ func stopJobHandler(c *cli.Context) error {
11771182
if warn != "" {
11781183
switch {
11791184
case xid != "":
1180-
actionWarn(c, fmt.Sprintf("ignoring %s in presence of %s argument ('%s')", warn, jobIDArgument, xid))
1185+
actionWarnf(c, "ignoring %s in presence of %s argument ('%s')", warn, jobIDArgument, xid)
11811186
case name == commandRebalance:
11821187
actionWarn(c, "global rebalance is _global_ - ignoring"+warn)
11831188
case regex != "" && name != cmdDownload && name != cmdDsort:
@@ -1292,7 +1297,7 @@ func stopJobHandler(c *cli.Context) error {
12921297
if err := xstop(&args); err != nil {
12931298
return err
12941299
}
1295-
actionDone(c, fmt.Sprintf("Stopped %s\n", msg))
1300+
actionDonef(c, "Stopped %s\n", msg)
12961301
return nil
12971302
}
12981303

@@ -1308,7 +1313,7 @@ func stopXactionKindOrAll(c *cli.Context, xactKind, xname string, bck cmn.Bck) e
13081313
if xname != "" {
13091314
what = " '" + xname + "'"
13101315
}
1311-
actionDone(c, fmt.Sprintf("No running%s jobs, nothing to do", what))
1316+
actionDonef(c, "No running%s jobs, nothing to do", what)
13121317
return nil
13131318
}
13141319
for _, cname := range cnames {
@@ -1319,7 +1324,7 @@ func stopXactionKindOrAll(c *cli.Context, xactKind, xname string, bck cmn.Bck) e
13191324
}
13201325
args := xact.ArgsMsg{ID: xactID, Kind: xactKind, Bck: bck}
13211326
if err := xstop(&args); err != nil {
1322-
actionWarn(c, fmt.Sprintf("failed to stop %s: %v", cname, err))
1327+
actionWarnf(c, "failed to stop %s: %v", cname, err)
13231328
} else {
13241329
actionDone(c, "Stopped "+cname)
13251330
}
@@ -1357,7 +1362,7 @@ func stopDownloadRegex(c *cli.Context, regex string) error {
13571362
actionDone(c, "Stopped download job "+dl.ID)
13581363
cnt++
13591364
} else {
1360-
actionWarn(c, fmt.Sprintf("failed to stop download job %q: %v", dl.ID, err))
1365+
actionWarnf(c, "failed to stop download job %q: %v", dl.ID, err)
13611366
}
13621367
}
13631368
if err != nil {
@@ -1373,7 +1378,7 @@ func stopDownloadHandler(c *cli.Context, id string) (err error) {
13731378
if err = api.AbortDownload(apiBP, id); err != nil {
13741379
return
13751380
}
1376-
actionDone(c, fmt.Sprintf("Stopped download job %s\n", id))
1381+
actionDonef(c, "Stopped download job %s\n", id)
13771382
return
13781383
}
13791384

@@ -1390,7 +1395,7 @@ func stopDsortRegex(c *cli.Context, regex string) error {
13901395
actionDone(c, "Stopped dsort job "+dsort.ID)
13911396
cnt++
13921397
} else {
1393-
actionWarn(c, fmt.Sprintf("failed to stop dsort job %q: %v", dsort.ID, err))
1398+
actionWarnf(c, "failed to stop dsort job %q: %v", dsort.ID, err)
13941399
}
13951400
}
13961401
if err != nil {
@@ -1406,7 +1411,7 @@ func stopDsortHandler(c *cli.Context, id string) (err error) {
14061411
if err = api.AbortDsort(apiBP, id); err != nil {
14071412
return
14081413
}
1409-
actionDone(c, fmt.Sprintf("Stopped dsort job %s\n", id))
1414+
actionDonef(c, "Stopped dsort job %s\n", id)
14101415
return
14111416
}
14121417

@@ -1428,7 +1433,7 @@ func waitJobHandler(c *cli.Context) error {
14281433
return missingArgumentsError(c, c.Command.ArgsUsage)
14291434
}
14301435
if daemonID != "" {
1431-
actionWarn(c, fmt.Sprintf("node ID %q will be ignored (waiting for a single target not supported)\n", daemonID))
1436+
actionWarnf(c, "node ID %q will be ignored (waiting for a single target not supported)\n", daemonID)
14321437
}
14331438

14341439
if name == "" && xid != "" {
@@ -1655,7 +1660,7 @@ func removeDownloadHandler(c *cli.Context) error {
16551660
if err := api.RemoveDownload(apiBP, id); err != nil {
16561661
return V(err)
16571662
}
1658-
actionDone(c, fmt.Sprintf("Removed finished download job %q", id))
1663+
actionDonef(c, "Removed finished download job %q", id)
16591664
return nil
16601665
}
16611666

@@ -1672,10 +1677,10 @@ func removeDownloadRegex(c *cli.Context, regex string) error {
16721677
}
16731678
err = api.RemoveDownload(apiBP, dl.ID)
16741679
if err == nil {
1675-
actionDone(c, fmt.Sprintf("Removed download job %q", dl.ID))
1680+
actionDonef(c, "Removed download job %q", dl.ID)
16761681
cnt++
16771682
} else {
1678-
actionWarn(c, fmt.Sprintf("failed to remove download job %q: %v", dl.ID, err))
1683+
actionWarnf(c, "failed to remove download job %q: %v", dl.ID, err)
16791684
}
16801685
}
16811686
if err != nil {
@@ -1705,7 +1710,7 @@ func removeDsortHandler(c *cli.Context) error {
17051710
return V(err)
17061711
}
17071712

1708-
actionDone(c, fmt.Sprintf("Removed finished dsort job %q", id))
1713+
actionDonef(c, "Removed finished dsort job %q", id)
17091714
return nil
17101715
}
17111716

@@ -1722,10 +1727,10 @@ func removeDsortRegex(c *cli.Context, regex string) error {
17221727
}
17231728
err = api.RemoveDsort(apiBP, dsort.ID)
17241729
if err == nil {
1725-
actionDone(c, fmt.Sprintf("Removed dsort job %q", dsort.ID))
1730+
actionDonef(c, "Removed dsort job %q", dsort.ID)
17261731
cnt++
17271732
} else {
1728-
actionWarn(c, fmt.Sprintf("failed to remove dsort job %q: %v", dsort.ID, err))
1733+
actionWarnf(c, "failed to remove dsort job %q: %v", dsort.ID, err)
17291734
}
17301735
}
17311736
if err != nil {

cmd/cli/cli/multiobj.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func evictBuckets(c *cli.Context, buckets []cmn.Bck) error {
347347
var evicted int
348348
for _, bck := range buckets {
349349
if err := evictBucket(c, bck); err != nil {
350-
actionWarn(c, fmt.Sprintf("failed to evict %s: %v", bck.Cname(""), err))
350+
actionWarnf(c, "failed to evict %s: %v", bck.Cname(""), err)
351351
continue
352352
}
353353
evicted++

cmd/cli/cli/multipart.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func uploadFileInChunks(c *cli.Context, filePath string, fileSize, chunkSize int
150150
return err
151151
}
152152

153-
actionDone(c, fmt.Sprintf("PUT in chunks %q => %s\n", filePath, bck.Cname(objName)))
153+
actionDonef(c, "PUT in chunks %q => %s\n", filePath, bck.Cname(objName))
154154

155155
return nil
156156
}

cmd/cli/cli/multipart_hdlr.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ func mptPutHandler(c *cli.Context) error {
154154
return fmt.Errorf("failed to upload part %d: %v", partNumber, err)
155155
}
156156

157-
actionDone(c, fmt.Sprintf("Uploaded part %d for %s (upload ID: %s)",
158-
partNumber, bck.Cname(objName), uploadID))
157+
actionDonef(c, "Uploaded part %d for %s (upload ID: %s)", partNumber, bck.Cname(objName), uploadID)
159158
return nil
160159
}
161160

cmd/cli/cli/nbi_hdlr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func createNBIHandler(c *cli.Context) error {
155155
return V(err)
156156
}
157157

158-
actionDone(c, fmt.Sprintf("Creating inventory %s. %s", bck.Cname(""), toMonitorMsg(c, xid, "")))
158+
actionDonef(c, "Creating inventory %s. %s", bck.Cname(""), toMonitorMsg(c, xid, ""))
159159
return nil
160160
}
161161

@@ -192,7 +192,7 @@ func removeNBIHandler(c *cli.Context) error {
192192
return V(err)
193193
}
194194

195-
actionDone(c, fmt.Sprintf("Removed inventory%s for bucket %s", s, bck.String()))
195+
actionDonef(c, "Removed inventory%s for bucket %s", s, bck.String())
196196
return nil
197197
}
198198

cmd/cli/cli/object.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func copyObject(c *cli.Context, bckFrom cmn.Bck, objFrom string, bckTo cmn.Bck,
145145
if objTo == "" {
146146
objTo = objFrom
147147
}
148-
actionDone(c, fmt.Sprintf("COPY %s => %s", bckFrom.Cname(objFrom), bckTo.Cname(objTo)))
148+
actionDonef(c, "COPY %s => %s", bckFrom.Cname(objFrom), bckTo.Cname(objTo))
149149
}
150150
return
151151
}

cmd/cli/cli/object_hdlr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ func putStdin(c *cli.Context, a *putargs) error {
559559
if err := putAppendChunks(c, a.dst.bck, encDstName, os.Stdin, cksum.Type(), chunkSize); err != nil {
560560
return err
561561
}
562-
actionDone(c, fmt.Sprintf("PUT (standard input) => %s\n", a.dst.bck.Cname(a.dst.oname)))
562+
actionDonef(c, "PUT (standard input) => %s\n", a.dst.bck.Cname(a.dst.oname))
563563
return nil
564564
}
565565

0 commit comments

Comments
 (0)