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



##########
File path: 
modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/RocksDbStorageEngine.java
##########
@@ -36,45 +42,94 @@
  * Storage engine implementation based on RocksDB.
  */
 public class RocksDbStorageEngine implements StorageEngine {
+    /** Engine name. */
+    public static final String ENGINE_NAME = "rocksdb";
+
     static {
         RocksDB.loadLibrary();
     }
 
+    private final RocksDbStorageEngineConfiguration engineConfig;
+
+    private final Path storagePath;
+
+    private final ExecutorService threadPool = Executors.newFixedThreadPool(
+            Runtime.getRuntime().availableProcessors(),
+            new NamedThreadFactory("rocksdb-storage-engine-pool")
+    );
+
+    private final Map<String, RocksDbDataRegion> regions = new 
ConcurrentHashMap<>();
+
     /**
-     * Thread pool to be used to snapshot partitions and maybe some other 
operations.
+     * Constructor.
+     *
+     * @param engineConfig RocksDB storage engine configuration.
+     * @param storagePath Storage path.
      */
-    private final ExecutorService threadPool = Executors.newFixedThreadPool(
-            Runtime.getRuntime().availableProcessors(), new 
NamedThreadFactory("rocksdb-storage-engine-pool"));
+    public RocksDbStorageEngine(RocksDbStorageEngineConfiguration 
engineConfig, Path storagePath) {
+        this.engineConfig = engineConfig;
+        this.storagePath = storagePath;
+    }
 
     /** {@inheritDoc} */
     @Override
-    public void start() {
+    public String name() {
+        return ENGINE_NAME;
     }
 
     /** {@inheritDoc} */
     @Override
-    public void stop() throws StorageException {
-        IgniteUtils.shutdownAndAwaitTermination(threadPool, 10, 
TimeUnit.SECONDS);
+    public void start() throws StorageException {
+        RocksDbDataRegion defaultRegion = new 
RocksDbDataRegion(engineConfig.defaultRegion());
+
+        defaultRegion.start();
+
+        regions.put(DEFAULT_DATA_REGION_NAME, defaultRegion);
+
+        for (String regionName : 
engineConfig.regions().value().namedListKeys()) {
+            RocksDbDataRegion region = new 
RocksDbDataRegion(engineConfig.regions().get(regionName));
+
+            region.start();
+
+            regions.put(regionName, region);
+        }
     }
 
     /** {@inheritDoc} */
     @Override
-    public DataRegion createDataRegion(DataRegionConfiguration regionCfg) {
-        assert regionCfg instanceof RocksDbDataRegionConfiguration : regionCfg;
+    public void stop() throws StorageException {
+        IgniteUtils.shutdownAndAwaitTermination(threadPool, 10, 
TimeUnit.SECONDS);
 
-        return new RocksDbDataRegion((RocksDbDataRegionConfiguration) 
regionCfg);
+        try {
+            IgniteUtils.closeAll(regions.values().stream().map(region -> 
region::stop));
+        } catch (Exception e) {
+            throw new StorageException("Error when stopping regions", e);
+        }
     }
 
     /** {@inheritDoc} */
     @Override
-    public TableStorage createTable(Path tablePath, TableConfiguration 
tableCfg, DataRegion dataRegion) {
-        assert dataRegion instanceof RocksDbDataRegion : dataRegion;
-
-        return new RocksDbTableStorage(
-                tablePath,
-                tableCfg,
-                threadPool,
-                (RocksDbDataRegion) dataRegion
-        );
+    public TableStorage createTable(TableConfiguration tableCfg) throws 
StorageException {
+        TableView tableView = tableCfg.value();
+
+        assert tableView.dataStorage().name().equals(ENGINE_NAME) : 
tableView.dataStorage().name();
+
+        RocksDbDataStorageView dataStorageView = (RocksDbDataStorageView) 
tableView.dataStorage();
+
+        RocksDbDataRegion dataRegion = 
regions.get(dataStorageView.dataRegion());
+
+        if (dataRegion == null) {

Review comment:
       Replaced with assertion




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