-
Notifications
You must be signed in to change notification settings - Fork 362
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
Azure: Add support for async copy #5118
Merged
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e2ebe9b
Azure: Add support for async copy
N-o-Z 1b3e213
CR Fixes
N-o-Z 9d0b492
CR Fixes 2
N-o-Z 6527b3f
Merge remote-tracking branch 'origin/master' into azure/add-support-f…
N-o-Z d034e6e
Merge remote-tracking branch 'origin/master' into azure/add-support-f…
N-o-Z da38dc6
Fix Azure auth_method deprecation
N-o-Z 4ae6c76
Cache UDC
N-o-Z 862c8c1
CR fixes
N-o-Z c4ea581
Lint error
N-o-Z 0a161cd
Remove auth_method from documentation
N-o-Z c353794
Update pkg/block/errors.go
N-o-Z f0527f7
Fixes 2
N-o-Z 72bb093
Fixes 3
N-o-Z a921fc1
Fixes 4
N-o-Z 4d3a10b
Fixes 5
N-o-Z 2fe29a1
Fixes 6
N-o-Z 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 |
---|---|---|
@@ -0,0 +1,194 @@ | ||
package esti | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/go-test/deep" | ||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/require" | ||
"github.com/treeverse/lakefs/pkg/api" | ||
"github.com/treeverse/lakefs/pkg/block" | ||
"github.com/treeverse/lakefs/pkg/block/azure" | ||
"github.com/treeverse/lakefs/pkg/config" | ||
) | ||
|
||
const ( | ||
s3CopyDataPath = "s3://esti-system-testing-data/copy-test-data/" | ||
gsCopyDataPath = "gs://esti-system-testing-data/copy-test-data/" | ||
azureCopyDataPathTemplate = "https://%s.blob.core.windows.net/esti-system-testing-data/copy-test-data/" | ||
azureAbortAccount = "esti4multipleaccounts" | ||
ingestionBranch = "test-data" | ||
largeObject = "squash.tar" | ||
) | ||
|
||
func TestCopyObject(t *testing.T) { | ||
ctx, _, repo := setupTest(t) | ||
defer tearDownTest(repo) | ||
|
||
t.Run("copy_large_size_file", func(t *testing.T) { | ||
blockstoreType := viper.GetString(config.BlockstoreTypeKey) | ||
var ( | ||
accountName string | ||
err error | ||
) | ||
// Copying from same account occurs immediately even for large files (async) | ||
if blockstoreType == block.BlockstoreTypeAzure { // Extract storage account | ||
resp, err := client.GetRepositoryWithResponse(ctx, repo) | ||
require.NoError(t, err) | ||
require.Equal(t, http.StatusOK, resp.StatusCode()) | ||
u, err := url.Parse(resp.JSON200.StorageNamespace) | ||
require.NoError(t, err) | ||
accountName, err = azure.ExtractStorageAccount(u) | ||
require.NoError(t, err) | ||
} | ||
|
||
importTestData(t, ctx, client, repo, accountName) | ||
N-o-Z marked this conversation as resolved.
Show resolved
Hide resolved
|
||
res, err := client.StatObjectWithResponse(ctx, repo, ingestionBranch, &api.StatObjectParams{ | ||
Path: largeObject, | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, http.StatusOK, res.StatusCode()) | ||
|
||
objStat := res.JSON200 | ||
destPath := "foo" | ||
srcBranch := ingestionBranch | ||
copyResp, err := client.CopyObjectWithResponse(ctx, repo, "main", &api.CopyObjectParams{ | ||
DestPath: destPath, | ||
}, api.CopyObjectJSONRequestBody{ | ||
SrcPath: largeObject, | ||
SrcRef: &srcBranch, | ||
}) | ||
require.NoError(t, err, "failed to copy") | ||
require.NotNil(t, copyResp.JSON201) | ||
|
||
// Verify creation path, date and physical address are different | ||
copyStat := copyResp.JSON201 | ||
require.NotEqual(t, objStat.PhysicalAddress, copyStat.PhysicalAddress) | ||
require.GreaterOrEqual(t, copyStat.Mtime, objStat.Mtime) | ||
require.Equal(t, destPath, copyStat.Path) | ||
|
||
// Verify all else is equal | ||
objStat.Mtime = copyStat.Mtime | ||
objStat.Path = copyStat.Path | ||
objStat.PhysicalAddress = copyStat.PhysicalAddress | ||
require.Nil(t, deep.Equal(objStat, copyStat)) | ||
|
||
// get back info | ||
statResp, err := client.StatObjectWithResponse(ctx, repo, "main", &api.StatObjectParams{Path: destPath}) | ||
require.NoError(t, err) | ||
require.Equal(t, http.StatusOK, statResp.StatusCode()) | ||
require.Nil(t, deep.Equal(statResp.JSON200, copyStat)) | ||
}) | ||
|
||
// Copying different accounts takes more time and allows us to abort the copy in the middle | ||
t.Run("copy_large_size_file_abort", func(t *testing.T) { | ||
requireBlockstoreType(t, block.BlockstoreTypeAzure) | ||
importTestData(t, ctx, client, repo, azureAbortAccount) | ||
var err error | ||
res, err := client.StatObjectWithResponse(ctx, repo, ingestionBranch, &api.StatObjectParams{ | ||
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. err shadow on the second line. would move the err to the inner scope or name it diff. |
||
Path: largeObject, | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, http.StatusOK, res.StatusCode()) | ||
N-o-Z marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
destPath := "bar" | ||
srcBranch := ingestionBranch | ||
cancelCtx, cancel := context.WithCancel(ctx) | ||
N-o-Z marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var ( | ||
wg sync.WaitGroup | ||
copyResp *api.CopyObjectResponse | ||
) | ||
// Run copy object async and cancel context after 5 seconds | ||
go func() { | ||
wg.Add(1) | ||
copyResp, err = client.CopyObjectWithResponse(cancelCtx, repo, "main", &api.CopyObjectParams{ | ||
DestPath: destPath, | ||
}, api.CopyObjectJSONRequestBody{ | ||
SrcPath: largeObject, | ||
SrcRef: &srcBranch, | ||
}) | ||
defer wg.Done() | ||
N-o-Z marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}() | ||
|
||
time.Sleep(5 * time.Second) | ||
cancel() | ||
wg.Wait() | ||
require.ErrorIs(t, err, context.Canceled) | ||
require.Nil(t, copyResp) | ||
|
||
// Verify object doesn't exist | ||
|
||
// get back info | ||
N-o-Z marked this conversation as resolved.
Show resolved
Hide resolved
|
||
statResp, err := client.StatObjectWithResponse(ctx, repo, "main", &api.StatObjectParams{Path: destPath}) | ||
require.NoError(t, err) | ||
require.Equal(t, http.StatusNotFound, statResp.StatusCode()) | ||
}) | ||
} | ||
|
||
func importTestData(t *testing.T, ctx context.Context, client api.ClientWithResponsesInterface, repoName, azAccountName string) { | ||
t.Helper() | ||
importPath := "" | ||
blockstoreType := viper.GetString(config.BlockstoreTypeKey) | ||
switch blockstoreType { | ||
case block.BlockstoreTypeS3: | ||
importPath = s3CopyDataPath | ||
case block.BlockstoreTypeGS: | ||
importPath = gsCopyDataPath | ||
case block.BlockstoreTypeAzure: | ||
importPath = fmt.Sprintf(azureCopyDataPathTemplate, azAccountName) | ||
N-o-Z marked this conversation as resolved.
Show resolved
Hide resolved
|
||
default: | ||
t.Skip("import isn't supported for non-production block adapters") | ||
} | ||
var ( | ||
after = "" | ||
token *string | ||
ranges []api.RangeMetadata | ||
) | ||
for { | ||
resp, err := client.IngestRangeWithResponse(ctx, repoName, api.IngestRangeJSONRequestBody{ | ||
After: after, | ||
ContinuationToken: token, | ||
FromSourceURI: importPath, | ||
}) | ||
require.NoError(t, err, "failed to ingest range") | ||
require.Equal(t, http.StatusCreated, resp.StatusCode()) | ||
require.NotNil(t, resp.JSON201) | ||
ranges = append(ranges, *resp.JSON201.Range) | ||
if !resp.JSON201.Pagination.HasMore { | ||
break | ||
} | ||
after = resp.JSON201.Pagination.LastKey | ||
token = resp.JSON201.Pagination.ContinuationToken | ||
} | ||
|
||
metarangeResp, err := client.CreateMetaRangeWithResponse(ctx, repoName, api.CreateMetaRangeJSONRequestBody{ | ||
Ranges: ranges, | ||
}) | ||
|
||
require.NoError(t, err, "failed to create metarange") | ||
require.Equal(t, http.StatusCreated, metarangeResp.StatusCode()) | ||
N-o-Z marked this conversation as resolved.
Show resolved
Hide resolved
|
||
require.NotNil(t, metarangeResp.JSON201.Id) | ||
|
||
_, err = client.CreateBranchWithResponse(ctx, repoName, api.CreateBranchJSONRequestBody{ | ||
Name: ingestionBranch, | ||
Source: "main", | ||
}) | ||
require.NoError(t, err, "failed to create branch") | ||
|
||
commitResp, err := client.CommitWithResponse(ctx, repoName, ingestionBranch, &api.CommitParams{ | ||
SourceMetarange: metarangeResp.JSON201.Id, | ||
}, api.CommitJSONRequestBody{ | ||
Message: "created by import", | ||
Metadata: &api.CommitCreation_Metadata{ | ||
AdditionalProperties: map[string]string{"created_by": "import"}, | ||
}, | ||
}) | ||
require.NoError(t, err, "failed to commit") | ||
require.Equal(t, http.StatusCreated, commitResp.StatusCode()) | ||
N-o-Z marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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
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
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
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.
Relevant to all the places we used
SkipTestIfAskedTo
, check with @idanovo if we still this feature as part of our system test code.This enabled us to skip specific tests by demand.
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 still use 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.
Moved it to setupTest function and removed explicit call where setupTest is used
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.
setupTest
- it setup a repository.setupTest
should also cleanup the repository for the cases we didn't defer cleanup 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.
setupTest doesn't perform cleanup - this is done by the teardownTest function, this is the case currently.
Moving the call under setupTest ensures it is not missed by anyone creating a new test and using this function.
setupTest does setup a repository but it is called "setupTest" and not "createRepository" I assume we can use it for other purposes of setting up a test - including skipping under certain circumstances