From 36e184266f76580e0e2b517512102548e4ed72bf Mon Sep 17 00:00:00 2001 From: Max Sum Date: Sun, 1 Dec 2019 00:35:52 +0800 Subject: [PATCH] union: fix description and variable names of epff, epmfs, mfs policies --- backend/union/policy/epff.go | 28 ++++++++++++++-------------- backend/union/policy/epmfs.go | 19 +++++++++++-------- backend/union/policy/mfs.go | 8 +++++--- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/backend/union/policy/epff.go b/backend/union/policy/epff.go index 2da8b3f5a..16589fe81 100644 --- a/backend/union/policy/epff.go +++ b/backend/union/policy/epff.go @@ -17,19 +17,19 @@ type EpFF struct {} func (p *EpFF) epff(ctx context.Context, upstreams []*upstream.Fs, path string) (*upstream.Fs, error) { ch := make(chan *upstream.Fs) - for _, r := range upstreams { - r := r // Closure + for _, u := range upstreams { + u := u // Closure go func() { - if !exists(ctx, r, path) { - r = nil + if !exists(ctx, u, path) { + u = nil } - ch <- r + ch <- u }() } - var r *upstream.Fs + var u *upstream.Fs for i := 0; i < len(upstreams); i++ { - r = <- ch - if r != nil { + u = <- ch + if u != nil { // close remaining goroutines go func(num int) { defer close(ch) @@ -39,10 +39,10 @@ func (p *EpFF) epff(ctx context.Context, upstreams []*upstream.Fs, path string) }(len(upstreams) - 1 - i) } } - if r == nil { + if u == nil { return nil, fs.ErrorObjectNotFound } - return r, nil + return u, nil } // Action category policy, governing the modification of files and directories @@ -54,8 +54,8 @@ func (p *EpFF) Action(ctx context.Context, upstreams []*upstream.Fs, path string if len(upstreams) == 0 { return nil, fs.ErrorPermissionDenied } - r, err := p.epff(ctx, upstreams, path) - return []*upstream.Fs{r}, err + u, err := p.epff(ctx, upstreams, path) + return []*upstream.Fs{u}, err } // ActionEntries is ACTION category policy but receving a set of candidate entries @@ -79,8 +79,8 @@ func (p *EpFF) Create(ctx context.Context, upstreams []*upstream.Fs, path string if len(upstreams) == 0 { return nil, fs.ErrorPermissionDenied } - r, err := p.epff(ctx, upstreams, path) - return []*upstream.Fs{r}, err + u, err := p.epff(ctx, upstreams, path) + return []*upstream.Fs{u}, err } // CreateEntries is CREATE category policy but receving a set of candidate entries diff --git a/backend/union/policy/epmfs.go b/backend/union/policy/epmfs.go index 4693c8e9a..c9e69ca1b 100644 --- a/backend/union/policy/epmfs.go +++ b/backend/union/policy/epmfs.go @@ -12,7 +12,7 @@ func init(){ } // EpMfs stands for existing path, most free space -// Of all the branches on which the path exists choose the drive with the most free space. +// Of all the candidates on which the path exists choose the one with the most free space. type EpMfs struct { EpAll } @@ -20,16 +20,19 @@ type EpMfs struct { func (p *EpMfs) mfs(upstreams []*upstream.Fs) (*upstream.Fs, error) { var maxFreeSpace int64 var mfsupstream *upstream.Fs - for _, r := range upstreams { - space, err := r.GetFreeSpace() + for _, u := range upstreams { + space, err := u.GetFreeSpace() if err != nil { return nil, err } if maxFreeSpace < space { maxFreeSpace = space - mfsupstream = r + mfsupstream = u } } + if mfsupstream == nil { + return nil, fs.ErrorObjectNotFound + } return mfsupstream, nil } @@ -55,8 +58,8 @@ func (p *EpMfs) Action(ctx context.Context, upstreams []*upstream.Fs, path strin if err != nil { return nil, err } - r, err := p.mfs(upstreams) - return []*upstream.Fs{r}, err + u, err := p.mfs(upstreams) + return []*upstream.Fs{u}, err } // ActionEntries is ACTION category policy but receving a set of candidate entries @@ -75,8 +78,8 @@ func (p *EpMfs) Create(ctx context.Context, upstreams []*upstream.Fs, path strin if err != nil { return nil, err } - r, err := p.mfs(upstreams) - return []*upstream.Fs{r}, err + u, err := p.mfs(upstreams) + return []*upstream.Fs{u}, err } // CreateEntries is CREATE category policy but receving a set of candidate entries diff --git a/backend/union/policy/mfs.go b/backend/union/policy/mfs.go index 3143ca2ec..bc4cca5d9 100644 --- a/backend/union/policy/mfs.go +++ b/backend/union/policy/mfs.go @@ -12,7 +12,9 @@ func init(){ } // Mfs stands for most free space -// Of all the candidates on which the path exists choose the one with the most free space. +// Search category: same as epmfs. +// Action category: same as epmfs. +// Create category: Pick the drive with the most free space. type Mfs struct { EpMfs } @@ -26,6 +28,6 @@ func (p *Mfs) Create(ctx context.Context, upstreams []*upstream.Fs, path string) if len(upstreams) == 0 { return nil, fs.ErrorPermissionDenied } - r, err := p.mfs(upstreams) - return []*upstream.Fs{r}, err + u, err := p.mfs(upstreams) + return []*upstream.Fs{u}, err }