tkalkirill commented on a change in pull request #754:
URL: https://github.com/apache/ignite-3/pull/754#discussion_r840665017



##########
File path: 
modules/storage-api/src/main/java/org/apache/ignite/internal/storage/DataStorageManager.java
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.storage;
+
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.configuration.schemas.store.DataStorageConfiguration;
+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 {
+    private final ConfigurationRegistry clusterConfigRegistry;
+
+    private final Path storagePath;
+
+    /** Mapping: {@link StorageEngine#name} -> {@link StorageEngine}. */
+    private final Map<String, StorageEngine> engines = new 
ConcurrentHashMap<>();
+
+    /**
+     * Constructor.
+     *
+     * @param clusterConfigRegistry Register of the (distributed) cluster 
configuration.
+     * @param storagePath Storage path.
+     */
+    public DataStorageManager(
+            ConfigurationRegistry clusterConfigRegistry,
+            Path storagePath
+    ) {
+        this.clusterConfigRegistry = clusterConfigRegistry;
+        this.storagePath = storagePath;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void start() {
+        for (StorageEngineFactory engineFactory : engineFactories()) {
+            StorageEngine engine = 
engineFactory.createEngine(clusterConfigRegistry, storagePath);
+
+            engine.start();
+
+            String name = engine.name();
+
+            if (engines.containsKey(name)) {
+                throw new StorageException(
+                        "There is already a storage engine with the same name: 
[name=" + name + ", engine=" + engines.get(name) + "]"
+                );
+            } else {
+                engines.put(name, engine);
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void stop() throws Exception {
+        IgniteUtils.closeAll(engines.values().stream().map(engine -> 
engine::stop));
+    }
+
+    /**
+     * Returns the storage engine factories.
+     *
+     * <p>NOTE: It is recommended to override only in tests.
+     */
+    protected Iterable<StorageEngineFactory> engineFactories() {
+        return ServiceLoader.load(StorageEngineFactory.class);
+    }
+
+    /**
+     * Returns the data storage engine by name.
+     *
+     * @param name Engine name.
+     */
+    public @Nullable StorageEngine engine(String name) {

Review comment:
       I'll take it away.




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