jt2594838 commented on code in PR #18008:
URL: https://github.com/apache/iotdb/pull/18008#discussion_r3464234090
##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/JVMCommonUtils.java:
##########
@@ -111,6 +111,9 @@ public static boolean hasSpace(String dir) {
public static long getOccupiedSpace(String folderPath) throws IOException {
Path folder = Paths.get(folderPath);
+ if (!Files.exists(folder)) {
+ return 0;
+ }
try (Stream<Path> s = Files.walk(folder)) {
return s.filter(p -> p.toFile().isFile()).mapToLong(p ->
p.toFile().length()).sum();
Review Comment:
Check p.toFile.exists() in mapToLong()
filter and mapToLong are not atomic, the file status may be changed between
the two steps.
##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/disk/strategy/DirectoryStrategyType.java:
##########
@@ -22,5 +22,27 @@ public enum DirectoryStrategyType {
SEQUENCE_STRATEGY,
MAX_DISK_USABLE_SPACE_FIRST_STRATEGY,
MIN_FOLDER_OCCUPIED_SPACE_FIRST_STRATEGY,
- RANDOM_ON_DISK_USABLE_SPACE_STRATEGY,
+ RANDOM_ON_DISK_USABLE_SPACE_STRATEGY;
+
+ /**
+ * Resolves the strategy type from a multi-dir strategy class name as
configured by {@code
+ * dn_multi_dir_strategy}. Accepts either a simple class name (e.g. {@code
SequenceStrategy}) or a
+ * fully-qualified one. Returns {@link #SEQUENCE_STRATEGY} for a null or
unrecognized value, which
+ * matches the configured default.
+ */
+ public static DirectoryStrategyType fromClassName(String className) {
+ if (className != null) {
+ String simpleName = className.substring(className.lastIndexOf('.') + 1);
+ if
(simpleName.equals(MaxDiskUsableSpaceFirstStrategy.class.getSimpleName())) {
+ return MAX_DISK_USABLE_SPACE_FIRST_STRATEGY;
+ } else if
(simpleName.equals(MinFolderOccupiedSpaceFirstStrategy.class.getSimpleName())) {
+ return MIN_FOLDER_OCCUPIED_SPACE_FIRST_STRATEGY;
+ } else if
(simpleName.equals(RandomOnDiskUsableSpaceStrategy.class.getSimpleName())) {
+ return RANDOM_ON_DISK_USABLE_SPACE_STRATEGY;
+ } else if (simpleName.equals(SequenceStrategy.class.getSimpleName())) {
+ return SEQUENCE_STRATEGY;
+ }
+ }
Review Comment:
Print a warn log for unrecognized name.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]