sashapolo commented on code in PR #6308:
URL: https://github.com/apache/ignite-3/pull/6308#discussion_r2227756569


##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/server/impl/GroupStoragesContextResolver.java:
##########
@@ -53,4 +55,12 @@ StoragesDestructionContext 
getContext(StorageDestructionIntent intent) {
     StorageDestructionIntent getIntent(RaftNodeId nodeId, boolean isVolatile) {
         return new StorageDestructionIntent(nodeId.nodeIdStringForStorage(), 
groupNameResolver.apply(nodeId.groupId()), isVolatile);
     }
+
+    Collection<Path> serverDataPaths() {
+        return new ArrayList<>(serverDataPathByGroupName.values());

Review Comment:
   Can we use `List.copyOf` instead? (minor thing, I know)



##########
modules/raft-api/src/main/java/org/apache/ignite/internal/raft/RawRaftNodeId.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.raft;
+
+import java.util.Objects;
+
+/**
+ * Raw Raft node ID.

Review Comment:
   What does "raw" mean?



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/server/impl/JraftServerImpl.java:
##########
@@ -621,12 +625,46 @@ private void destroyStorages(StoragesDestructionContext 
context) {
             // This destroys both meta storage and snapshots storage as they 
are stored under nodeDataPath.
             IgniteUtils.deleteIfExistsThrowable(dataPath);
         } catch (Exception e) {
-            throw new IgniteInternalException("Failed to delete storage for 
node: " + nodeId, e);
+            throw new IgniteInternalException(INTERNAL_ERR, "Failed to delete 
storage for node: " + nodeId, e);
         }
 
         groupStoragesDestructionIntents.removeStorageDestructionIntent(nodeId);
     }
 
+    /**
+     * Returns Raft node IDs for all groups that are present on disk.
+     *
+     * <p>This method should only be called when no Raft nodes are started or 
being started.
+     */
+    public Set<RawRaftNodeId> raftNodeIdsOnDisk() {
+        Set<String> groupIdsForStorage = new HashSet<>();
+
+        for (LogStorageFactory logStorageFactory : 
groupStoragesContextResolver.logStorageFactories()) {
+            
groupIdsForStorage.addAll(logStorageFactory.raftNodeStorageIdsOnDisk());
+        }
+        groupIdsForStorage.addAll(raftNodeMetaStorageIdsOnDisk());
+
+        return groupIdsForStorage.stream()
+                .map(RaftNodeId::fromNodeIdStringForStorage)
+                .collect(toUnmodifiableSet());
+    }
+
+    private Set<String> raftNodeMetaStorageIdsOnDisk() {
+        return groupStoragesContextResolver.serverDataPaths().stream()
+                .flatMap(JraftServerImpl::listUncheckingly)
+                .filter(Files::isDirectory)
+                .map(groupDirPath -> groupDirPath.getFileName().toString())
+                .collect(toUnmodifiableSet());
+    }
+
+    private static Stream<Path> listUncheckingly(Path dir) {

Review Comment:
   "Uncheckingly"?



##########
modules/raft/src/main/java/org/apache/ignite/internal/raft/server/impl/JraftServerImpl.java:
##########
@@ -621,12 +625,46 @@ private void destroyStorages(StoragesDestructionContext 
context) {
             // This destroys both meta storage and snapshots storage as they 
are stored under nodeDataPath.
             IgniteUtils.deleteIfExistsThrowable(dataPath);
         } catch (Exception e) {
-            throw new IgniteInternalException("Failed to delete storage for 
node: " + nodeId, e);
+            throw new IgniteInternalException(INTERNAL_ERR, "Failed to delete 
storage for node: " + nodeId, e);
         }
 
         groupStoragesDestructionIntents.removeStorageDestructionIntent(nodeId);
     }
 
+    /**
+     * Returns Raft node IDs for all groups that are present on disk.
+     *
+     * <p>This method should only be called when no Raft nodes are started or 
being started.
+     */
+    public Set<RawRaftNodeId> raftNodeIdsOnDisk() {
+        Set<String> groupIdsForStorage = new HashSet<>();
+
+        for (LogStorageFactory logStorageFactory : 
groupStoragesContextResolver.logStorageFactories()) {
+            
groupIdsForStorage.addAll(logStorageFactory.raftNodeStorageIdsOnDisk());
+        }
+        groupIdsForStorage.addAll(raftNodeMetaStorageIdsOnDisk());
+
+        return groupIdsForStorage.stream()
+                .map(RaftNodeId::fromNodeIdStringForStorage)
+                .collect(toUnmodifiableSet());
+    }
+
+    private Set<String> raftNodeMetaStorageIdsOnDisk() {
+        return groupStoragesContextResolver.serverDataPaths().stream()
+                .flatMap(JraftServerImpl::listUncheckingly)
+                .filter(Files::isDirectory)
+                .map(groupDirPath -> groupDirPath.getFileName().toString())
+                .collect(toUnmodifiableSet());
+    }
+
+    private static Stream<Path> listUncheckingly(Path dir) {
+        try {
+            return Files.list(dir);

Review Comment:
   This stream must be explicitly closed



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to