Skip to content

Commit

Permalink
Fix the problem that getLastMappedFile function affects performance
Browse files Browse the repository at this point in the history
  • Loading branch information
guyinyou committed Sep 25, 2023
1 parent 88a9d93 commit 223a2a5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,19 @@ public MappedFile getLastMappedFile(final long startOffset) {
}

public MappedFile getLastMappedFile() {
MappedFile[] mappedFiles = this.mappedFiles.toArray(new MappedFile[0]);
return mappedFiles.length == 0 ? null : mappedFiles[mappedFiles.length - 1];
MappedFile mappedFileLast = null;
while (!this.mappedFiles.isEmpty()) {
try {
mappedFileLast = this.mappedFiles.get(this.mappedFiles.size() - 1);
break;
} catch (IndexOutOfBoundsException e) {
//continue;
} catch (Exception e) {
log.error("getLastMappedFile has exception.", e);
break;
}
}
return mappedFileLast;
}

public boolean resetOffset(long offset) {
Expand Down

0 comments on commit 223a2a5

Please sign in to comment.