-
Notifications
You must be signed in to change notification settings - Fork 644
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
Add CopyFileAsync to ICoreFileStorageService #5581
Conversation
168c99a
to
c64a3c7
Compare
@@ -168,6 +169,34 @@ public Task SaveFileAsync(string folderName, string fileName, Stream packageFile | |||
return Task.FromResult(0); | |||
} | |||
|
|||
public Task CopyFileAsync(string srcFolderName, string srcFileName, string destFolderName, string destFileName) |
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.
check input
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.
Fixed.
|
||
public virtual void Copy(string sourceFileName, string destFileName, bool overwrite) | ||
{ | ||
File.Copy(sourceFileName, destFileName, overwrite); |
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.
can we make this async? https://stackoverflow.com/questions/882686/asynchronous-file-copy-move-in-c-sharp
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.
I'd rather use the high level file system API on File
. We don't use this in production so I'd rather favor small code. We can switch to async later if the performance will be helped.
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.
Did some tests. Performance is worse.
{ | ||
return Convert.ToBase64String(hashAlgorithm.ComputeHash(fileStream)); | ||
} | ||
} |
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's the perf of this? Please test on files of size 250M
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.
Perf is bound by disk. Note we don't use the FileSystemFileStorageService
in production. We can optimize this later if necessary.
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.
I added this so the method would have similar semantics to the blob storage implementation (which no-ops if the destination file is the same).
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 need to understand the perf. If the hash takes much longer then the copy itself, doesn't make sense to do 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.
Sure, I'll get some numbers on disk and SSD.
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.
You're right. File.Copy
is freakishly fast and file comparison is slow.
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.
Removed the check.
@@ -100,6 +104,60 @@ public CloudBlobCoreFileStorageService(ICloudBlobClient client) | |||
} | |||
} | |||
|
|||
public async Task CopyFileAsync(string srcFolderName, string srcFileName, string destFolderName, string destFileName) |
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.
check input
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.
Fixed.
@@ -16,6 +17,9 @@ namespace NuGetGallery | |||
{ | |||
public class CloudBlobCoreFileStorageService : ICoreFileStorageService | |||
{ | |||
private static readonly TimeSpan MaxCopyDuration = TimeSpan.FromMinutes(10); | |||
private static readonly TimeSpan CopyPollFrequency = TimeSpan.FromMilliseconds(100); |
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.
seems too small. What is this number based on?
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.
Agree, I've seen some examples online that use 500ms.
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.
Fixed.
@@ -16,6 +17,9 @@ namespace NuGetGallery | |||
{ | |||
public class CloudBlobCoreFileStorageService : ICoreFileStorageService | |||
{ | |||
private static readonly TimeSpan MaxCopyDuration = TimeSpan.FromMinutes(10); |
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 is this number based on?
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.
This is the max operation timeout for China uploads.
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.
Comment would be good here
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.
Fixed.
await Task.Delay(CopyPollFrequency); | ||
} | ||
|
||
if (destBlob.CopyState.Status == CopyStatus.Pending) |
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.
should we kill the copy operation in those cases?
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.
I decided against this because we can still recover if the caller calls this CopyFileAsync
method later. Consider if the timeout occurs, exception is thrown, and orchestrator tries again via service bus message. Things can still work out.
I would rather take this approach than aborting and trying again over and over.
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.
(since would rather trust blob storage server side to get the job done eventually than us trying to start it every N minutes)
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 trigger a copy operation and the previous copy is still in progress?
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 won't even start. We have a precondition If-None-Match: *
.
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.
🕐
Progress on NuGet/Engineering#1190 Progress on NuGet/Engineering#1203
110f141
to
262741e
Compare
🔔 comments adressed. |
Progress on https://github.com/NuGet/Engineering/issues/1190
Progress on https://github.com/NuGet/Engineering/issues/1203