Avoid unnecessary seeks in seekToNextEventPosition

When an exact match is found during the binary search for the
next event, use the matching block instead of seeking from the
'low' block.

Add toString method to DLQEntry

Fixes #7464
This commit is contained in:
Rob Bavey 2017-06-15 10:02:22 -04:00
parent 6b5379026e
commit 036caeb21a
2 changed files with 16 additions and 2 deletions

View file

@ -112,4 +112,15 @@ public class DLQEntry implements Cloneable, Serializable, Queueable {
public Timestamp getEntryTime() {
return entryTime;
}
@Override
public String toString() {
return "DLQEntry{" +
"event=" + event +
", pluginType='" + pluginType + '\'' +
", pluginId='" + pluginId + '\'' +
", reason='" + reason + '\'' +
", entryTime=" + entryTime +
'}';
}
}

View file

@ -43,6 +43,7 @@ public class RecordIOReader {
private int currentBlockSizeReadFromChannel;
private final Path path;
private long channelPosition;
private static final int UNSET = -1;
public RecordIOReader(Path path) throws IOException {
this.path = path;
@ -74,7 +75,7 @@ public class RecordIOReader {
}
public <T> byte[] seekToNextEventPosition(T target, Function<byte[], T> keyExtractor, Comparator<T> keyComparator) throws IOException {
int matchingBlock;
int matchingBlock = UNSET;
int lowBlock = 0;
int highBlock = (int) (channel.size() - VERSION_SIZE) / BLOCK_SIZE;
@ -96,7 +97,9 @@ public class RecordIOReader {
break;
}
}
matchingBlock = lowBlock;
if (matchingBlock == UNSET) {
matchingBlock = lowBlock;
}
// now sequential scan to event
seekToBlock(matchingBlock);