tkalkirill commented on code in PR #763:
URL: https://github.com/apache/ignite-3/pull/763#discussion_r846011201


##########
modules/storage-api/src/main/java/org/apache/ignite/internal/storage/DataStorageManager.java:
##########
@@ -17,84 +17,104 @@
 
 package org.apache.ignite.internal.storage;
 
-import static java.util.function.Function.identity;
 import static java.util.stream.Collectors.toUnmodifiableMap;
+import static 
org.apache.ignite.configuration.schemas.store.DataStorageConfigurationSchema.UNKNOWN_DATA_STORAGE;
+import static org.apache.ignite.internal.util.CollectionUtils.first;
 
 import java.nio.file.Path;
-import java.util.List;
 import java.util.Map;
 import java.util.ServiceLoader;
+import java.util.function.Consumer;
 import java.util.stream.StreamSupport;
+import org.apache.ignite.configuration.schemas.store.DataStorageChange;
 import org.apache.ignite.configuration.schemas.store.DataStorageConfiguration;
+import 
org.apache.ignite.configuration.schemas.store.DataStorageConfigurationSchema;
+import org.apache.ignite.configuration.schemas.table.TableConfigurationSchema;
+import org.apache.ignite.configuration.schemas.table.TablesConfigurationSchema;
 import org.apache.ignite.internal.configuration.ConfigurationRegistry;
 import org.apache.ignite.internal.manager.IgniteComponent;
 import org.apache.ignite.internal.storage.engine.StorageEngine;
 import org.apache.ignite.internal.storage.engine.StorageEngineFactory;
 import org.apache.ignite.internal.tostring.S;
-import org.apache.ignite.internal.util.IgniteUtils;
 import org.jetbrains.annotations.Nullable;
 
 /**
  * Data storage manager.
  */
 public class DataStorageManager implements IgniteComponent {
-    /** Mapping: {@link StorageEngine#name} -> {@link StorageEngine}. */
+    /** Mapping: {@link StorageEngineFactory#name} -> {@link StorageEngine}. */
     private final Map<String, StorageEngine> engines;
 
     /**
      * Constructor.
      *
      * @param clusterConfigRegistry Register of the (distributed) cluster 
configuration.
      * @param storagePath Storage path.
-     * @throws StorageException If there are duplicates of the data storage 
engine.
+     * @param engineFactories Storage engine factories.
+     * @throws IllegalStateException If there are duplicates of the data 
storage engine.
      */
     public DataStorageManager(
             ConfigurationRegistry clusterConfigRegistry,
-            Path storagePath
+            Path storagePath,
+            Iterable<StorageEngineFactory> engineFactories
     ) {
-        this.engines = StreamSupport.stream(engineFactories().spliterator(), 
false)
-                .map(engineFactory -> 
engineFactory.createEngine(clusterConfigRegistry, storagePath))
+        engines = StreamSupport.stream(engineFactories.spliterator(), false)
                 .collect(toUnmodifiableMap(
-                        StorageEngine::name,
-                        identity(),
-                        (storageEngine1, storageEngine2) -> {
-                            throw new StorageException(String.format(
-                                    "Duplicate key [key=%s, engines=%s]",
-                                    storageEngine1.name(),
-                                    List.of(storageEngine1, storageEngine2)
-                            ));
-                        }
+                        StorageEngineFactory::name,
+                        engineFactory -> 
engineFactory.createEngine(clusterConfigRegistry, storagePath)
                 ));
     }
 
+    /**
+     * Constructor, overloads {@link 
DataStorageManager#DataStorageManager(ConfigurationRegistry, Path, Iterable)} 
with loading factories
+     * through a {@link ServiceLoader}.
+     */
+    public DataStorageManager(
+            ConfigurationRegistry clusterConfigRegistry,
+            Path storagePath
+    ) {
+        this(clusterConfigRegistry, storagePath, 
ServiceLoader.load(StorageEngineFactory.class));
+    }
+
     /** {@inheritDoc} */
     @Override
-    public void start() {
+    public void start() throws StorageException {
         engines.values().forEach(StorageEngine::start);
     }
 
     /** {@inheritDoc} */
     @Override
-    public void stop() throws Exception {
-        IgniteUtils.closeAll(engines.values().stream().map(engine -> 
engine::stop));
+    public void stop() throws StorageException {
+        engines.values().forEach(StorageEngine::stop);

Review Comment:
   Fix it



-- 
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]

Reply via email to