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

Lock the random access if a forward or backward seek is detected #1250

Open
wants to merge 1 commit into
base: uberChannelLimit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ public void updateAccessPattern(long currentPosition) {
return;
}
if (readOptions.getFadvise() == Fadvise.AUTO_RANDOM) {
if (randomAccess) {
if (isBackwardOrForwardSeekNotRequested()) {
if (isSequentialAccessPattern(currentPosition)) {
unsetRandomAccess();
}
} else {
if (isRandomAccessPattern(currentPosition)) {
} else if (isRandomAccessPattern(currentPosition)) {
setRandomAccess();
}
}
Expand Down Expand Up @@ -151,18 +149,21 @@ private boolean isRandomAccessPattern(long currentPosition) {
return false;
}

private boolean isBackwardOrForwardSeekNotRequested() {
return !isBackwardSeekRequested && !isForwardSeekRequested;
}

private boolean shouldDetectSequentialAccess() {
return randomAccess
&& !isBackwardSeekRequested
&& !isForwardSeekRequested
&& isBackwardOrForwardSeekNotRequested()
&& consecutiveSequentialCount >= readOptions.getFadviseRequestTrackCount()
&& readOptions.getFadvise() == Fadvise.AUTO_RANDOM;
}

private boolean shouldDetectRandomAccess() {
return !randomAccess
Copy link
Contributor

Choose a reason for hiding this comment

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

If already in randomAccess mode there is no need to detect random access.

I do agree that the current logic will not update backwardSeek and forwardSeek if occurredwhen random access was set but I would suggest updating those flags well within fn:updateAccessPattern .

&& (readOptions.getFadvise() == Fadvise.AUTO
|| readOptions.getFadvise() == Fadvise.AUTO_RANDOM);
return (!randomAccess && readOptions.getFadvise() == Fadvise.AUTO)
|| (isBackwardOrForwardSeekNotRequested()
&& readOptions.getFadvise() == Fadvise.AUTO_RANDOM);
}

private void setRandomAccess() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,28 @@ public void testAutoRandomMode() {
assertThat(fileAccessPattern.isRandomAccessPattern()).isEqualTo(expectedRandomAccess[i]);
fileAccessPattern.updateLastServedIndex(currentPosition);
}

// R --> R backward seek
// a backward seek should lock the random pattern
readIndexes = new long[] {4, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4};
expectedRandomAccess =
new boolean[] {true, true, true, true, true, true, true, true, true, true, true};
for (int i = 0; i < readIndexes.length; i++) {
long currentPosition = readIndexes[i];
fileAccessPattern.updateAccessPattern(currentPosition);
assertThat(fileAccessPattern.isRandomAccessPattern()).isEqualTo(expectedRandomAccess[i]);
fileAccessPattern.updateLastServedIndex(currentPosition);
}

// R --> R forward seek
// a forward seek should lock the random pattern
readIndexes = new long[] {0, 11, 12, 13, 14, 15};
expectedRandomAccess = new boolean[] {true, true, true, true, true, true};
for (int i = 0; i < readIndexes.length; i++) {
long currentPosition = readIndexes[i];
fileAccessPattern.updateAccessPattern(currentPosition);
assertThat(fileAccessPattern.isRandomAccessPattern()).isEqualTo(expectedRandomAccess[i]);
fileAccessPattern.updateLastServedIndex(currentPosition);
}
}
}