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

Fix handling of artifact range requests #1445

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zyga
Copy link
Contributor

@zyga zyga commented Oct 2, 2023

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.

@hawkbit-bot
Copy link

Can one of the admins verify this patch?

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 <me@zygoon.pl>
@zyga zyga force-pushed the fix/better-range-requests branch from e6407fc to c684a77 Compare October 2, 2023 20:28
Copy link
Contributor

@avgustinmm avgustinmm left a 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);
Copy link
Contributor

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

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

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

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?

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.

None yet

3 participants