This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
storage: fix s3 walk directory #750
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f3f47a7
fix s3 walk directory
glorv ee60a3f
Merge branch 'master' into fix-walk
overvenus aae24bd
fix typo
glorv 484346f
Merge branch 'fix-walk' of https://github.com/glorv/br into fix-walk
glorv c9d5a7c
also check suffix when append '/' to s3 prefix
glorv b5d761b
Merge branch 'master' into fix-walk
ti-srebot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -870,7 +870,7 @@ func (s *s3Suite) TestWalkDir(c *C) { | |||||
}, nil | ||||||
}). | ||||||
After(firstCall) | ||||||
s.s3.EXPECT(). | ||||||
thirdCall := s.s3.EXPECT(). | ||||||
ListObjectsWithContext(ctx, gomock.Any()). | ||||||
DoAndReturn(func(_ context.Context, input *s3.ListObjectsInput) (*s3.ListObjectsOutput, error) { | ||||||
c.Assert(aws.StringValue(input.Marker), Equals, aws.StringValue(contents[3].Key)) | ||||||
|
@@ -881,6 +881,31 @@ func (s *s3Suite) TestWalkDir(c *C) { | |||||
}, nil | ||||||
}). | ||||||
After(secondCall) | ||||||
forthCall := s.s3.EXPECT(). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo?
Suggested change
|
||||||
ListObjectsWithContext(ctx, gomock.Any()). | ||||||
DoAndReturn(func(_ context.Context, input *s3.ListObjectsInput) (*s3.ListObjectsOutput, error) { | ||||||
c.Assert(aws.StringValue(input.Bucket), Equals, "bucket") | ||||||
c.Assert(aws.StringValue(input.Prefix), Equals, "prefix/") | ||||||
c.Assert(aws.StringValue(input.Marker), Equals, "") | ||||||
c.Assert(aws.Int64Value(input.MaxKeys), Equals, int64(4)) | ||||||
c.Assert(aws.StringValue(input.Delimiter), Equals, "") | ||||||
return &s3.ListObjectsOutput{ | ||||||
IsTruncated: aws.Bool(true), | ||||||
Contents: contents[:4], | ||||||
}, nil | ||||||
}). | ||||||
After(thirdCall) | ||||||
s.s3.EXPECT(). | ||||||
ListObjectsWithContext(ctx, gomock.Any()). | ||||||
DoAndReturn(func(_ context.Context, input *s3.ListObjectsInput) (*s3.ListObjectsOutput, error) { | ||||||
c.Assert(aws.StringValue(input.Marker), Equals, aws.StringValue(contents[3].Key)) | ||||||
c.Assert(aws.Int64Value(input.MaxKeys), Equals, int64(4)) | ||||||
return &s3.ListObjectsOutput{ | ||||||
IsTruncated: aws.Bool(false), | ||||||
Contents: contents[4:], | ||||||
}, nil | ||||||
}). | ||||||
After(forthCall) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
// Ensure we receive the items in order. | ||||||
i := 0 | ||||||
|
@@ -897,6 +922,22 @@ func (s *s3Suite) TestWalkDir(c *C) { | |||||
) | ||||||
c.Assert(err, IsNil) | ||||||
c.Assert(i, Equals, len(contents)) | ||||||
|
||||||
// test with empty subDir | ||||||
i = 0 | ||||||
err = s.storage.WalkDir( | ||||||
ctx, | ||||||
&WalkOption{ListCount: 4}, | ||||||
func(path string, size int64) error { | ||||||
comment := Commentf("index = %d", i) | ||||||
c.Assert("prefix/"+path, Equals, *contents[i].Key, comment) | ||||||
c.Assert(size, Equals, *contents[i].Size, comment) | ||||||
i++ | ||||||
return nil | ||||||
}, | ||||||
) | ||||||
c.Assert(err, IsNil) | ||||||
c.Assert(i, Equals, len(contents)) | ||||||
} | ||||||
|
||||||
// TestWalkDirBucket checks WalkDir retrieves all directory content under a bucket. | ||||||
|
@@ -927,7 +968,7 @@ func (s *s3SuiteCustom) TestWalkDirWithEmptyPrefix(c *C) { | |||||
Size: aws.Int64(27499), | ||||||
}, | ||||||
} | ||||||
s3API.EXPECT(). | ||||||
firstCall := s3API.EXPECT(). | ||||||
ListObjectsWithContext(ctx, gomock.Any()). | ||||||
DoAndReturn(func(_ context.Context, input *s3.ListObjectsInput) (*s3.ListObjectsOutput, error) { | ||||||
c.Assert(aws.StringValue(input.Bucket), Equals, "bucket") | ||||||
|
@@ -940,6 +981,20 @@ func (s *s3SuiteCustom) TestWalkDirWithEmptyPrefix(c *C) { | |||||
Contents: contents, | ||||||
}, nil | ||||||
}) | ||||||
s3API.EXPECT(). | ||||||
ListObjectsWithContext(ctx, gomock.Any()). | ||||||
DoAndReturn(func(_ context.Context, input *s3.ListObjectsInput) (*s3.ListObjectsOutput, error) { | ||||||
c.Assert(aws.StringValue(input.Bucket), Equals, "bucket") | ||||||
c.Assert(aws.StringValue(input.Prefix), Equals, "sp/") | ||||||
c.Assert(aws.StringValue(input.Marker), Equals, "") | ||||||
c.Assert(aws.Int64Value(input.MaxKeys), Equals, int64(2)) | ||||||
c.Assert(aws.StringValue(input.Delimiter), Equals, "") | ||||||
return &s3.ListObjectsOutput{ | ||||||
IsTruncated: aws.Bool(false), | ||||||
Contents: contents[:1], | ||||||
}, nil | ||||||
}). | ||||||
After(firstCall) | ||||||
|
||||||
// Ensure we receive the items in order. | ||||||
i := 0 | ||||||
|
@@ -956,4 +1011,20 @@ func (s *s3SuiteCustom) TestWalkDirWithEmptyPrefix(c *C) { | |||||
) | ||||||
c.Assert(err, IsNil) | ||||||
c.Assert(i, Equals, len(contents)) | ||||||
|
||||||
// test with non-empty sub-dir | ||||||
i = 0 | ||||||
err = storage.WalkDir( | ||||||
ctx, | ||||||
&WalkOption{SubDir: "sp", ListCount: 2}, | ||||||
func(path string, size int64) error { | ||||||
comment := Commentf("index = %d", i) | ||||||
c.Assert(path, Equals, *contents[i].Key, comment) | ||||||
c.Assert(size, Equals, *contents[i].Size, comment) | ||||||
i++ | ||||||
return nil | ||||||
}, | ||||||
) | ||||||
c.Assert(err, IsNil) | ||||||
c.Assert(i, Equals, 1) | ||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if there is a '/' already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we just
path.Clean
it 🤷There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Prefix
is parsed from url it can't contains the "/" suffix. See:br/pkg/storage/parse.go
Lines 69 to 70 in 578be7f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just not want the bare "/" prefix. for other non-empty prefixes, the suffix "/" is needed.
BTW, maybe we shouldn't depend on the
Prefix
filed to contain the "/" suffix, but in this way, we need to change more code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the user wants to load all data from one bucket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original pr is try to resolve this issue then. If the input path is the bucket name, we should leave the prefix parameter empty in the
ListObject
request, otherwise, s3 will return empty result.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about checking suffix too? In case the API is called from other projects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done