-
Notifications
You must be signed in to change notification settings - Fork 191
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 handling of artifact range requests #1445
base: master
Are you sure you want to change the base?
Conversation
Can one of the admins verify this patch? |
d2940c9
to
e6407fc
Compare
Artifact range requests in HawkBit were impossible to do efficiently, as the underlying mechanism had no choice but to read the start byte and discard content both before and after. To address this situation, we need to introduce a new method to DbArtifact: getFileInputStream(long, long), which maps to the semantics of a range request. The next step is to adjust FileStreamingUtil to use it for both simple range and multi-part requests. Signed-off-by: Zygmunt Krynicki <[email protected]>
e6407fc
to
c684a77
Compare
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.
Hi @zyga,
thanks for your contribution. Sorry, for the delayed review.
I did the review and do have some comments.
* | ||
* @return {@link InputStream} to read from artifact. | ||
*/ | ||
InputStream getFileInputStream(long start, long end); |
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.
here an default implementation could be provided - one that skips the reading of input stream start.
@@ -63,4 +63,9 @@ public String getContentType() { | |||
public InputStream getFileInputStream() { | |||
return decryptionFunction.apply(encryptedDbArtifact.getFileInputStream()); | |||
} | |||
|
|||
@Override | |||
public InputStream getFileInputStream(long start, long end) { |
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.
start and end are pointers in the plain (decrypted input stream).
here in encryptedDbArtifact.getFileInputStream(start, end) they are applied to the encrypted stream where the offsets could differ.
Also, decryption function could be stateful and depend on the previous content.
I'd propose to implement implement default range function and to use it for that DB
@@ -340,8 +340,6 @@ private static long copyStreams(final InputStream from, final OutputStream to, | |||
long total = 0; | |||
int progressPercent = 1; | |||
|
|||
ByteStreams.skipFully(from, start); |
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 this method, now reads from 0 to length (exclusively) "final long start" is little bit misleading.
I'd propose to remove start and file name parameters and to log start/end in callers
Or at least rename start / length to rangeStart / rangeLength so the start param to be not correlated to input stream start offset
public InputStream getFileInputStream(long start, long end) { | ||
try { | ||
var f = new RandomAccessFile(file, "r"); | ||
var ch = f.getChannel(); |
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 not add an additional dependency on com.google.common
wouldn't
f.seek(start);
return f;
do the same?
Quality Gate failedFailed conditions See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
Artifact range requests in HawkBit were impossible to do efficiently, as the underlying mechanism had no choice but to read the start byte and discard content both before and after.
To address this situation, we need to introduce a new method to DbArtifact: getFileInputStream(long, long), which maps to the semantics of a range request.
The next step is to adjust FileStreamingUtil to use it for both simple range and multi-part requests.