Skip to content

Commit

Permalink
fileservice: add QCloudSDK
Browse files Browse the repository at this point in the history
  • Loading branch information
reusee committed Oct 22, 2024
1 parent caea954 commit d52dc72
Show file tree
Hide file tree
Showing 10 changed files with 675 additions and 50 deletions.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spkg/bom v1.0.0
github.com/stretchr/testify v1.9.0
github.com/tencentyun/cos-go-sdk-v5 v0.7.55
github.com/ti-mo/conntrack v0.5.1
github.com/ti-mo/netfilter v0.5.2
github.com/tidwall/btree v1.6.0
Expand All @@ -93,6 +94,7 @@ require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cilium/ebpf v0.9.1 // indirect
github.com/clbanning/mxj v1.8.4 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-ini/ini v1.67.0 // indirect
Expand All @@ -101,6 +103,7 @@ require (
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/gosimple/slug v1.13.1 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/itchyny/timefmt-go v0.1.6 // indirect
Expand All @@ -110,8 +113,10 @@ require (
github.com/mdlayher/netlink v1.7.2 // indirect
github.com/mdlayher/socket v0.5.1 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mozillazg/go-httpheader v0.2.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
Expand Down
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
github.com/RoaringBitmap/roaring v1.2.3 h1:yqreLINqIrX22ErkKI0vY47/ivtJr6n+kMhVOVmhWBY=
github.com/RoaringBitmap/roaring v1.2.3/go.mod h1:plvDsJQpxOC5bw8LRteu/MLWHsHez/3y6cubLI4/1yE=
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
Expand Down Expand Up @@ -133,6 +134,8 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/cilium/ebpf v0.9.1 h1:64sn2K3UKw8NbP/blsixRpF3nXuyhz/VjRlRzvlBRu4=
github.com/cilium/ebpf v0.9.1/go.mod h1:+OhNOIXx/Fnu1IE8bJz2dzOA+VSfyTfdNUVdlQnxUFY=
github.com/clbanning/mxj v1.8.4 h1:HuhwZtbyvyOw+3Z1AowPkU87JkJUSv751ELWaiTpj8I=
github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
Expand Down Expand Up @@ -295,6 +298,7 @@ github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptG
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 h1:zN2lZNZRflqFyxVaTIU61KNKQ9C0055u9CAfpmqUvo4=
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3/go.mod h1:nPpo7qLxd6XL3hWJG/O60sR8ZKfMCiIoNap5GvD12KU=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
Expand Down Expand Up @@ -329,6 +333,7 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand All @@ -337,6 +342,8 @@ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand All @@ -348,6 +355,7 @@ github.com/google/pprof v0.0.0-20230510103437-eeec1cb781c3/go.mod h1:79YE0hCXdHa
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -543,6 +551,7 @@ github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa1
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
Expand Down Expand Up @@ -579,6 +588,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwd
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
github.com/mozillazg/go-httpheader v0.2.1 h1:geV7TrjbL8KXSyvghnFm+NyTux/hxwueTSrwhe88TQQ=
github.com/mozillazg/go-httpheader v0.2.1/go.mod h1:jJ8xECTlalr6ValeXYdOF8fFUISeBAdw6E61aqQma60=
github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM=
github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
Expand Down Expand Up @@ -738,6 +749,10 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.563/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563/go.mod h1:uom4Nvi9W+Qkom0exYiJ9VWJjXwyxtPYTkKkaLMlfE0=
github.com/tencentyun/cos-go-sdk-v5 v0.7.55 h1:9DfH3umWUd0I2jdqcUxrU1kLfUPOydULNy4T9qN5PF8=
github.com/tencentyun/cos-go-sdk-v5 v0.7.55/go.mod h1:8+hG+mQMuRP/OIS9d83syAvXvrMj9HhkND6Q1fLghw0=
github.com/testcontainers/testcontainers-go v0.29.1 h1:z8kxdFlovA2y97RWx98v/TQ+tR+SXZm6p35M+xB92zk=
github.com/testcontainers/testcontainers-go v0.29.1/go.mod h1:SnKnKQav8UcgtKqjp/AD8bE1MqZm+3TDb/B8crE3XnI=
github.com/testcontainers/testcontainers-go/modules/compose v0.29.1 h1:47ipPM+s+ltCDOP3Sa1j95AkNb+z+WGiHLDbLU8ixuc=
Expand Down
13 changes: 6 additions & 7 deletions pkg/fileservice/disk_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,20 +537,19 @@ func BenchmarkDiskCacheMultipleIOEntries(b *testing.B) {
}
var counter perfcounter.CounterSet
ctx := perfcounter.WithCounterSet(ctx, &counter)
err := cache.Read(
ctx,
&IOVector{
FilePath: "foo",
Entries: entries,
},
)
vec := &IOVector{
FilePath: "foo",
Entries: entries,
}
err := cache.Read(ctx, vec)
if err != nil {
b.Fatal(err)
}
numOpen := counter.FileService.Cache.Disk.OpenFullFile.Load()
if numOpen != 1 {
b.Fatal()
}
vec.Release()
}
}

