Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileservice: make FileService.List returns iter.Seq2 #19573

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 2 additions & 58 deletions cmd/mo-service/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,12 @@
package main

import (
"context"
"testing"

"github.com/matrixorigin/matrixone/pkg/common/moerr"
"github.com/matrixorigin/matrixone/pkg/fileservice"
"github.com/matrixorigin/matrixone/pkg/testutil"
)

var _ fileservice.FileService = &testFS{}

type testFS struct {
}

func (tfs *testFS) Name() string {
//TODO implement me
panic("implement me")
}

func (tfs *testFS) Write(ctx context.Context, vector fileservice.IOVector) error {
return moerr.NewInternalError(ctx, "return err")
}

func (tfs *testFS) Read(ctx context.Context, vector *fileservice.IOVector) error {
//TODO implement me
panic("implement me")
}

func (tfs *testFS) ReadCache(ctx context.Context, vector *fileservice.IOVector) error {
//TODO implement me
panic("implement me")
}

func (tfs *testFS) List(ctx context.Context, dirPath string) ([]fileservice.DirEntry, error) {
//TODO implement me
panic("implement me")
}

func (tfs *testFS) Delete(ctx context.Context, filePaths ...string) error {
//TODO implement me
panic("implement me")
}

func (tfs *testFS) StatFile(ctx context.Context, filePath string) (*fileservice.DirEntry, error) {
//TODO implement me
panic("implement me")
}

func (tfs *testFS) PrefetchFile(ctx context.Context, filePath string) error {
//TODO implement me
panic("implement me")
}

func (tfs *testFS) Cost() *fileservice.CostAttr {
//TODO implement me
panic("implement me")
}

func (tfs *testFS) Close() {
//TODO implement me
panic("implement me")
}

