Skip to content

Commit

Permalink
list-objects to report 'version-changed'
Browse files Browse the repository at this point in the history
* part three, prev. commit: 821eb0f

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Jan 12, 2024
1 parent a8f5dec commit 671558c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
7 changes: 4 additions & 3 deletions cmd/cli/cli/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ var (
Usage: "list also objects that were _not_ matched by regex and/or template (range)",
}
verChangedFlag = cli.BoolFlag{
Name: "check-version",
Name: "check-versions",
Usage: "check whether listed remote objects and their in-cluster copies are identical, ie., have the same versions\n" +
indent4 + "\t- applies to remote buckets only\n" +
indent4 + "\t- see related: 'ais get --latest', 'ais cp --sync', 'ais prefetch --latest'",
Expand Down Expand Up @@ -592,8 +592,9 @@ var (
Name: "latest",
Usage: "GET, prefetch, or copy the latest object version from the associated remote bucket;\n" +
indent1 + "\tprovides operation-level control over object versioning (and version synchronization)\n" +
indent1 + "\t_without_ requiring to change bucket configuration\n" +
indent1 + "\t(the latter can be done using 'ais bucket props set BUCKET versioning')",
indent1 + "\twithout requiring to change bucket configuration\n" +
indent1 + "\t- the latter can be done using 'ais bucket props set BUCKET versioning'\n" +
indent1 + "\t- see also: 'ais ls --check-versions', 'ais cp', 'ais prefetch', 'ais get'",
}
syncFlag = cli.BoolFlag{
Name: "sync",
Expand Down
20 changes: 15 additions & 5 deletions cmd/cli/cli/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ func listObjects(c *cli.Context, bck cmn.Bck, prefix string, listArch bool) erro
props = splitCsv(propsStr) // split apc.LsPropsSepa
}

// add _implied_ props into control lsmsg
if flagIsSet(c, nameOnlyFlag) {
if flagIsSet(c, verChangedFlag) {
return fmt.Errorf(errFmtExclusive, qflprn(verChangedFlag), qflprn(nameOnlyFlag))
Expand All @@ -327,8 +328,6 @@ func listObjects(c *cli.Context, bck cmn.Bck, prefix string, listArch bool) erro
msg.AddProps(apc.GetPropsName)
msg.AddProps(apc.GetPropsSize)
msg.SetFlag(apc.LsNameSize)
} else if flagIsSet(c, verChangedFlag) {
msg.AddProps(apc.GetPropsDefaultCloud...) // TODO: maybe too crude
} else {
msg.AddProps(apc.GetPropsMinimal...)
}
Expand All @@ -345,10 +344,21 @@ func listObjects(c *cli.Context, bck cmn.Bck, prefix string, listArch bool) erro
// (due to mirroring, EC). The status helps to tell an object from its replica(s).
msg.AddProps(apc.GetPropsStatus)
}
propsStr = msg.Props // show these and only these props
// and finally:
if flagIsSet(c, verChangedFlag) {
if !msg.WantProp(apc.GetPropsCustom) {
msg.AddProps(apc.GetPropsCustom)
}
if !msg.WantProp(apc.GetPropsVersion) {
msg.AddProps(apc.GetPropsVersion)
}
}

// set page
if flagIsSet(c, startAfterFlag) {
msg.StartAfter = parseStrFlag(c, startAfterFlag)
}

pageSize, limit, err := _setPage(c, bck)
if err != nil {
return err
Expand All @@ -372,7 +382,7 @@ func listObjects(c *cli.Context, bck cmn.Bck, prefix string, listArch bool) erro
} else {
toPrint = objList.Entries
}
err = printLso(c, toPrint, lstFilter, msg.Props,
err = printLso(c, toPrint, lstFilter, propsStr,
addCachedCol, bck.IsRemote(), msg.IsFlagSet(apc.LsVerChanged))
if err != nil {
return err
Expand Down Expand Up @@ -411,7 +421,7 @@ func listObjects(c *cli.Context, bck cmn.Bck, prefix string, listArch bool) erro
if err != nil {
return lsoErr(msg, err)
}
return printLso(c, objList.Entries, lstFilter, msg.Props,
return printLso(c, objList.Entries, lstFilter, propsStr,
addCachedCol, bck.IsRemote(), msg.IsFlagSet(apc.LsVerChanged))
}

Expand Down
6 changes: 3 additions & 3 deletions cmn/objattrs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Package cmn provides common constants, types, and utilities for AIS clients
// and AIStore.
/*
* Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
*/
package cmn

Expand Down Expand Up @@ -93,14 +93,14 @@ func (oa *ObjAttrs) SetSize(size int64) {

func CustomMD2S(md cos.StrKVs) string { return fmt.Sprintf("%+v", md) }

func S2CustomMD(custom string) (md cos.StrKVs) {
func S2CustomMD(custom, version string) (md cos.StrKVs) {
if len(custom) < 8 || !strings.HasPrefix(custom, "map[") { // Sprintf above
return nil
}
s := custom[4 : len(custom)-1]
lst := strings.Split(s, " ")
md = make(cos.StrKVs, len(lst))
parseCustom(md, lst, VersionObjMD)
md[VersionObjMD] = version
parseCustom(md, lst, SourceObjMD)
parseCustom(md, lst, CRC32CObjMD)
parseCustom(md, lst, MD5ObjMD)
Expand Down
8 changes: 6 additions & 2 deletions xact/xs/wanted_lso.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Package xs contains most of the supported eXtended actions (xactions) with some
// exceptions that include certain storage services (mirror, EC) and extensions (downloader, lru).
/*
* Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved.
*/
package xs

Expand Down Expand Up @@ -38,6 +38,10 @@ func wanted(msg *apc.LsoMsg) (flags cos.BitFlags) {
}

func (wi *walkInfo) setWanted(e *cmn.LsoEntry, lom *core.LOM) {
var (
custom = e.Custom
version = e.Version
)
for name, fl := range allmap {
if !wi.wanted.IsSet(fl) {
continue
Expand Down Expand Up @@ -81,7 +85,7 @@ func (wi *walkInfo) setWanted(e *cmn.LsoEntry, lom *core.LOM) {
//
// extensive version-changed check
//
md := cmn.S2CustomMD(e.Custom)
md := cmn.S2CustomMD(custom, version)
if len(md) > 0 {
var oa cmn.ObjAttrs
oa.CustomMD = md
Expand Down

0 comments on commit 671558c

Please sign in to comment.