Skip to content

Commit

Permalink
get-bmd Go API; follow-up
Browse files Browse the repository at this point in the history
* `GetBMD` to use /v1/daemon path, similar to `GetClusterMap`
* fix 'TODO' from the previous 37101ed commit

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Dec 12, 2023
1 parent f83bd00 commit 14e5644
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
13 changes: 8 additions & 5 deletions ais/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ func TestMountpathDisableAll(t *testing.T) {
tools.WaitForResilvering(t, baseParams, target)

tlog.Logf("waiting for bucket %s to show up on all targets\n", m.bck)
err = checkBMDsFor(m.proxyURL, m.bck)
err = checkTargetBMDsFor(m.proxyURL, m.bck)
tassert.CheckFatal(t, err)

// Put and read random files
Expand All @@ -1104,21 +1104,24 @@ func TestMountpathDisableAll(t *testing.T) {
m.ensureNumMountpaths(target, origMountpaths)
}

// TODO: instead, need target query w/ access control
func checkBMDsFor(proxyURL string, bck cmn.Bck) error {
// get BMD from each target; check the BMD for the specified bucket
func checkTargetBMDsFor(proxyURL string, bck cmn.Bck) error {
bp := tools.BaseAPIParams(proxyURL)
smap, err := api.GetClusterMap(bp)
if err != nil {
return err
}
to := time.Now().Add(10 * time.Second)
b := meta.CloneBck(&bck)
for _, s := range smap.Pmap {
for tid := range smap.Tmap {
// poll
for {
bmd, err := api.GetBMD(tools.BaseAPIParams(s.URL(cmn.NetPublic)))
// alternatively, something like: api.GetBMD(tools.BaseAPIParams(tsi.URL(...)))
val, err := api.GetNodeMeta(bp, tid, apc.WhatBMD)
if err != nil {
return err
}
bmd := val.(*meta.BMD)
if _, bucketExists := bmd.Get(b); bucketExists {
break
}
Expand Down
43 changes: 20 additions & 23 deletions api/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func mkhealth(bp BaseParams, readyToRebalance ...bool) (reqParams *ReqParams) {
return
}

// GetClusterMap retrieves AIStore cluster map.
// get cluster map from a BaseParams-referenced node
func GetClusterMap(bp BaseParams) (smap *meta.Smap, err error) {
bp.Method = http.MethodGet
reqParams := AllocRp()
Expand All @@ -78,10 +78,10 @@ func GetClusterMap(bp BaseParams) (smap *meta.Smap, err error) {
}
_, err = reqParams.DoReqAny(&smap)
FreeRp(reqParams)
return
return smap, err
}

// GetNodeClusterMap retrieves AIStore cluster map from a specific node.
// GetNodeClusterMap retrieves cluster map from the specified node.
func GetNodeClusterMap(bp BaseParams, sid string) (smap *meta.Smap, err error) {
bp.Method = http.MethodGet
reqParams := AllocRp()
Expand All @@ -96,6 +96,22 @@ func GetNodeClusterMap(bp BaseParams, sid string) (smap *meta.Smap, err error) {
return
}

// get bucket metadata (BMD) from a BaseParams-referenced node
func GetBMD(bp BaseParams) (bmd *meta.BMD, err error) {
bp.Method = http.MethodGet
reqParams := AllocRp()
{
reqParams.BaseParams = bp
reqParams.Path = apc.URLPathDae.S
reqParams.Query = url.Values{apc.QparamWhat: []string{apc.WhatBMD}}
}

bmd = &meta.BMD{}
_, err = reqParams.DoReqAny(bmd)
FreeRp(reqParams)
return bmd, err
}

// - get (smap, bmd, config) *cluster-level* metadata from the spec-ed node
// - compare with GetClusterMap, GetNodeClusterMap, GetClusterConfig et al.
// - TODO: etl meta
Expand Down Expand Up @@ -129,7 +145,7 @@ func GetNodeMeta(bp BaseParams, sid, what string) (out any, err error) {
return
}

// GetClusterSysInfo retrieves AIStore system info.
// GetClusterSysInfo retrieves cluster's system information
func GetClusterSysInfo(bp BaseParams) (info apc.ClusterSysInfo, err error) {
bp.Method = http.MethodGet
reqParams := AllocRp()
Expand Down Expand Up @@ -323,25 +339,6 @@ func GetClusterConfig(bp BaseParams) (*cmn.ClusterConfig, error) {
return cluConfig, nil
}

// GetBMD returns bucket metadata
func GetBMD(bp BaseParams) (*meta.BMD, error) {
bp.Method = http.MethodGet
reqParams := AllocRp()
{
reqParams.BaseParams = bp
reqParams.Path = apc.URLPathClu.S
reqParams.Query = url.Values{apc.QparamWhat: []string{apc.WhatBMD}}
}

bmd := &meta.BMD{}
_, err := reqParams.DoReqAny(bmd)
FreeRp(reqParams)
if err != nil {
return nil, err
}
return bmd, nil
}

func AttachRemoteAIS(bp BaseParams, alias, u string) error {
bp.Method = http.MethodPut
reqParams := AllocRp()
Expand Down

0 comments on commit 14e5644

Please sign in to comment.