func Test_saveMallocProfile(t *testing.T) {
globalEtlFS = &testFS{}
globalEtlFS = testutil.NewETLFS()
saveMallocProfile()
}
4 changes: 2 additions & 2 deletions pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func Test_backupConfigFile(t *testing.T) {
},
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
assert.NoError(t, err)
list, err2 := Fs.List(context.Background(), configDir)
list, err2 := fileservice.SortedList(Fs.List(context.Background(), configDir))
assert.NoError(t, err2)
var configFile string
for _, entry := range list {
Expand Down Expand Up @@ -587,7 +587,7 @@ func TestBackup(t *testing.T) {
assert.NotNil(t, cfg)

//checkup config files
list, err2 := cfg.GeneralDir.List(context.Background(), configDir)
list, err2 := fileservice.SortedList(cfg.GeneralDir.List(context.Background(), configDir))
assert.NoError(t, err2)
var configFile string
for _, entry := range list {
Expand Down
2 changes: 1 addition & 1 deletion pkg/backup/tae.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func copyFileAndGetMetaFiles(
decodeFunc func(string) (types.TS, types.TS, string),
copy bool,
) ([]*taeFile, []*checkpoint.MetaFile, []fileservice.DirEntry, error) {
files, err := srcFs.List(ctx, dir)
files, err := fileservice.SortedList(srcFs.List(ctx, dir))
if err != nil {
return nil, nil, nil, err
}
Expand Down
8 changes: 2 additions & 6 deletions pkg/cnservice/server_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/matrixorigin/matrixone/pkg/fileservice"
"github.com/matrixorigin/matrixone/pkg/frontend"
mock_frontend "github.com/matrixorigin/matrixone/pkg/frontend/test"
"github.com/matrixorigin/matrixone/pkg/frontend/test/mock_file"
"github.com/matrixorigin/matrixone/pkg/frontend/test/mock_incr"
"github.com/matrixorigin/matrixone/pkg/frontend/test/mock_lock"
"github.com/matrixorigin/matrixone/pkg/frontend/test/mock_moserver"
Expand All @@ -48,6 +47,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/queryservice"
"github.com/matrixorigin/matrixone/pkg/shardservice"
"github.com/matrixorigin/matrixone/pkg/taskservice"
"github.com/matrixorigin/matrixone/pkg/testutil"
"github.com/matrixorigin/matrixone/pkg/txn/client"
"github.com/matrixorigin/matrixone/pkg/util/trace"
"github.com/matrixorigin/matrixone/pkg/vm/engine"
Expand Down Expand Up @@ -1016,11 +1016,7 @@ func Test_service_handleGetCacheData(t *testing.T) {
ctx := context.Background()
ctl := gomock.NewController(t)

mockFs := mock_file.NewMockFileService(ctl)
mockFs.EXPECT().Name().Return(defines.SharedFileServiceName).AnyTimes()
mockFs.EXPECT().ReadCache(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()

fs, err := fileservice.NewFileServices("dummy", mockFs)
fs, err := fileservice.NewFileServices("dummy", testutil.NewSharedFS())
require.NoError(t, err)

mockQuery := mock_query.NewMockQueryService(ctl)
Expand Down
18 changes: 8 additions & 10 deletions pkg/common/stage/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,10 @@ func stageListWithWildcard(service string, pattern string, proc *process.Process
if err != nil {
return nil, err
}
entries, err := etlfs.List(proc.Ctx, readpath)
if err != nil {
return nil, err
}
for _, entry := range entries {
for entry, err := range etlfs.List(proc.Ctx, readpath) {
if err != nil {
return nil, err
}
if !entry.IsDir && i+1 != len(pathDir) {
continue
}
Expand Down Expand Up @@ -403,11 +402,10 @@ func stageListWithoutWildcard(service string, pattern string, proc *process.Proc
if err != nil {
return nil, err
}
entries, err := etlfs.List(proc.Ctx, readpath)
if err != nil {
return nil, err
}
for _, entry := range entries {
for entry, err := range etlfs.List(proc.Ctx, readpath) {
if err != nil {
return nil, err
}
fileList = append(fileList, path.Join(pattern, entry.Name))
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/datasync/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestCopyFiles(t *testing.T) {
}
assert.NoError(t, c.srcFS.Write(ctx, vec))
assert.Error(t, c.copyFiles(ctx, locations, ""))
entries, err := c.dstFS.List(ctx, "")
entries, err := fileservice.SortedList(c.dstFS.List(ctx, ""))
assert.NoError(t, err)
assert.Equal(t, 0, len(entries))
})
Expand All @@ -171,7 +171,7 @@ func TestCopyFiles(t *testing.T) {
}
assert.NoError(t, c.srcFS.Write(ctx, vec))
assert.Error(t, c.copyFiles(ctx, locations, "/nodir"))
entries, err := c.dstFS.List(ctx, "")
entries, err := fileservice.SortedList(c.dstFS.List(ctx, ""))
assert.NoError(t, err)
assert.Equal(t, 0, len(entries))
})
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestCopyFiles(t *testing.T) {
assert.NoError(t, c.srcFS.Write(ctx, vec))
}
assert.NoError(t, c.copyFiles(ctx, locations, ""))
entries, err := c.dstFS.List(ctx, "")
entries, err := fileservice.SortedList(c.dstFS.List(ctx, ""))
assert.NoError(t, err)
assert.Equal(t, 100, len(entries))
})
Expand Down Expand Up @@ -328,7 +328,7 @@ func TestFullSync(t *testing.T) {
assert.NotNil(t, ckp)
err = c.fullSync(ctx, ckp.Location)
assert.NoError(t, err)
files, err := c.dstFS.List(ctx, "")
files, err := fileservice.SortedList(c.dstFS.List(ctx, ""))
assert.NoError(t, err)
assert.Equal(t, 35, len(files))
})
Expand Down Expand Up @@ -1006,7 +1006,7 @@ func TestCompleteData(t *testing.T) {
lc.setLeaderID(10)
err := c.completeData(ctx)
assert.NoError(t, err)
files, err := c.dstFS.List(ctx, "")
files, err := fileservice.SortedList(c.dstFS.List(ctx, ""))
assert.NoError(t, err)
assert.Equal(t, 0, len(files))
requiredLsn, err := c.logClient.getRequiredLsn(ctx)
Expand All @@ -1027,7 +1027,7 @@ func TestCompleteData(t *testing.T) {
lc.setLeaderID(10)
err := c.completeData(ctx)
assert.NoError(t, err)
files, err := c.dstFS.List(ctx, "")
files, err := fileservice.SortedList(c.dstFS.List(ctx, ""))
assert.NoError(t, err)
assert.Equal(t, 35, len(files))
requiredLsn, err := c.logClient.getRequiredLsn(ctx)
Expand Down Expand Up @@ -1069,7 +1069,7 @@ func TestCompleteData(t *testing.T) {

err := c.completeData(ctx)
assert.NoError(t, err)
files, err := c.dstFS.List(ctx, "")
files, err := fileservice.SortedList(c.dstFS.List(ctx, ""))
assert.NoError(t, err)
assert.Equal(t, 35+(150-102), len(files))
requiredLsn, err := c.logClient.getRequiredLsn(ctx)
Expand Down
64 changes: 32 additions & 32 deletions pkg/fileservice/aliyun_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"io"
"iter"
"net/http"
gotrace "runtime/trace"
"strconv"
Expand Down Expand Up @@ -123,49 +124,48 @@ var _ ObjectStorage = new(AliyunSDK)
func (a *AliyunSDK) List(
ctx context.Context,
prefix string,
fn func(bool, string, int64) (bool, error),
) error {

if err := ctx.Err(); err != nil {
return err
}

var cont string

loop1:
for {
result, err := a.listObjects(ctx, prefix, cont)
if err != nil {
return err
) iter.Seq2[*DirEntry, error] {
return func(yield func(*DirEntry, error) bool) {
if err := ctx.Err(); err != nil {
yield(nil, err)
return
}

for _, obj := range result.Objects {
more, err := fn(false, obj.Key, obj.Size)
var cont string

loop1:
for {
result, err := a.listObjects(ctx, prefix, cont)
if err != nil {
return err
yield(nil, err)
return
}
if !more {
break loop1

for _, obj := range result.Objects {
if !yield(&DirEntry{
Name: obj.Key,
Size: obj.Size,
}, nil) {
break loop1
}
}
}

for _, prefix := range result.CommonPrefixes {
more, err := fn(true, prefix, 0)
if err != nil {
return err
for _, prefix := range result.CommonPrefixes {
if !yield(&DirEntry{
IsDir: true,
Name: prefix,
}, nil) {
break loop1
}
}
if !more {
break loop1

if !result.IsTruncated {
break
}
cont = result.NextContinuationToken
}

if !result.IsTruncated {
break
}
cont = result.NextContinuationToken
}

return nil
}

func (a *AliyunSDK) Stat(
Expand Down
Loading
Loading