Skip to content

Commit b30bd87

Browse files
authored
[ISSUE #2667] Repair 'file doesn't exist on this path'
Signed-off-by: zhangyang <[email protected]>
1 parent d429aa2 commit b30bd87

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ public DefaultMessageStore(final MessageStoreConfig messageStoreConfig, final Br
164164

165165
File file = new File(StorePathConfigHelper.getLockFile(messageStoreConfig.getStorePathRootDir()));
166166
MappedFile.ensureDirOK(file.getParent());
167+
MappedFile.ensureDirOK(getStorePathPhysic());
168+
MappedFile.ensureDirOK(getStorePathLogic());
167169
lockFile = new RandomAccessFile(file, "rw");
168170
}
169171

@@ -779,8 +781,8 @@ public String getRunningDataInfo() {
779781
return this.storeStatsService.toString();
780782
}
781783

782-
private String getStorePathPhysic() {
783-
String storePathPhysic = "";
784+
public String getStorePathPhysic() {
785+
String storePathPhysic;
784786
if (DefaultMessageStore.this.getMessageStoreConfig().isEnableDLegerCommitLog()) {
785787
storePathPhysic = ((DLedgerCommitLog)DefaultMessageStore.this.getCommitLog()).getdLedgerServer().getdLedgerConfig().getDataStorePath();
786788
} else {
@@ -789,6 +791,10 @@ private String getStorePathPhysic() {
789791
return storePathPhysic;
790792
}
791793

794+
public String getStorePathLogic() {
795+
return StorePathConfigHelper.getStorePathConsumeQueue(this.messageStoreConfig.getStorePathRootDir());
796+
}
797+
792798
@Override
793799
public HashMap<String, String> getRuntimeInfo() {
794800
HashMap<String, String> result = this.storeStatsService.getRuntimeInfo();
@@ -807,9 +813,7 @@ public HashMap<String, String> getRuntimeInfo() {
807813
}
808814

809815
{
810-
String storePathLogics = StorePathConfigHelper.getStorePathConsumeQueue(this.messageStoreConfig.getStorePathRootDir());
811-
double logicsRatio = UtilAll.isPathExists(storePathLogics) ?
812-
UtilAll.getDiskPartitionSpaceUsedPercent(storePathLogics) : -1;
816+
double logicsRatio = UtilAll.getDiskPartitionSpaceUsedPercent(getStorePathLogic());
813817
result.put(RunningStats.consumeQueueDiskRatio.name(), String.valueOf(logicsRatio));
814818
}
815819

store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,22 @@ public void testRecover() throws Exception {
605605
}
606606
}
607607

608+
@Test
609+
public void testStorePathOK() {
610+
if (messageStore instanceof DefaultMessageStore) {
611+
assertTrue(fileExists(((DefaultMessageStore) messageStore).getStorePathPhysic()));
612+
assertTrue(fileExists(((DefaultMessageStore) messageStore).getStorePathLogic()));
613+
}
614+
}
615+
616+
private boolean fileExists(String path) {
617+
if (path != null) {
618+
File f = new File(path);
619+
return f.exists();
620+
}
621+
return false;
622+
}
623+
608624
private void damageCommitlog(long offset) throws Exception {
609625
MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
610626
File file = new File(messageStoreConfig.getStorePathCommitLog() + File.separator + "00000000000000000000");

0 commit comments

Comments
 (0)