This is an automated email from the ASF dual-hosted git repository.

jinrongtong pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new d7e5c4d1a4 [ISSUE #7389] Fix the problem that getLastMappedFile 
function affects performance
d7e5c4d1a4 is described below

commit d7e5c4d1a4e048cd97f0b29a96a0fc575927a03e
Author: guyinyou <[email protected]>
AuthorDate: Mon Sep 25 13:37:36 2023 +0800

    [ISSUE #7389] Fix the problem that getLastMappedFile function affects 
performance
    
    Co-authored-by: guyinyou <[email protected]>
---
 .../java/org/apache/rocketmq/store/MappedFileQueue.java   | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java 
b/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java
index 32b90d14f7..9a0824829e 100644
--- a/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java
+++ b/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java
@@ -377,8 +377,19 @@ public class MappedFileQueue implements Swappable {
     }
 
     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) {

Reply via email to