Skip to content
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 @@ -173,7 +173,10 @@ public QueryOffsetResult queryOffset(String topic, String key, int maxNum, long
public QueryOffsetResult queryOffset(String topic, String key, int maxNum, long begin, long end, String indexType) {
long indexLastUpdateTimestamp = 0;
long indexLastUpdatePhyoffset = 0;
maxNum = Math.min(maxNum, this.defaultMessageStore.getMessageStoreConfig().getMaxMsgsNumBatch());
// maxNum comes from the request header and is only checked for null,
// so a negative value must be clamped here instead of blowing up the
// ArrayList allocation below with an IllegalArgumentException.
maxNum = Math.min(Math.max(maxNum, 0), this.defaultMessageStore.getMessageStoreConfig().getMaxMsgsNumBatch());
List<Long> phyOffsets = new ArrayList<>(maxNum);
try {
this.readWriteLock.readLock().lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@ public void testQueryOffsetWithZeroMaxNum() {
assertNotNull(result);
assertEquals(Collections.emptyList(), result.getPhyOffsets());
}

@Test
public void testQueryOffsetWithNegativeMaxNum() {
QueryOffsetResult result = indexService.queryOffset("test", "testKey", -1, 0, 100);
assertNotNull(result);
assertEquals(Collections.emptyList(), result.getPhyOffsets());
}
}