Skip to content

Commit

Permalink
CLI: an option to remove zero size objects
Browse files Browse the repository at this point in the history
* as in: 'ais space-cleanup --rm-zero-size'
* separately, gitlab short 32m

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Nov 26, 2024
1 parent 44f77df commit d63e1c2
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 28 deletions.
10 changes: 5 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ include:
stage: test-short
tags:
- $RUNNER_TAG
timeout: 30m
timeout: 32m
<<: *default_only_def
except:
variables:
Expand All @@ -69,7 +69,7 @@ include:
stage: test-short
tags:
- $RUNNER_TAG
timeout: 30m
timeout: 32m
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == "main"'
when: manual
Expand All @@ -81,7 +81,7 @@ include:
stage: test-short
tags:
- $RUNNER_TAG
timeout: 30m
timeout: 32m
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule" || $CI_PIPELINE_SOURCE == "web"'
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == "main"'
Expand Down Expand Up @@ -500,12 +500,12 @@ test:short:python-etl:
script:
- cd python
- make python_etl_tests


# e.g. RE: "ETLBucket|ETLConnectionError|ETLInitCode" (or any other regex to select tests)
test:short:assorted:k8s:
extends: .test_k8s_short_template
timeout: 30m
timeout: 32m
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == "main"'
when: manual
Expand Down
5 changes: 2 additions & 3 deletions ais/tgtspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,11 @@ func (t *target) runSpaceCleanup(xargs *xact.ArgsMsg, wg *sync.WaitGroup) fs.Cap
t.bcastAsyncIC(msg)
}
ini := space.IniCln{
StatsT: t.statsT,
Xaction: xcln.(*space.XactCln),
Config: cmn.GCO.Get(),
StatsT: t.statsT,
Buckets: xargs.Buckets,
WG: wg,
Force: xargs.Force,
Args: xargs,
}
xcln.AddNotif(&xact.NotifXact{
Base: nl.Base{When: core.UponTerm, Dsts: []string{equalIC}, F: t.notifyTerm},
Expand Down
2 changes: 1 addition & 1 deletion ais/tgtxact.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (t *target) httpxput(w http.ResponseWriter, r *http.Request) {
}
return
}
// all other "startables"
// all other _startable_ xactions
xid, err := t.xstart(&xargs, bck, msg)
if err != nil {
t.writeErr(w, r, err)
Expand Down
10 changes: 7 additions & 3 deletions cmd/cli/cli/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
commandShow = "show"
)

// advanced command and subcommands
// 'ais advanced' subcommands
const (
cmdGenShards = "gen-shards"
cmdPreload = "preload"
Expand All @@ -50,6 +50,8 @@ const (
cmdRotateLogs = "rotate-logs"
)

const advancedUsageOnly = "(caution: advanced usage only)"

// - 2nd level subcommands (mostly, verbs)
// - show subcommands (`show <what>`)
// - 3rd level subcommands
Expand Down Expand Up @@ -502,6 +504,8 @@ var (
indent1 + "\t(tip: check 'ais config cluster lru.dont_evict_time' as well)",
}

rmZeroSizeFlag = cli.BoolFlag{Name: "rm-zero-size", Usage: "remove zero size objects " + advancedUsageOnly}

// units enum { unitsIEC, unitsSI, unitsRaw }
unitsFlag = cli.StringFlag{
Name: "units",
Expand Down Expand Up @@ -1059,11 +1063,11 @@ var (
}
nonElectableFlag = cli.BoolFlag{
Name: "non-electable",
Usage: "this proxy must not be elected as primary (advanced use)",
Usage: "this proxy must not be elected as primary " + advancedUsageOnly,
}
noRebalanceFlag = cli.BoolFlag{
Name: "no-rebalance",
Usage: "do _not_ run global rebalance after putting node in maintenance (caution: advanced usage only!)",
Usage: "do _not_ run global rebalance after putting node in maintenance " + advancedUsageOnly,
}
mountpathLabelFlag = cli.StringFlag{
Name: "label",
Expand Down
13 changes: 10 additions & 3 deletions cmd/cli/cli/storage_hdlr.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var (
{
Name: cmdMpathRescanDisks,
Usage: "re-resolve (mountpath, filesystem) to its underlying disk(s) and revalidate the disks\n" +
indent1 + "\t(advanced use only)",
indent1 + "\t" + advancedUsageOnly,
ArgsUsage: nodeMountpathPairArgument,
Flags: mpathCmdsFlags["default"],
Action: mpathRescanHandler,
Expand All @@ -112,12 +112,13 @@ var (
var (
cleanupFlags = []cli.Flag{
forceClnFlag,
rmZeroSizeFlag,
waitFlag,
waitJobXactFinishedFlag,
}
cleanupCmd = cli.Command{
Name: cmdStgCleanup,
Usage: "perform storage cleanup: remove deleted objects and old/obsolete workfiles",
Usage: "remove deleted objects and old/obsolete workfiles; remove misplaced objects; optionally, remove zero size objects",
ArgsUsage: listAnyCommandArgument,
Flags: cleanupFlags,
Action: cleanupStorageHandler,
Expand Down Expand Up @@ -229,8 +230,14 @@ func cleanupStorageHandler(c *cli.Context) (err error) {
}
}

force := flagIsSet(c, forceFlag)
// xargs
force := flagIsSet(c, forceClnFlag)
xargs := xact.ArgsMsg{Kind: apc.ActStoreCleanup, Bck: bck, Force: force}
if flagIsSet(c, rmZeroSizeFlag) {
xargs.Flags = xact.XrmZeroSize
}

// do
if id, err = api.StartXaction(apiBP, &xargs, ""); err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/NVIDIA/aistore/cmd/cli
go 1.23.2

require (
github.com/NVIDIA/aistore v1.3.26-0.20241119190643-7c6f3181bf9f
github.com/NVIDIA/aistore v1.3.26-0.20241126181423-44f77dfe5637
github.com/fatih/color v1.18.0
github.com/json-iterator/go v1.1.12
github.com/onsi/ginkgo/v2 v2.21.0
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
code.cloudfoundry.org/bytefmt v0.0.0-20190710193110-1eb035ffe2b6/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/NVIDIA/aistore v1.3.26-0.20241119190643-7c6f3181bf9f h1:+Cl8s4DwoXEX9XKqXZBvDt+Fhbv4zGcu8TFm9j9vujc=
github.com/NVIDIA/aistore v1.3.26-0.20241119190643-7c6f3181bf9f/go.mod h1:I3l9tS47EY4ODo7mQQGsFFrIjHa6mwnNRF4t1LXKCvA=
github.com/NVIDIA/aistore v1.3.26-0.20241126181423-44f77dfe5637 h1:mbCYjPrmGzEKSIWP3aS9mY2DhKb77Wbxmwk3ybM1TP0=
github.com/NVIDIA/aistore v1.3.26-0.20241126181423-44f77dfe5637/go.mod h1:/6lHPQptxjseMk9B2Zv3wcFkXsyZdr4YCsbfjzHe7r8=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ $ find . -type f -name "*.md" | xargs grep "ais.*mountpath"
```console
$ ais storage cleanup --help
NAME:
ais storage cleanup - perform storage cleanup: remove deleted objects and old/obsolete workfiles
ais storage cleanup - remove deleted objects and old/obsolete workfiles; remove misplaced objects; optionally, remove zero size objects

USAGE:
ais storage cleanup [command options] PROVIDER:[//BUCKET_NAME]

OPTIONS:
--force, -f disregard interrupted rebalance and possibly other conditions preventing full cleanup
(tip: check 'ais config cluster lru.dont_evict_time' as well)
--rm-zero-size remove zero-size objects (caution: advanced usage only)
--wait wait for an asynchronous operation to finish (optionally, use '--timeout' to limit the waiting time)
--timeout value maximum time to wait for a job to finish; if omitted: wait forever or until Ctrl-C;
valid time units: ns, us (or µs), ms, s (default), m, h
Expand Down
24 changes: 16 additions & 8 deletions space/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ import (

type (
IniCln struct {
StatsT stats.Tracker
Config *cmn.Config
Xaction *XactCln
StatsT stats.Tracker
Buckets []cmn.Bck // optional list of specific buckets to cleanup
WG *sync.WaitGroup
Force bool
Args *xact.ArgsMsg
}
XactCln struct {
xact.Base
Expand Down Expand Up @@ -209,10 +208,10 @@ func (p *clnP) rmMisplaced() bool {
why = g.Xact.String() + " is running"
case g.Interrupted:
why = "rebalance interrupted"
ok = p.ini.Force
ok = p.ini.Args.Force
case g.Restarted:
why = "node restarted"
ok = p.ini.Force
ok = p.ini.Args.Force
case l.Xact != nil:
why = l.Xact.String() + " is running"
case l.Interrupted:
Expand Down Expand Up @@ -241,7 +240,7 @@ func (j *clnJ) String() string {
sb.WriteString(j.ini.Xaction.String())
sb.WriteString(": jog-")
sb.WriteString(j.mi.String())
if j.ini.Force {
if j.ini.Args.Force {
sb.WriteString("-with-force")
}
return sb.String()
Expand All @@ -262,8 +261,8 @@ func (j *clnJ) run(providers []string) {
}

// traverse
if len(j.ini.Buckets) != 0 {
size, err = j.jogBcks(j.ini.Buckets)
if len(j.ini.Args.Buckets) != 0 {
size, err = j.jogBcks(j.ini.Args.Buckets)
} else {
size, err = j.jog(providers)
}
Expand Down Expand Up @@ -489,6 +488,15 @@ func (j *clnJ) visitObj(fqn string, lom *core.LOM) {
if lom.HasCopies() {
j.rmExtraCopies(lom)
}
if lom.Lsize() == 0 {
if j.ini.Args.Flags&xact.XrmZeroSize == xact.XrmZeroSize {
if ecode, err := core.T.DeleteObject(lom, false /*evict*/); err != nil {
nlog.Errorln("failed to remove zero-size", lom.Cname(), "err:", err, "code:", ecode)
} else {
nlog.Warningln("removed zero-size", lom.Cname())
}
}
}
return
}
if lom.IsCopy() {
Expand Down
2 changes: 2 additions & 0 deletions space/space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/NVIDIA/aistore/hk"
"github.com/NVIDIA/aistore/space"
"github.com/NVIDIA/aistore/tools/trand"
"github.com/NVIDIA/aistore/xact"
"github.com/NVIDIA/aistore/xact/xreg"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -360,6 +361,7 @@ func newInitStoreCln() *space.IniCln {
Xaction: xcln,
Config: cmn.GCO.Get(),
StatsT: mock.NewStatsTracker(),
Args: &xact.ArgsMsg{},
}
}

Expand Down
2 changes: 1 addition & 1 deletion xact/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const (

// ArgsMsg.Flags
const (
XrmZeroSize = 1 << iota
XrmZeroSize = 1 << iota // usage: x-cleanup (apc.ActStoreCleanup) to remove zero size objects
)

type (
Expand Down

0 comments on commit d63e1c2

Please sign in to comment.