From f2759f8355050d799a9295747af9201c2327e8bd Mon Sep 17 00:00:00 2001 From: hexueyuan Date: Mon, 11 Nov 2024 17:56:32 +0800 Subject: [PATCH] Fix duplicate mapped file in mutil commitlog store path mode. --- .../apache/rocketmq/store/AllocateMappedFileService.java | 2 +- .../apache/rocketmq/store/MultiPathMappedFileQueueTest.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/store/src/main/java/org/apache/rocketmq/store/AllocateMappedFileService.java b/store/src/main/java/org/apache/rocketmq/store/AllocateMappedFileService.java index 273f732dac0..79227a3567a 100644 --- a/store/src/main/java/org/apache/rocketmq/store/AllocateMappedFileService.java +++ b/store/src/main/java/org/apache/rocketmq/store/AllocateMappedFileService.java @@ -163,7 +163,7 @@ private boolean mmapOperation() { AllocateRequest req = null; try { req = this.requestQueue.take(); - String fileName = req.getFilePath().substring(req.getFilePath().lastIndexOf("/") + 1); + String fileName = req.getFilePath().substring(req.getFilePath().lastIndexOf(File.separator) + 1); AllocateRequest expectedRequest = this.requestTable.get(fileName); if (null == expectedRequest) { log.warn("this mmap request expired, maybe cause timeout " + req.getFilePath() + " " diff --git a/store/src/test/java/org/apache/rocketmq/store/MultiPathMappedFileQueueTest.java b/store/src/test/java/org/apache/rocketmq/store/MultiPathMappedFileQueueTest.java index 991757dc8d5..3b22386789f 100644 --- a/store/src/test/java/org/apache/rocketmq/store/MultiPathMappedFileQueueTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/MultiPathMappedFileQueueTest.java @@ -19,7 +19,9 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.io.File; import java.io.IOException; +import java.util.Arrays; import java.util.HashSet; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -191,7 +193,9 @@ public void testUniqueNextNextMappedFile() throws IOException { MappedFile mappedFile1 = mappedFileQueue.tryCreateMappedFile(1024); assertThat(mappedFile1).isNotNull(); - assertThat(mappedFile1.getFile().getPath()).isEqualTo("target/unit_test_store/b/00000000000000001024"); + assertThat(mappedFile1.getFile().getPath()).isEqualTo( + String.join(File.separator, Arrays.asList("target", "unit_test_store", "b", "00000000000000001024")) + ); mappedFileQueue.shutdown(1000); mappedFileQueue.destroy();