Skip to content

Commit

Permalink
[API change] get-bucket-info to support prefix option
Browse files Browse the repository at this point in the history
* e.g.: 'ais ls ais://nnn --summary --prefix=aaa/bbb'

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Jun 18, 2024
1 parent 59719f6 commit 56935d4
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 17 deletions.
16 changes: 10 additions & 6 deletions ais/htrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,21 @@ func (h *htrun) parseReq(w http.ResponseWriter, r *http.Request, apireq *apiRequ
debug.Assert(len(apireq.prefix) != 0)
apireq.items, err = h.parseURL(w, r, apireq.prefix, apireq.after, false)
if err != nil {
return
return err
}
debug.Assert(len(apireq.items) > apireq.bckIdx)
bckName := apireq.items[apireq.bckIdx]
if apireq.dpq == nil {

if apireq.dpq != nil {
if err = apireq.dpq.parse(r.URL.RawQuery); err != nil {
h.writeErr(w, r, err)
return err
}
} else {
apireq.query = r.URL.Query()
} else if err = apireq.dpq.parse(r.URL.RawQuery); err != nil {
return
}
apireq.bck, err = newBckFromQ(bckName, apireq.query, apireq.dpq)
if err != nil {

if apireq.bck, err = newBckFromQ(bckName, apireq.query, apireq.dpq); err != nil {
h.writeErr(w, r, err)
}
return err
Expand Down
23 changes: 22 additions & 1 deletion ais/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1856,8 +1856,23 @@ func (p *proxy) httpobjpost(w http.ResponseWriter, r *http.Request, apireq *apiR
}
}

// HEAD /v1/buckets/bucket-name
// HEAD /v1/buckets/bucket-name[/prefix]
// with additional preparsing step to support api.GetBucketInfo prefix (as in: ais ls --summary)
func (p *proxy) httpbckhead(w http.ResponseWriter, r *http.Request, apireq *apiRequest) {
var prefix string

// preparse
if items, err := p.parseURL(w, r, apireq.prefix, apireq.after, true); err == nil {
debug.Assert(apireq.bckIdx == 0, "expecting bucket name at idx = 0")
if len(items) > 1 {
prefix = items[1]
for _, s := range items[2:] {
prefix += "/" + s
}
apireq.after = 2
}
}

err := p.parseReq(w, r, apireq)
if err != nil {
return
Expand All @@ -1883,11 +1898,17 @@ func (p *proxy) httpbckhead(w http.ResponseWriter, r *http.Request, apireq *apiR
if dpq.binfo != "" { // QparamBinfoWithOrWithoutRemote
msg = apc.BsummCtrlMsg{
UUID: dpq.uuid,
Prefix: prefix,
ObjCached: !cos.IsParseBool(dpq.binfo),
BckPresent: apc.IsFltPresent(fltPresence),
DontAddRemote: dpq.dontAddRemote,
}
bckArgs.dontAddRemote = msg.DontAddRemote
} else if prefix != "" {
err := fmt.Errorf("invalid URL '%s': expecting just the bucket name, got '%s' and '%s'",
r.URL.Path, apireq.bck.Name, prefix)
p.writeErr(w, r, err)
return
}
bckArgs.createAIS = false

Expand Down
6 changes: 3 additions & 3 deletions ais/test/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func TestGetBucketInfo(t *testing.T) {
isPresent bool
)
if bck.IsRemote() {
_, _, _, err := api.GetBucketInfo(baseParams, bck, api.BinfoArgs{FltPresence: apc.FltPresent})
_, _, _, err := api.GetBucketInfo(baseParams, bck, &api.BinfoArgs{FltPresence: apc.FltPresent})
isPresent = err == nil
}
for _, fltPresence := range fltPresentEnum {
Expand All @@ -219,7 +219,7 @@ func TestGetBucketInfo(t *testing.T) {
args.WithRemote = bck.IsRemote()
}

xid, props, info, err := api.GetBucketInfo(baseParams, bck, args)
xid, props, info, err := api.GetBucketInfo(baseParams, bck, &args)
if err != nil {
if herr := cmn.Str2HTTPErr(err.Error()); herr != nil {
tlog.Logln(herr.TypeCode + ": " + herr.Message)
Expand All @@ -246,7 +246,7 @@ func TestGetBucketInfo(t *testing.T) {
tlog.Logln("")
}
if bck.IsRemote() {
_, _, _, err := api.GetBucketInfo(baseParams, bck, api.BinfoArgs{FltPresence: apc.FltPresent})
_, _, _, err := api.GetBucketInfo(baseParams, bck, &api.BinfoArgs{FltPresence: apc.FltPresent})
isPresentEnd := err == nil
tassert.Errorf(t, isPresent == isPresentEnd, "presence in the beginning (%t) != (%t) at the end",
isPresent, isPresentEnd)
Expand Down
11 changes: 8 additions & 3 deletions api/bsumm.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type (
BinfoArgs struct {
BsummArgs
UUID string
Prefix string
FltPresence int
Summarize bool
WithRemote bool
Expand All @@ -47,7 +48,7 @@ type (
// - is obtained via GetBucketInfo() API
// - and delivered via apc.HdrBucketInfo header (compare with GetBucketSummary)
// The API uses http.MethodHead and can be considered an extension of HeadBucket (above)
func GetBucketInfo(bp BaseParams, bck cmn.Bck, args BinfoArgs) (string, *cmn.Bprops, *cmn.BsummResult, error) {
func GetBucketInfo(bp BaseParams, bck cmn.Bck, args *BinfoArgs) (string, *cmn.Bprops, *cmn.BsummResult, error) {
q := make(url.Values, 4)
q = bck.AddToQuery(q)
q.Set(apc.QparamFltPresence, strconv.Itoa(args.FltPresence))
Expand All @@ -65,7 +66,11 @@ func GetBucketInfo(bp BaseParams, bck cmn.Bck, args BinfoArgs) (string, *cmn.Bpr
reqParams := AllocRp()
{
reqParams.BaseParams = bp
reqParams.Path = apc.URLPathBuckets.Join(bck.Name)
if args.Prefix != "" {
reqParams.Path = apc.URLPathBuckets.Join(bck.Name, args.Prefix)
} else {
reqParams.Path = apc.URLPathBuckets.Join(bck.Name)
}
reqParams.Query = q
}
xid, p, info, err := _binfo(reqParams, bck, args)
Expand All @@ -75,7 +80,7 @@ func GetBucketInfo(bp BaseParams, bck cmn.Bck, args BinfoArgs) (string, *cmn.Bpr

// compare w/ _bsumm
// TODO: _binfoDontWait w/ ref
func _binfo(reqParams *ReqParams, bck cmn.Bck, args BinfoArgs) (xid string, p *cmn.Bprops, info *cmn.BsummResult, err error) {
func _binfo(reqParams *ReqParams, bck cmn.Bck, args *BinfoArgs) (xid string, p *cmn.Bprops, info *cmn.BsummResult, err error) {
var (
hdr http.Header
status int
Expand Down
3 changes: 2 additions & 1 deletion cmd/cli/cli/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func listBckTableWithSummary(c *cli.Context, qbck cmn.QueryBcks, bcks cmn.Bcks,
// because api.BinfoArgs (left) contains api.BsummArgs (right)
args.CallAfter = ctx.args.CallAfter
args.Callback = ctx.args.Callback
args.Prefix = prefix

// one at a time
prev := ctx.started
Expand All @@ -161,7 +162,7 @@ func listBckTableWithSummary(c *cli.Context, qbck cmn.QueryBcks, bcks cmn.Bcks,
continue
}
ctx.qbck = cmn.QueryBcks(bck)
xid, props, info, err := api.GetBucketInfo(apiBP, bck, args)
xid, props, info, err := api.GetBucketInfo(apiBP, bck, &args)
if err != nil {
var partial bool
if herr, ok := err.(*cmn.ErrHTTP); ok {
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.22.3

require (
github.com/NVIDIA/aistore v1.3.24-0.20240614190157-f337216fc28b
github.com/NVIDIA/aistore v1.3.24-0.20240618150949-10e2b1b379b1
github.com/fatih/color v1.17.0
github.com/json-iterator/go v1.1.12
github.com/onsi/ginkgo/v2 v2.19.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.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/NVIDIA/aistore v1.3.24-0.20240614190157-f337216fc28b h1:qP6vNJQbNpwnMXnH5wVTaL5Pp6I7NBrc1+X/trZ/bsw=
github.com/NVIDIA/aistore v1.3.24-0.20240614190157-f337216fc28b/go.mod h1:rzuE/hzSFxylpF5sfawzy1DPnkmWchiW11nb1omitq8=
github.com/NVIDIA/aistore v1.3.24-0.20240618150949-10e2b1b379b1 h1:Rysl68V9Kq0B3fWGMTQvS9rpUQmxA9ZNOJ1TaZ5tbT0=
github.com/NVIDIA/aistore v1.3.24-0.20240618150949-10e2b1b379b1/go.mod h1:rzuE/hzSFxylpF5sfawzy1DPnkmWchiW11nb1omitq8=
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

0 comments on commit 56935d4

Please sign in to comment.