-
Notifications
You must be signed in to change notification settings - Fork 361
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
Fix S3 gateway cross-repo copies #7468
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
754398d
Fix S3 gateway cross-repo copies
arielshaqed 1dcdf87
Test S3 gateway multipart copy in Esti
arielshaqed b37f996
[esti] Use sigV4 for S3 gateway MPU copy tests
arielshaqed b2602ae
Add copy-source to sigV2 signed headers and restore sigV2 signing
arielshaqed 52fef46
[bug] Make randomReader return EOF when it's done
arielshaqed 52b6c8e
Try again with sigv4
arielshaqed c7fef45
[bug] Actually request multipart-range in copy
arielshaqed 155cfdc
[bug] Use distinct repository name from TestS3CopyObject
arielshaqed 767ebc3
[bug] Start, End on MinIO client CopySrcOptions are inclusive bounds
arielshaqed 02411e1
[bug] Azure copyPartRange should stage block on destination
arielshaqed f623b3f
[CR] Put all "const ...ContentLength..." together and document them
arielshaqed b9227a7
[CR] Rename RandomReader -> NewRandomReader
arielshaqed 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
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 |
---|---|---|
|
@@ -174,9 +174,20 @@ func getMultipartSize(ctx context.Context, container container.Client, objName s | |
return int64(size), nil | ||
} | ||
|
||
func copyPartRange(ctx context.Context, destinationContainer container.Client, destinationObjName string, sourceBlobURL blockblob.Client, startPosition, count int64) (*block.UploadPartResponse, error) { | ||
func copyPartRange(ctx context.Context, clientCache *ClientCache, destinationKey, sourceKey BlobURLInfo, startPosition, count int64) (*block.UploadPartResponse, error) { | ||
destinationContainer, err := clientCache.NewContainerClient(destinationKey.StorageAccountName, destinationKey.ContainerName) | ||
if err != nil { | ||
return nil, fmt.Errorf("copy part: get destination client: %w", err) | ||
} | ||
sourceContainer, err := clientCache.NewContainerClient(sourceKey.StorageAccountName, sourceKey.ContainerName) | ||
if err != nil { | ||
return nil, fmt.Errorf("copy part: get source client: %w", err) | ||
} | ||
base64BlockID := generateRandomBlockID() | ||
_, err := sourceBlobURL.StageBlockFromURL(ctx, base64BlockID, sourceBlobURL.URL(), | ||
destinationBlob := destinationContainer.NewBlockBlobClient(destinationKey.BlobURL) | ||
sourceBlob := sourceContainer.NewBlockBlobClient(sourceKey.BlobURL) | ||
|
||
stageBlockResponse, err := destinationBlob.StageBlockFromURL(ctx, base64BlockID, sourceBlob.URL(), | ||
&blockblob.StageBlockFromURLOptions{ | ||
Range: blob.HTTPRange{ | ||
Offset: startPosition, | ||
|
@@ -187,25 +198,20 @@ func copyPartRange(ctx context.Context, destinationContainer container.Client, d | |
return nil, err | ||
} | ||
|
||
// add size and id to etag | ||
response, err := sourceBlobURL.GetProperties(ctx, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
etag := "\"" + hex.EncodeToString(response.ContentMD5) + "\"" | ||
size := response.ContentLength | ||
// add size, etag | ||
etag := "\"" + hex.EncodeToString(stageBlockResponse.ContentMD5) + "\"" | ||
base64Etag := base64.StdEncoding.EncodeToString([]byte(etag)) | ||
// stage id data | ||
blobIDsURL := destinationContainer.NewBlockBlobClient(destinationObjName + idSuffix) | ||
_, err = blobIDsURL.StageBlock(ctx, base64Etag, streaming.NopCloser(strings.NewReader(base64BlockID+"\n")), nil) | ||
blobIDsBlob := destinationContainer.NewBlockBlobClient(destinationKey.BlobURL + idSuffix) | ||
_, err = blobIDsBlob.StageBlock(ctx, base64Etag, streaming.NopCloser(strings.NewReader(base64BlockID+"\n")), nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed staging part data: %w", err) | ||
} | ||
|
||
// stage size data | ||
sizeData := fmt.Sprintf("%d\n", size) | ||
blobSizesURL := destinationContainer.NewBlockBlobClient(destinationObjName + sizeSuffix) | ||
_, err = blobSizesURL.StageBlock(ctx, base64Etag, streaming.NopCloser(strings.NewReader(sizeData)), nil) | ||
sizeData := fmt.Sprintf("%d\n", count) | ||
blobSizesBlob := destinationContainer.NewBlockBlobClient(destinationKey.BlobURL + sizeSuffix) | ||
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. Consider moving sizeSuffix and idSuffix to this file 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. Not done in this PR. |
||
_, err = blobSizesBlob.StageBlock(ctx, base64Etag, streaming.NopCloser(strings.NewReader(sizeData)), nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed staging part data: %w", err) | ||
} | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package testutil | ||
|
||
import ( | ||
"hash/crc64" | ||
"io" | ||
) | ||
|
||
const bufSize = 4 << 16 | ||
|
||
var table *crc64.Table = crc64.MakeTable(crc64.ECMA) | ||
|
||
// ChecksumReader returns the checksum (CRC-64) of the contents of reader. | ||
func ChecksumReader(reader io.Reader) (uint64, error) { | ||
buf := make([]byte, bufSize) | ||
var val uint64 | ||
for { | ||
n, err := reader.Read(buf) | ||
if err != nil { | ||
if err == io.EOF { | ||
return val, nil | ||
} | ||
return val, err | ||
} | ||
if n == 0 { | ||
return val, nil | ||
} | ||
val = crc64.Update(val, table, buf[:n]) | ||
} | ||
} |
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
Oops, something went wrong.
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.
: 🎉
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 only thing tests are good for are finding bugs. And fixing them. And preventing regressions. Automatically. Not sure it's worth the effort.
Although... in this case this test actually found bugs. And helped fix one of them. And another test in the file prevented a regression. Automatically. Actually the case against writing tests has never been weaker 🥳 .