union: add min_free_space option for lfs/eplfs policies - fixes #6071
This commit is contained in:
parent
29e37749b3
commit
1651429041
3 changed files with 22 additions and 6 deletions
|
@ -13,4 +13,5 @@ type Options struct {
|
||||||
CreatePolicy string `config:"create_policy"`
|
CreatePolicy string `config:"create_policy"`
|
||||||
SearchPolicy string `config:"search_policy"`
|
SearchPolicy string `config:"search_policy"`
|
||||||
CacheTime int `config:"cache_time"`
|
CacheTime int `config:"cache_time"`
|
||||||
|
MinFreeSpace fs.SizeSuffix `config:"min_free_space"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package policy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/rclone/rclone/backend/union/upstream"
|
"github.com/rclone/rclone/backend/union/upstream"
|
||||||
|
@ -18,6 +19,8 @@ type EpLfs struct {
|
||||||
EpAll
|
EpAll
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var errNoUpstreamsFound = errors.New("no upstreams found with more than min_free_space space spare")
|
||||||
|
|
||||||
func (p *EpLfs) lfs(upstreams []*upstream.Fs) (*upstream.Fs, error) {
|
func (p *EpLfs) lfs(upstreams []*upstream.Fs) (*upstream.Fs, error) {
|
||||||
var minFreeSpace int64 = math.MaxInt64
|
var minFreeSpace int64 = math.MaxInt64
|
||||||
var lfsupstream *upstream.Fs
|
var lfsupstream *upstream.Fs
|
||||||
|
@ -27,31 +30,35 @@ func (p *EpLfs) lfs(upstreams []*upstream.Fs) (*upstream.Fs, error) {
|
||||||
fs.LogPrintf(fs.LogLevelNotice, nil,
|
fs.LogPrintf(fs.LogLevelNotice, nil,
|
||||||
"Free Space is not supported for upstream %s, treating as infinite", u.Name())
|
"Free Space is not supported for upstream %s, treating as infinite", u.Name())
|
||||||
}
|
}
|
||||||
if space < minFreeSpace {
|
if space < minFreeSpace && space > int64(u.Opt.MinFreeSpace) {
|
||||||
minFreeSpace = space
|
minFreeSpace = space
|
||||||
lfsupstream = u
|
lfsupstream = u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if lfsupstream == nil {
|
if lfsupstream == nil {
|
||||||
return nil, fs.ErrorObjectNotFound
|
return nil, errNoUpstreamsFound
|
||||||
}
|
}
|
||||||
return lfsupstream, nil
|
return lfsupstream, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EpLfs) lfsEntries(entries []upstream.Entry) (upstream.Entry, error) {
|
func (p *EpLfs) lfsEntries(entries []upstream.Entry) (upstream.Entry, error) {
|
||||||
var minFreeSpace int64
|
var minFreeSpace int64 = math.MaxInt64
|
||||||
var lfsEntry upstream.Entry
|
var lfsEntry upstream.Entry
|
||||||
for _, e := range entries {
|
for _, e := range entries {
|
||||||
space, err := e.UpstreamFs().GetFreeSpace()
|
u := e.UpstreamFs()
|
||||||
|
space, err := u.GetFreeSpace()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.LogPrintf(fs.LogLevelNotice, nil,
|
fs.LogPrintf(fs.LogLevelNotice, nil,
|
||||||
"Free Space is not supported for upstream %s, treating as infinite", e.UpstreamFs().Name())
|
"Free Space is not supported for upstream %s, treating as infinite", u.Name())
|
||||||
}
|
}
|
||||||
if space < minFreeSpace {
|
if space < minFreeSpace && space > int64(u.Opt.MinFreeSpace) {
|
||||||
minFreeSpace = space
|
minFreeSpace = space
|
||||||
lfsEntry = e
|
lfsEntry = e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if lfsEntry == nil {
|
||||||
|
return nil, errNoUpstreamsFound
|
||||||
|
}
|
||||||
return lfsEntry, nil
|
return lfsEntry, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,14 @@ func init() {
|
||||||
Name: "cache_time",
|
Name: "cache_time",
|
||||||
Help: "Cache time of usage and free space (in seconds).\n\nThis option is only useful when a path preserving policy is used.",
|
Help: "Cache time of usage and free space (in seconds).\n\nThis option is only useful when a path preserving policy is used.",
|
||||||
Default: 120,
|
Default: 120,
|
||||||
|
}, {
|
||||||
|
Name: "min_free_space",
|
||||||
|
Help: `Minimum viable free space for lfs/eplfs policies.
|
||||||
|
|
||||||
|
If a remote has less than this much free space then it won't be
|
||||||
|
considered for use in lfs or eplfs policies.`,
|
||||||
|
Advanced: true,
|
||||||
|
Default: fs.Gibi,
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
fs.Register(fsi)
|
fs.Register(fsi)
|
||||||
|
|
Loading…
Reference in a new issue