Skip to content

Commit 7398e7d

Browse files
KirCutej2rong4cnjyxjjj
authored
feat(alias): support load balance (#1767)
* feat(alias): support load balance * feat(alias): support storage match for load balance * feat(patch): add alias addition upgrade patch * fix bugs * fix(op/balance): optimize compatibility * chore: change default read conflict policy * feat(alias): refactor Alias initialization and enhance path handling * feat(alias): enhance object masking and add support for operation restrictions * feat(alias): enhance object masking * feat(fs): add permission checks * improve parsing * update object masks * feat(fs): enhance virtual file handling * feat(storage): enhance virtual file retrieval and path handling * refactor(alias): rename path handling functions for clarity and consistency * fix(alias): update path handling in Other method to use balanced path * fix bug * feat(alias): add file size validation * feat(alias): add hash consistency check * 移除哈希合并, * fix(alias): wrong behavior for all_strict/deterministic_or_all * Revert "fix(alias): wrong behavior for all_strict/deterministic_or_all" This reverts commit f001f2d. * fix(alias): wrong behavior for all_strict/deterministic_or_all * feat(alias): support part-based read load balance * fix(alias): list panic when leak conflict path * fix(alias): remove Other load balance * fix(alias): 修复 Link 方法中 resultLink 的返回类型和内容复制问题 * fix(alias): 更好的下载并发? * chore(alias): all tips * fix(alias): moving paths mismatch --------- Co-authored-by: j2rong4cn <j2rong@qq.com> Co-authored-by: ShenLin <773933146@qq.com>
1 parent 6e2d499 commit 7398e7d

File tree

17 files changed

+987
-525
lines changed

17 files changed

+987
-525
lines changed

drivers/alias/driver.go

Lines changed: 299 additions & 327 deletions
Large diffs are not rendered by default.

drivers/alias/meta.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ import (
66
)
77

88
type Addition struct {
9-
// Usually one of two
10-
// driver.RootPath
11-
// define other
12-
Paths string `json:"paths" required:"true" type:"text"`
13-
ProtectSameName bool `json:"protect_same_name" default:"true" required:"false" help:"Protects same-name files from Delete or Rename"`
14-
ParallelWrite bool `json:"parallel_write" type:"bool" default:"false"`
15-
DownloadConcurrency int `json:"download_concurrency" default:"0" required:"false" type:"number" help:"Need to enable proxy"`
16-
DownloadPartSize int `json:"download_part_size" default:"0" type:"number" required:"false" help:"Need to enable proxy. Unit: KB"`
17-
Writable bool `json:"writable" type:"bool" default:"false"`
18-
ProviderPassThrough bool `json:"provider_pass_through" type:"bool" default:"false"`
19-
DetailsPassThrough bool `json:"details_pass_through" type:"bool" default:"false"`
9+
Paths string `json:"paths" required:"true" type:"text"`
10+
ReadConflictPolicy string `json:"read_conflict_policy" type:"select" options:"first,random,all" default:"first"`
11+
WriteConflictPolicy string `json:"write_conflict_policy" type:"select" options:"disabled,first,deterministic,deterministic_or_all,all,all_strict" default:"disabled" help:"How the driver handles identical backend paths when renaming, removing, or making directories."`
12+
PutConflictPolicy string `json:"put_conflict_policy" type:"select" options:"disabled,first,deterministic,deterministic_or_all,all,all_strict,random,quota,quota_strict" default:"disabled" help:"How the driver handles identical backend paths when uploading, copying, moving, or decompressing."`
13+
FileConsistencyCheck bool `json:"file_consistency_check" type:"bool" default:"false"`
14+
DownloadConcurrency int `json:"download_concurrency" default:"0" required:"false" type:"number" help:"Need to enable proxy"`
15+
DownloadPartSize int `json:"download_part_size" default:"0" type:"number" required:"false" help:"Need to enable proxy. Unit: KB"`
16+
ProviderPassThrough bool `json:"provider_pass_through" type:"bool" default:"false"`
17+
DetailsPassThrough bool `json:"details_pass_through" type:"bool" default:"false"`
2018
}
2119

2220
var config = driver.Config{
@@ -31,10 +29,6 @@ var config = driver.Config{
3129

3230
func init() {
3331
op.RegisterDriver(func() driver.Driver {
34-
return &Alias{
35-
Addition: Addition{
36-
ProtectSameName: true,
37-
},
38-
}
32+
return &Alias{}
3933
})
4034
}

drivers/alias/types.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,78 @@
11
package alias
2+
3+
import (
4+
"time"
5+
6+
"github.com/OpenListTeam/OpenList/v4/internal/model"
7+
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
8+
"github.com/pkg/errors"
9+
)
10+
11+
const (
12+
DisabledWP = "disabled"
13+
FirstRWP = "first"
14+
DeterministicWP = "deterministic"
15+
DeterministicOrAllWP = "deterministic_or_all"
16+
AllRWP = "all"
17+
AllStrictWP = "all_strict"
18+
RandomBalancedRP = "random"
19+
BalancedByQuotaP = "quota"
20+
BalancedByQuotaStrictP = "quota_strict"
21+
)
22+
23+
var (
24+
ValidReadConflictPolicy = []string{FirstRWP, RandomBalancedRP, AllRWP}
25+
ValidWriteConflictPolicy = []string{DisabledWP, FirstRWP, DeterministicWP, DeterministicOrAllWP, AllRWP,
26+
AllStrictWP}
27+
ValidPutConflictPolicy = []string{DisabledWP, FirstRWP, DeterministicWP, DeterministicOrAllWP, AllRWP,
28+
AllStrictWP, RandomBalancedRP, BalancedByQuotaP, BalancedByQuotaStrictP}
29+
)
30+
31+
var (
32+
ErrPathConflict = errors.New("path conflict")
33+
ErrSamePathLeak = errors.New("leak some of same-name dirs")
34+
ErrNoEnoughSpace = errors.New("none of same-name dirs has enough space")
35+
ErrNotEnoughSrcObjs = errors.New("cannot move fewer objs to more paths, please try copying")
36+
)
37+
38+
type BalancedObjs []model.Obj
39+
40+
func (b BalancedObjs) GetSize() int64 {
41+
return b[0].GetSize()
42+
}
43+
44+
func (b BalancedObjs) ModTime() time.Time {
45+
return b[0].ModTime()
46+
}
47+
48+
func (b BalancedObjs) CreateTime() time.Time {
49+
return b[0].CreateTime()
50+
}
51+
52+
func (b BalancedObjs) IsDir() bool {
53+
return b[0].IsDir()
54+
}
55+
56+
func (b BalancedObjs) GetHash() utils.HashInfo {
57+
return b[0].GetHash()
58+
}
59+
60+
func (b BalancedObjs) GetName() string {
61+
return b[0].GetName()
62+
}
63+
64+
func (b BalancedObjs) GetPath() string {
65+
return b[0].GetPath()
66+
}
67+
68+
func (b BalancedObjs) GetID() string {
69+
return b[0].GetID()
70+
}
71+
72+
func (b BalancedObjs) Unwrap() model.Obj {
73+
return b[0]
74+
}
75+
76+
var _ model.Obj = (BalancedObjs)(nil)
77+
78+
type tempObj struct{ model.Object }

0 commit comments

Comments
 (0)