Expand Down
28 changes: 12 additions & 16 deletions pkg/fileservice/file_service_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,22 @@ func benchmarkFileService(ctx context.Context, b *testing.B, newFS func() FileSe

b.RunParallel(func(pb *testing.PB) {

readVector := &IOVector{
FilePath: "foo",
}
offset := int64(0)
for _, part := range parts2 {
readVector.Entries = append(readVector.Entries, IOEntry{
Offset: offset,
Size: int64(len(part)),
ToCacheData: CacheOriginalData,
})
offset += int64(len(part))
}

for pb.Next() {
for i := range readVector.Entries {
readVector.Entries[i].done = false
readVector.Entries[i].Data = nil
readVector := &IOVector{
FilePath: "foo",
}
offset := int64(0)
for _, part := range parts2 {
readVector.Entries = append(readVector.Entries, IOEntry{
Offset: offset,
Size: int64(len(part)),
ToCacheData: CacheOriginalData,
})
offset += int64(len(part))
}
err := fs.Read(ctx, readVector)
assert.Nil(b, err)
readVector.Release()
}

})
Expand Down
34 changes: 20 additions & 14 deletions pkg/fileservice/file_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func testFileService(
content := make([]byte, _BlockContentSize*4)
_, err := rand.Read(content)
assert.Nil(t, err)
parts := randomSplit(content, len(content)/16)
parts := randomCut(content, 16)

// write
writeVector := IOVector{
Expand Down Expand Up @@ -361,7 +361,7 @@ func testFileService(
readVector.Release()

// read, random entry
parts = randomSplit(content, len(content)/16)
parts = randomCut(content, 16)
readVector.Entries = readVector.Entries[:0]
offset = int64(0)
for _, part := range parts {
Expand All @@ -374,12 +374,12 @@ func testFileService(
err = fs.Read(ctx, readVector)
assert.Nil(t, err)
for i, entry := range readVector.Entries {
assert.Equal(t, parts[i], entry.Data, "path: %s, entry: %+v, content %v", filePath, entry, content)
assert.Equal(t, parts[i], entry.Data, "path: %s, entry: %+v", filePath, entry)
}
readVector.Release()

// read, random entry with ReadCloserForRead
parts = randomSplit(content, len(content)/16)
parts = randomCut(content, 16)
readVector.Entries = readVector.Entries[:0]
offset = int64(0)
readers := make([]io.ReadCloser, len(parts))
Expand Down Expand Up @@ -1014,19 +1014,25 @@ func testFileService(

}

func randomSplit(data []byte, maxLen int) (ret [][]byte) {
for {
if len(data) == 0 {
return
func randomCut(data []byte, parts int) [][]byte {
positions := mrand.Perm(len(data))[:parts-1]
sort.Ints(positions)
slices := make([][]byte, 0, parts)
slices = append(slices, data[:positions[0]])
for i, pos := range positions {
if i == len(positions)-1 {
break
}
if len(data) < maxLen {
ret = append(ret, data)
return
slices = append(slices, data[pos:positions[i+1]])
}
slices = append(slices, data[positions[len(positions)-1]:])
ret := slices[:0]
for _, slice := range slices {
if len(slice) > 0 {
ret = append(ret, slice)
}
cut := 1 + mrand.Intn(maxLen)
ret = append(ret, data[:cut])
data = data[cut:]
}
return ret
}

func fixedSplit(data []byte, l int) (ret [][]byte) {
Expand Down
26 changes: 16 additions & 10 deletions pkg/fileservice/memory_fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,18 @@ func BenchmarkMemoryFSWithMemoryCache(b *testing.B) {
var counterSet perfcounter.CounterSet
ctx = perfcounter.WithCounterSet(ctx, &counterSet)

cache := NewMemCache(
fscache.ConstCapacity(128*1024*1024),
nil,
nil,
"",
)
defer cache.Close()

benchmarkFileService(ctx, b, func() FileService {
fs, err := NewMemoryFS("memory", DisabledCacheConfig, nil)
assert.Nil(b, err)
fs.caches = append(fs.caches, NewMemCache(
fscache.ConstCapacity(128*1024*1024),
nil,
nil,
"",
))
fs.caches = append(fs.caches, cache)
return fs
})

Expand All @@ -79,13 +82,16 @@ func BenchmarkMemoryFSWithMemoryCacheLowCapacity(b *testing.B) {
var counterSet perfcounter.CounterSet
ctx = perfcounter.WithCounterSet(ctx, &counterSet)

cache := NewMemCache(
fscache.ConstCapacity(2*1024*1024), nil, nil,
"",
)
defer cache.Close()

benchmarkFileService(ctx, b, func() FileService {
fs, err := NewMemoryFS("memory", DisabledCacheConfig, nil)
assert.Nil(b, err)
fs.caches = append(fs.caches, NewMemCache(
fscache.ConstCapacity(2*1024*1024), nil, nil,
"",
))
fs.caches = append(fs.caches, cache)
return fs
})

Expand Down
7 changes: 7 additions & 0 deletions pkg/fileservice/object_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ func TestObjectStorages(t *testing.T) {
}
return storage
})
testObjectStorage(t, "qcloud", func(t *testing.T) *QCloudSDK {
storage, err := NewQCloudSDK(context.Background(), args, nil)
if err != nil {
t.Fatal(err)
}
return storage
})

case strings.Contains(args.Endpoint, "aws"):
// AWS
Expand Down
Loading

0 comments on commit d52dc72

Please sign in to comment.