From b30bd870545f7a3ea62e5f41fdbb75ed2993c78c Mon Sep 17 00:00:00 2001 From: Git_Yang <30995057+Git-Yang@users.noreply.github.com> Date: Mon, 27 Sep 2021 08:50:30 +0800 Subject: [PATCH] [ISSUE #2667] Repair 'file doesn't exist on this path' Signed-off-by: zhangyang --- .../rocketmq/store/DefaultMessageStore.java | 14 +++++++++----- .../rocketmq/store/DefaultMessageStoreTest.java | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java index f6c652e9..09e15349 100644 --- a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java +++ b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java @@ -164,6 +164,8 @@ public class DefaultMessageStore implements MessageStore { File file = new File(StorePathConfigHelper.getLockFile(messageStoreConfig.getStorePathRootDir())); MappedFile.ensureDirOK(file.getParent()); + MappedFile.ensureDirOK(getStorePathPhysic()); + MappedFile.ensureDirOK(getStorePathLogic()); lockFile = new RandomAccessFile(file, "rw"); } @@ -779,8 +781,8 @@ public class DefaultMessageStore implements MessageStore { return this.storeStatsService.toString(); } - private String getStorePathPhysic() { - String storePathPhysic = ""; + public String getStorePathPhysic() { + String storePathPhysic; if (DefaultMessageStore.this.getMessageStoreConfig().isEnableDLegerCommitLog()) { storePathPhysic = ((DLedgerCommitLog)DefaultMessageStore.this.getCommitLog()).getdLedgerServer().getdLedgerConfig().getDataStorePath(); } else { @@ -789,6 +791,10 @@ public class DefaultMessageStore implements MessageStore { return storePathPhysic; } + public String getStorePathLogic() { + return StorePathConfigHelper.getStorePathConsumeQueue(this.messageStoreConfig.getStorePathRootDir()); + } + @Override public HashMap getRuntimeInfo() { HashMap result = this.storeStatsService.getRuntimeInfo(); @@ -807,9 +813,7 @@ public class DefaultMessageStore implements MessageStore { } { - String storePathLogics = StorePathConfigHelper.getStorePathConsumeQueue(this.messageStoreConfig.getStorePathRootDir()); - double logicsRatio = UtilAll.isPathExists(storePathLogics) ? - UtilAll.getDiskPartitionSpaceUsedPercent(storePathLogics) : -1; + double logicsRatio = UtilAll.getDiskPartitionSpaceUsedPercent(getStorePathLogic()); result.put(RunningStats.consumeQueueDiskRatio.name(), String.valueOf(logicsRatio)); } diff --git a/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java b/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java index 440f9146..f3e619d7 100644 --- a/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java @@ -605,6 +605,22 @@ public class DefaultMessageStoreTest { } } + @Test + public void testStorePathOK() { + if (messageStore instanceof DefaultMessageStore) { + assertTrue(fileExists(((DefaultMessageStore) messageStore).getStorePathPhysic())); + assertTrue(fileExists(((DefaultMessageStore) messageStore).getStorePathLogic())); + } + } + + private boolean fileExists(String path) { + if (path != null) { + File f = new File(path); + return f.exists(); + } + return false; + } + private void damageCommitlog(long offset) throws Exception { MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); File file = new File(messageStoreConfig.getStorePathCommitLog() + File.separator + "00000000000000000000"); -- GitLab