Skip to content

Commit cd6bec6

Browse files
authored
[ISSUE #9441] Add file length check in IndexService (#9442)
1 parent 577371e commit cd6bec6

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

tieredstore/src/main/java/org/apache/rocketmq/tieredstore/index/IndexStoreFile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ protected CompletableFuture<List<IndexItem>> queryAsyncFromUnsealedFile(
314314
protected CompletableFuture<List<IndexItem>> queryAsyncFromSegmentFile(
315315
String key, int maxCount, long beginTime, long endTime) {
316316

317-
if (this.fileSegment == null || !UPLOAD.equals(this.fileStatus.get())) {
317+
if (this.fileSegment == null || !UPLOAD.equals(this.fileStatus.get()) ||
318+
this.fileSegment.getCommitPosition() <= this.getSlotPosition(0)) {
318319
return CompletableFuture.completedFuture(Collections.emptyList());
319320
}
320321

tieredstore/src/main/java/org/apache/rocketmq/tieredstore/provider/FileSegment.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,22 +325,25 @@ public ByteBuffer read(long position, int length) {
325325

326326
public CompletableFuture<ByteBuffer> readAsync(long position, int length) {
327327
CompletableFuture<ByteBuffer> future = new CompletableFuture<>();
328+
328329
if (position < 0 || position >= commitPosition) {
329-
future.completeExceptionally(new TieredStoreException(
330-
TieredStoreErrorCode.ILLEGAL_PARAM, "FileSegment read position is illegal position"));
330+
future.completeExceptionally(new TieredStoreException(TieredStoreErrorCode.ILLEGAL_PARAM,
331+
String.format("FileSegment read position illegal, filePath=%s, fileType=%s, position=%d, length=%d, commit=%d",
332+
filePath, fileType, position, length, commitPosition)));
331333
return future;
332334
}
333335

334336
if (length <= 0) {
335-
future.completeExceptionally(new TieredStoreException(
336-
TieredStoreErrorCode.ILLEGAL_PARAM, "FileSegment read length illegal"));
337+
future.completeExceptionally(new TieredStoreException(TieredStoreErrorCode.ILLEGAL_PARAM,
338+
String.format("FileSegment read length illegal, filePath=%s, fileType=%s, position=%d, length=%d, commit=%d",
339+
filePath, fileType, position, length, commitPosition)));
337340
return future;
338341
}
339342

340343
int readableBytes = (int) (commitPosition - position);
341344
if (readableBytes < length) {
342345
length = readableBytes;
343-
log.debug("FileSegment#readAsync, expect request position is greater than commit position, " +
346+
log.debug("FileSegment expect request position is greater than commit position, " +
344347
"file: {}, request position: {}, commit position: {}, change length from {} to {}",
345348
getPath(), position, commitPosition, length, readableBytes);
346349
}

0 commit comments

Comments
 (0)