Skip to content

Fix handling of artifact range requests#1445

Closed
zyga wants to merge 1 commit intoeclipse-hawkbit:masterfrom
zyga:fix/better-range-requests
Closed

Fix handling of artifact range requests#1445
zyga wants to merge 1 commit intoeclipse-hawkbit:masterfrom
zyga:fix/better-range-requests

Conversation

@zyga
Copy link
Copy Markdown
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
Copy Markdown

Can one of the admins verify this patch?

@zyga zyga force-pushed the fix/better-range-requests branch 3 times, most recently from d2940c9 to e6407fc Compare October 2, 2023 19:47
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
Copy Markdown
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
Copy Markdown
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.

}

@Override
public InputStream getFileInputStream(long start, long end) {
Copy link
Copy Markdown
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

long total = 0;
int progressPercent = 1;

ByteStreams.skipFully(from, start);
Copy link
Copy Markdown
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
Copy Markdown
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?

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Oct 7, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
B Security Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@github-advanced-security
Copy link
Copy Markdown

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.

@avgustinmm
Copy link
Copy Markdown
Contributor

Closing as outdated - no communication and including conflicts. If still interested in PR I could reopen it or new one could be created

@avgustinmm avgustinmm closed this Jan 6, 2025
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.

4 participants