-
Notifications
You must be signed in to change notification settings - Fork 126
RSDK-12274: Streaming file copy: write to temp file & rename on success #5424
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
Conversation
|
LGTM @aldenh-viam. I like the idea of ensuring the file copy is completed before naming the file the expected name. That will fix the state we are seeing. |
cheukt
left a comment
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 add a test for this?
| } else { | ||
| // Since file may be streamed (see copyFile in copy_rpc.go), write to a temp file (filename.download) and rename after the download | ||
| // has completed. This way a temporary network blip won't leave a corrupted partial file in the expected location. | ||
| // Technically the temp file can be deleted upon any Copy error, but it will also be clobbered next time we retry. |
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.
let's do a best effort clean up here, would suck if the partially downloaded module is very large and we just leave it hanging around
8efaa34 to
91ff31b
Compare
cheukt
left a comment
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.
LGTM - thanks for adding the test!
shellRPCFileReadCopier / shellFileCopyWriterin services/shell/copy_rpc.go uses a gRPC stream to upload a large file in chunks directly into the specified filename. If there is a network blip midway through the transfer, the partial file is left on the destination. If this happens during aviam module reload, RDK'sreconfigurewill repeatedly try loading the corruptedmodulename.tar.gzand failing.This change makes
shellRPCFileReadCopierwrite files to a temporaryfilename.downloadand rename it tofilenameonly if the stream completes without error.Note: this
Copymethod also supports directories, but if my understanding is correct, it only creates empty directories for future files, so it doesn't need the same write-to-temp-and-rename logic.cc @michaellee1019 @cheukt: team discussed offline and we believe we don't want to skip failed packages and proceed with regular startup to avoid the possibility of the robot getting stuck in a bad config state.