Skip to content

Commit

Permalink
'api' package not to import 'core'
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Dec 26, 2023
1 parent 982bcb4 commit 674a39f
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 122 deletions.
16 changes: 9 additions & 7 deletions ais/backend/ais.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (

const ua = "aisnode/backend"

const remAisDefunct = "defunct" // uuid configured offline

type (
remAis struct {
smap *meta.Smap
Expand Down Expand Up @@ -160,11 +162,11 @@ func (m *AISBackendProvider) _apply(cfg *cmn.ClusterConfig, clusterConf cmn.Back
// return (m.remote + m.alias) in-memory info wo/ connecting to remote cluster(s)
// (compare with GetInfo() below)
// TODO: caller to pass its cached version to optimize-out allocations
func (m *AISBackendProvider) GetInfoInternal() (res core.Remotes) {
func (m *AISBackendProvider) GetInfoInternal() (res meta.RemAisVec) {
m.mu.RLock()
res.A = make([]*core.RemAis, 0, len(m.remote))
res.A = make([]*meta.RemAis, 0, len(m.remote))
for uuid, remAis := range m.remote {
out := &core.RemAis{UUID: uuid, URL: remAis.url}
out := &meta.RemAis{UUID: uuid, URL: remAis.url}
for a, u := range m.alias {
if uuid == u {
out.Alias = a
Expand All @@ -183,16 +185,16 @@ func (m *AISBackendProvider) GetInfoInternal() (res core.Remotes) {
// select the correct one at the moment it sends a request.
// See also: GetInfoInternal()
// TODO: ditto
func (m *AISBackendProvider) GetInfo(clusterConf cmn.BackendConfAIS) (res core.Remotes) {
func (m *AISBackendProvider) GetInfo(clusterConf cmn.BackendConfAIS) (res meta.RemAisVec) {
var (
cfg = cmn.GCO.Get()
cliPlain, cliTLS = remaisClients(&cfg.Client)
)
m.mu.RLock()
res.A = make([]*core.RemAis, 0, len(m.remote))
res.A = make([]*meta.RemAis, 0, len(m.remote))
for uuid, remAis := range m.remote {
var (
out = &core.RemAis{UUID: uuid, URL: remAis.url}
out = &meta.RemAis{UUID: uuid, URL: remAis.url}
client = cliPlain
)
if cos.IsHTTPS(remAis.url) {
Expand Down Expand Up @@ -223,7 +225,7 @@ func (m *AISBackendProvider) GetInfo(clusterConf cmn.BackendConfAIS) (res core.R
for alias, clusterURLs := range clusterConf {
if _, ok := m.alias[alias]; !ok {
if _, ok = m.remote[alias]; !ok {
out := &core.RemAis{Alias: alias, UUID: apc.RemAisDefunct}
out := &meta.RemAis{Alias: alias, UUID: remAisDefunct}
out.URL = fmt.Sprintf("%v", clusterURLs)
res.A = append(res.A, out)
}
Expand Down
3 changes: 1 addition & 2 deletions ais/htcommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/cmn/debug"
"github.com/NVIDIA/aistore/cmn/nlog"
"github.com/NVIDIA/aistore/core"
"github.com/NVIDIA/aistore/core/meta"
"github.com/NVIDIA/aistore/ext/etl"
"github.com/NVIDIA/aistore/memsys"
Expand Down Expand Up @@ -473,7 +472,7 @@ func (c cresSM) read(res *callResult, body io.Reader) { res.v = c.newV(); res.jr
func (cresND) newV() any { return &meta.Snode{} }
func (c cresND) read(res *callResult, body io.Reader) { res.v = c.newV(); res.jread(body) }

func (cresBA) newV() any { return &core.Remotes{} }
func (cresBA) newV() any { return &meta.RemAisVec{} }
func (c cresBA) read(res *callResult, body io.Reader) { res.v = c.newV(); res.jread(body) }

func (cresEI) newV() any { return &etl.InfoList{} }
Expand Down
12 changes: 6 additions & 6 deletions ais/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ type (
mu sync.RWMutex
}
remais struct {
core.Remotes
old []*core.RemAis // to facilitate a2u resolution (and, therefore, offline access)
meta.RemAisVec
old []*meta.RemAis // to facilitate a2u resolution (and, therefore, offline access)
mu sync.RWMutex
in atomic.Bool
}
Expand Down Expand Up @@ -1717,7 +1717,7 @@ func (p *proxy) httpobjpost(w http.ResponseWriter, r *http.Request, apireq *apiR
}
return
}
args := &core.PromoteArgs{}
args := &apc.PromoteArgs{}
if err := cos.MorphMarshal(msg.Value, args); err != nil {
p.writeErrf(w, r, cmn.FmtErrMorphUnmarshal, p.si, msg.Action, msg.Value, err)
return
Expand Down Expand Up @@ -3035,7 +3035,7 @@ func (p *proxy) _remais(newConfig *cmn.ClusterConfig, blocking bool) {
}
for ; retries > 0; retries-- {
time.Sleep(sleep)
all, err := p.getRemAises(false /*refresh*/)
all, err := p.getRemAisVec(false /*refresh*/)
if err != nil {
if retries < maxretries {
nlog.Errorf("%s: failed to get remais (%d attempts)", p, retries-1)
Expand All @@ -3049,7 +3049,7 @@ func (p *proxy) _remais(newConfig *cmn.ClusterConfig, blocking bool) {
if p.remais.Ver < all.Ver {
// keep old/detached clusters to support access to existing ("cached") buckets
// i.e., the ability to resolve remote alias to Ns.UUID (see p.a2u)
for _, a := range p.remais.Remotes.A {
for _, a := range p.remais.RemAisVec.A {
var found bool
for _, b := range p.remais.old {
if b.UUID == a.UUID {
Expand All @@ -3066,7 +3066,7 @@ func (p *proxy) _remais(newConfig *cmn.ClusterConfig, blocking bool) {
}
}

p.remais.Remotes = *all
p.remais.RemAisVec = *all
nver = p.remais.Ver
p.remais.mu.Unlock()
break
Expand Down
8 changes: 4 additions & 4 deletions ais/prxclu.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (p *proxy) httpcluget(w http.ResponseWriter, r *http.Request) {
case apc.WhatMountpaths:
p.qcluMountpaths(w, r, what, query)
case apc.WhatRemoteAIS:
all, err := p.getRemAises(true /*refresh*/)
all, err := p.getRemAisVec(true /*refresh*/)
if err != nil {
p.writeErr(w, r, err)
return
Expand Down Expand Up @@ -223,7 +223,7 @@ func (p *proxy) qcluSysinfo(w http.ResponseWriter, r *http.Request, what string,
p.writeJSON(w, r, out, what)
}

func (p *proxy) getRemAises(refresh bool) (*core.Remotes, error) {
func (p *proxy) getRemAisVec(refresh bool) (*meta.RemAisVec, error) {
smap := p.owner.smap.get()
si, errT := smap.GetRandTarget()
if errT != nil {
Expand All @@ -245,12 +245,12 @@ func (p *proxy) getRemAises(refresh bool) (*core.Remotes, error) {
cargs.cresv = cresBA{} // -> cmn.BackendInfoAIS
}
var (
v *core.Remotes
v *meta.RemAisVec
res = p.call(cargs, smap)
err = res.toErr()
)
if err == nil {
v = res.v.(*core.Remotes)
v = res.v.(*meta.RemAisVec)
}
freeCargs(cargs)
freeCR(res)
Expand Down
21 changes: 8 additions & 13 deletions ais/test/promote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/NVIDIA/aistore/api"
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/core"
"github.com/NVIDIA/aistore/core/meta"
"github.com/NVIDIA/aistore/tools"
"github.com/NVIDIA/aistore/tools/tassert"
Expand Down Expand Up @@ -148,16 +147,12 @@ func (test *prmTests) do(t *testing.T, bck *meta.Bck) {
test.generate(t, from, to, tempdir, subdir)

// prepare request
args := api.PromoteArgs{
BaseParams: baseParams,
Bck: m.bck,
PromoteArgs: core.PromoteArgs{
SrcFQN: tempdir,
Recursive: test.recurs,
OverwriteDst: test.overwriteDst,
DeleteSrc: test.deleteSrc,
SrcIsNotFshare: test.notFshare,
},
args := apc.PromoteArgs{
SrcFQN: tempdir,
Recursive: test.recurs,
OverwriteDst: test.overwriteDst,
DeleteSrc: test.deleteSrc,
SrcIsNotFshare: test.notFshare,
}
var target *meta.Snode
if test.singleTarget {
Expand All @@ -167,7 +162,7 @@ func (test *prmTests) do(t *testing.T, bck *meta.Bck) {
}

// (I) do
xid, err := api.Promote(&args)
xid, err := api.Promote(baseParams, m.bck, &args)
tassert.CheckFatal(t, err)

// wait for the operation to finish and collect stats
Expand Down Expand Up @@ -245,7 +240,7 @@ func (test *prmTests) do(t *testing.T, bck *meta.Bck) {
}

// do
xid, err = api.Promote(&args)
xid, err = api.Promote(baseParams, m.bck, &args)
tassert.CheckFatal(t, err)

locObjs, outObjs, inObjs = test.wait(t, xid, tempdir, target, &m)
Expand Down
2 changes: 1 addition & 1 deletion ais/tgtcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (t *target) httpdaeget(w http.ResponseWriter, r *http.Request) {

anyConf := cmn.GCO.Get().Backend.Get(apc.AIS)
if anyConf == nil {
t.writeJSON(w, r, core.Remotes{}, httpdaeWhat)
t.writeJSON(w, r, meta.RemAisVec{}, httpdaeWhat)
return
}
aisConf, ok := anyConf.(cmn.BackendConfAIS)
Expand Down
2 changes: 1 addition & 1 deletion ais/tgtobj.go
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ func (a *apndOI) flush() (int, error) {
Bck: a.lom.Bck(),
Cksum: partialCksum,
Config: a.config,
PromoteArgs: core.PromoteArgs{
PromoteArgs: apc.PromoteArgs{
SrcFQN: a.hdl.workFQN,
ObjName: a.lom.ObjName,
OverwriteDst: true,
Expand Down
6 changes: 3 additions & 3 deletions ais/tgttxn.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ func (t *target) promote(c *txnSrv, hdr http.Header) (string, error) {
if err := c.bck.Init(t.owner.bmd); err != nil {
return "", err
}
prmMsg := &core.PromoteArgs{}
prmMsg := &apc.PromoteArgs{}
if err := cos.MorphMarshal(c.msg.Value, prmMsg); err != nil {
err = fmt.Errorf(cmn.FmtErrMorphUnmarshal, t, c.msg.Action, c.msg.Value, err)
return "", err
Expand Down Expand Up @@ -981,7 +981,7 @@ func (t *target) promote(c *txnSrv, hdr http.Header) (string, error) {
}

// scan and, optionally, auto-detect file-share
func prmScan(dirFQN string, prmMsg *core.PromoteArgs) (fqns []string, totalN int, cksumVal string, err error) {
func prmScan(dirFQN string, prmMsg *apc.PromoteArgs) (fqns []string, totalN int, cksumVal string, err error) {
var (
cksum *cos.CksumHash
autoDetect = !prmMsg.SrcIsNotFshare || !cmn.Rom.Features().IsSet(feat.DontAutoDetectFshare)
Expand Down Expand Up @@ -1042,7 +1042,7 @@ func (t *target) prmNumFiles(c *txnSrv, txnPrm *txnPromote, confirmedFshare bool
params := core.PromoteParams{
Bck: c.bck,
Config: config,
PromoteArgs: core.PromoteArgs{
PromoteArgs: apc.PromoteArgs{
SrcFQN: fqn,
ObjName: objName,
OverwriteDst: txnPrm.msg.OverwriteDst,
Expand Down
4 changes: 2 additions & 2 deletions ais/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type (
txnBckBase
}
txnPromote struct {
msg *core.PromoteArgs
msg *apc.PromoteArgs
xprm *xs.XactDirPromote
dirFQN string
fqns []string
Expand Down Expand Up @@ -635,7 +635,7 @@ func (txn *txnArchMultiObj) String() string {
// txnPromote //
////////////////

func newTxnPromote(c *txnSrv, msg *core.PromoteArgs, fqns []string, dirFQN string, totalN int) (txn *txnPromote) {
func newTxnPromote(c *txnSrv, msg *apc.PromoteArgs, fqns []string, dirFQN string, totalN int) (txn *txnPromote) {
txn = &txnPromote{msg: msg, fqns: fqns, dirFQN: dirFQN, totalN: totalN}
txn.init(c.bck)
txn.fillFromCtx(c)
Expand Down
4 changes: 0 additions & 4 deletions api/apc/actmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ const (
NodeDecommission = "decommission"
)

const (
RemAisDefunct = "defunct" // uuid configured offline
)

// ActMsg is a JSON-formatted control structures used in a majority of API calls
type (
ActMsg struct {
Expand Down
20 changes: 20 additions & 0 deletions api/apc/promote.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Package apc: API messages and constants
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
package apc

// common part that's used in `api.PromoteArgs` and `PromoteParams`(server side), both
type PromoteArgs struct {
DaemonID string `json:"tid,omitempty"` // target ID
SrcFQN string `json:"src,omitempty"` // source file or directory (must be absolute pathname)
ObjName string `json:"obj,omitempty"` // destination object name or prefix
Recursive bool `json:"rcr,omitempty"` // recursively promote nested dirs
// once successfully promoted:
OverwriteDst bool `json:"ovw,omitempty"` // overwrite destination
DeleteSrc bool `json:"dls,omitempty"` // remove source when (and after) successfully promoting
// explicit request _not_ to treat the source as a potential file share
// and _not_ to try to auto-detect if it is;
// (auto-detection takes time, etc.)
SrcIsNotFshare bool `json:"notshr,omitempty"` // the source is not a file share equally accessible by all targets
}
3 changes: 1 addition & 2 deletions api/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/core"
"github.com/NVIDIA/aistore/core/meta"
"github.com/NVIDIA/aistore/stats"
jsoniter "github.com/json-iterator/go"
Expand Down Expand Up @@ -199,7 +198,7 @@ func GetClusterStats(bp BaseParams) (res stats.Cluster, err error) {
return
}

func GetRemoteAIS(bp BaseParams) (remais core.Remotes, err error) {
func GetRemoteAIS(bp BaseParams) (remais meta.RemAisVec, err error) {
bp.Method = http.MethodGet
reqParams := AllocRp()
{
Expand Down
22 changes: 6 additions & 16 deletions api/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/core"
)

const (
Expand Down Expand Up @@ -88,11 +87,6 @@ type (
// - we simply don't care.
SkipVC bool
}
PromoteArgs struct {
BaseParams BaseParams
Bck cmn.Bck
core.PromoteArgs
}

// (see also: api.PutApndArchArgs)
AppendArgs struct {
Expand Down Expand Up @@ -552,23 +546,19 @@ func RenameObject(bp BaseParams, bck cmn.Bck, oldName, newName string) error {
}

// promote files and directories to ais objects
func Promote(args *PromoteArgs) (xid string, err error) {
var (
actMsg = apc.ActMsg{Action: apc.ActPromote, Name: args.SrcFQN, Value: &args.PromoteArgs}
method = args.BaseParams.Method
)
args.BaseParams.Method = http.MethodPost
func Promote(bp BaseParams, bck cmn.Bck, args *apc.PromoteArgs) (xid string, err error) {
actMsg := apc.ActMsg{Action: apc.ActPromote, Name: args.SrcFQN, Value: args}
bp.Method = http.MethodPost
reqParams := AllocRp()
{
reqParams.BaseParams = args.BaseParams
reqParams.Path = apc.URLPathObjects.Join(args.Bck.Name)
reqParams.BaseParams = bp
reqParams.Path = apc.URLPathObjects.Join(bck.Name)
reqParams.Body = cos.MustMarshal(actMsg)
reqParams.Header = http.Header{cos.HdrContentType: []string{cos.ContentJSON}}
reqParams.Query = args.Bck.NewQuery()
reqParams.Query = bck.NewQuery()
}
_, err = reqParams.doReqStr(&xid)
FreeRp(reqParams)
args.BaseParams.Method = method
return xid, err
}

Expand Down
25 changes: 10 additions & 15 deletions cmd/cli/cli/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/NVIDIA/aistore/cmn"
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/cmn/debug"
"github.com/NVIDIA/aistore/core"
"github.com/NVIDIA/aistore/sys"
jsoniter "github.com/json-iterator/go"
"github.com/urfave/cli"
Expand All @@ -32,20 +31,16 @@ func promote(c *cli.Context, bck cmn.Bck, objName, fqn string) error {
target = parseStrFlag(c, targetIDFlag)
recurs = flagIsSet(c, recursFlag)
)
promoteArgs := &api.PromoteArgs{
BaseParams: apiBP,
Bck: bck,
PromoteArgs: core.PromoteArgs{
DaemonID: target,
ObjName: objName,
SrcFQN: fqn,
Recursive: recurs,
SrcIsNotFshare: flagIsSet(c, notFshareFlag),
OverwriteDst: flagIsSet(c, overwriteFlag),
DeleteSrc: flagIsSet(c, deleteSrcFlag),
},
}
xid, err := api.Promote(promoteArgs)
args := apc.PromoteArgs{
DaemonID: target,
ObjName: objName,
SrcFQN: fqn,
Recursive: recurs,
SrcIsNotFshare: flagIsSet(c, notFshareFlag),
OverwriteDst: flagIsSet(c, overwriteFlag),
DeleteSrc: flagIsSet(c, deleteSrcFlag),
}
xid, err := api.Promote(apiBP, bck, &args)
if err != nil {
return V(err)
}
Expand Down
Loading

0 comments on commit 674a39f

Please sign in to comment.