Skip to content

Commit 4a653a5

Browse files
committed
Use commons i18n for disk messages
1 parent d65dcc6 commit 4a653a5

5 files changed

Lines changed: 34 additions & 7 deletions

File tree

iotdb-core/node-commons/src/main/i18n/en/org/apache/iotdb/commons/i18n/UtilMessages.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ public final class UtilMessages {
107107
public static final String UNEXPECTED_ERROR_CHECKING_DISK_SPACE =
108108
"Unexpected error checking disk space for {}";
109109

110+
// ======================== FolderManager ========================
111+
112+
public static final String ALL_FOLDERS_FULL_CHANGE_TO_READ_ONLY =
113+
"All folders are full, change system mode to read-only.";
114+
public static final String FAILED_TO_PROCESS_FOLDER = "Failed to process folder {}";
115+
public static final String FAILED_TO_READ_FILE_STORE_PATH =
116+
"Failed to read file store path '{}'";
117+
public static final String DISK_SPACE_INSUFFICIENT_READ_ONLY =
118+
"Disk space is insufficient, change system mode to read-only.";
119+
public static final String CANNOT_CALCULATE_OCCUPIED_SPACE =
120+
"Cannot calculate occupied space of folder {}";
121+
110122
// ======================== NodeUrlUtils ========================
111123

112124
public static final String BAD_CONFIG_NODE_URL = "Bad ConfigNode url: {}";

iotdb-core/node-commons/src/main/i18n/zh/org/apache/iotdb/commons/i18n/UtilMessages.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ public final class UtilMessages {
105105
public static final String UNEXPECTED_ERROR_CHECKING_DISK_SPACE =
106106
"检查 {} 的磁盘空间时发生意外错误";
107107

108+
// ======================== FolderManager ========================
109+
110+
public static final String ALL_FOLDERS_FULL_CHANGE_TO_READ_ONLY =
111+
"所有文件夹空间均已耗尽,系统切换为只读模式。";
112+
public static final String FAILED_TO_PROCESS_FOLDER = "处理文件夹 {} 失败";
113+
public static final String FAILED_TO_READ_FILE_STORE_PATH =
114+
"读取文件存储路径 '{}' 失败";
115+
public static final String DISK_SPACE_INSUFFICIENT_READ_ONLY =
116+
"磁盘空间不足,系统切换为只读模式。";
117+
public static final String CANNOT_CALCULATE_OCCUPIED_SPACE =
118+
"无法计算文件夹 {} 的已占用空间";
119+
108120
// ======================== NodeUrlUtils ========================
109121

110122
public static final String BAD_CONFIG_NODE_URL = "ConfigNode URL 格式错误:{}";

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/disk/FolderManager.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.iotdb.commons.disk.strategy.RandomOnDiskUsableSpaceStrategy;
2929
import org.apache.iotdb.commons.disk.strategy.SequenceStrategy;
3030
import org.apache.iotdb.commons.exception.DiskSpaceInsufficientException;
31+
import org.apache.iotdb.commons.i18n.UtilMessages;
3132

3233
import org.slf4j.Logger;
3334
import org.slf4j.LoggerFactory;
@@ -86,7 +87,7 @@ public FolderManager(List<String> folders, DirectoryStrategyType type)
8687
this.selectStrategy.setFolders(folders);
8788
this.selectStrategy.setFoldersStates(foldersStates);
8889
} catch (DiskSpaceInsufficientException e) {
89-
logger.error("All folders are full, change system mode to read-only.", e);
90+
logger.error(UtilMessages.ALL_FOLDERS_FULL_CHANGE_TO_READ_ONLY, e);
9091
CommonDescriptor.getInstance().getConfig().setNodeStatus(NodeStatus.ReadOnly);
9192
CommonDescriptor.getInstance().getConfig().setStatusReason(NodeStatus.DISK_FULL);
9293
throw e;
@@ -102,7 +103,7 @@ public String getNextFolder() throws DiskSpaceInsufficientException {
102103
try {
103104
return folders.get(selectStrategy.nextFolderIndex());
104105
} catch (DiskSpaceInsufficientException e) {
105-
logger.error("All folders are full, change system mode to read-only.", e);
106+
logger.error(UtilMessages.ALL_FOLDERS_FULL_CHANGE_TO_READ_ONLY, e);
106107
CommonDescriptor.getInstance().getConfig().setNodeStatus(NodeStatus.ReadOnly);
107108
CommonDescriptor.getInstance().getConfig().setStatusReason(NodeStatus.DISK_FULL);
108109
throw e;
@@ -133,7 +134,7 @@ public <T, E extends Exception> T getNextWithRetry(ThrowingFunction<String, T, E
133134
try {
134135
folder = folders.get(selectStrategy.nextFolderIndex());
135136
} catch (DiskSpaceInsufficientException e) {
136-
logger.error("All folders are full, change system mode to read-only.", e);
137+
logger.error(UtilMessages.ALL_FOLDERS_FULL_CHANGE_TO_READ_ONLY, e);
137138
CommonDescriptor.getInstance().getConfig().setNodeStatus(NodeStatus.ReadOnly);
138139
CommonDescriptor.getInstance().getConfig().setStatusReason(NodeStatus.DISK_FULL);
139140
throw e;
@@ -142,7 +143,7 @@ public <T, E extends Exception> T getNextWithRetry(ThrowingFunction<String, T, E
142143
return folderConsumer.apply(folder);
143144
} catch (Exception e) {
144145
updateFolderState(folder, FolderState.ABNORMAL);
145-
logger.warn("Failed to process folder {}", folder);
146+
logger.warn(UtilMessages.FAILED_TO_PROCESS_FOLDER, folder);
146147
}
147148
}
148149
throw new DiskSpaceInsufficientException(folders);
@@ -164,7 +165,7 @@ public String getFirstFolderOfSameDisk(String pathStr) {
164165
}
165166
}
166167
} catch (IOException e) {
167-
logger.warn("Failed to read file store path '" + pathStr + "'", e);
168+
logger.warn(UtilMessages.FAILED_TO_READ_FILE_STORE_PATH, pathStr, e);
168169
}
169170
return null;
170171
}

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/disk/strategy/DirectoryStrategy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.iotdb.commons.conf.CommonDescriptor;
2323
import org.apache.iotdb.commons.disk.FolderManager;
2424
import org.apache.iotdb.commons.exception.DiskSpaceInsufficientException;
25+
import org.apache.iotdb.commons.i18n.UtilMessages;
2526
import org.apache.iotdb.commons.utils.JVMCommonUtils;
2627

2728
import org.slf4j.Logger;
@@ -60,7 +61,7 @@ public void setFolders(List<String> folders) throws DiskSpaceInsufficientExcepti
6061
}
6162
}
6263
if (!hasSpace) {
63-
LOGGER.error("Disk space is insufficient, change system mode to read-only.");
64+
LOGGER.error(UtilMessages.DISK_SPACE_INSUFFICIENT_READ_ONLY);
6465
CommonDescriptor.getInstance().getConfig().setNodeStatus(NodeStatus.ReadOnly);
6566
throw new DiskSpaceInsufficientException(folders);
6667
}

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/disk/strategy/MinFolderOccupiedSpaceFirstStrategy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.iotdb.commons.disk.strategy;
2020

2121
import org.apache.iotdb.commons.exception.DiskSpaceInsufficientException;
22+
import org.apache.iotdb.commons.i18n.UtilMessages;
2223
import org.apache.iotdb.commons.utils.JVMCommonUtils;
2324

2425
import java.io.IOException;
@@ -47,7 +48,7 @@ private int getMinOccupiedSpaceFolder() throws DiskSpaceInsufficientException {
4748
try {
4849
space = JVMCommonUtils.getOccupiedSpace(folder);
4950
} catch (IOException e) {
50-
LOGGER.error("Cannot calculate occupied space of folder {}", folder, e);
51+
LOGGER.error(UtilMessages.CANNOT_CALCULATE_OCCUPIED_SPACE, folder, e);
5152
continue;
5253
}
5354
if (space < minSpace) {

0 commit comments

Comments
 (0)