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 f6c652e9379598499e200cf8383cbecaf3f57528..09e153494df51627910f9cf46cbc6f7fbaf99197 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 440f9146314a049a91e7096f4b382399b878f8d6..f3e619d7784595280d3a54c239b3136b7ea97199 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");