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

Add CopyFileAsync to ICoreFileStorageService #5581

Merged
merged 1 commit into from
Mar 7, 2018
Merged

Conversation

joelverhagen
Copy link
Member

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check input

Copy link
Member Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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.

Copy link
Member Author

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));
}
}
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Member Author

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).

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check input

Copy link
Member Author

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);
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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);
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

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)
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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)

Copy link
Contributor

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?

Copy link
Member Author

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: *.

Copy link
Contributor

@skofman1 skofman1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

@joelverhagen
Copy link
Member Author

🔔 comments adressed.

@joelverhagen joelverhagen merged commit 262741e into dev Mar 7, 2018
@joelverhagen joelverhagen deleted the jver-copyapi branch March 7, 2018 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants