You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/04/15 09:46:36 UTC

[GitHub] [iotdb] HeimingZ commented on a diff in pull request #5558: [IOTDB-2934] Fix StorageEngineV2 cannot recover

HeimingZ commented on code in PR #5558:
URL: https://github.com/apache/iotdb/pull/5558#discussion_r851183256


##########
server/src/main/java/org/apache/iotdb/db/engine/StorageEngineV2.java:
##########
@@ -229,44 +239,54 @@ public void recover() {
     recoverEndTrigger.start();
   }
 
-  private void getLocalDataRegion() throws MetadataException, DataRegionException {
-    File system = SystemFileFactory.INSTANCE.getFile(systemDir);
-    File[] sgDirs = system.listFiles();
-    int sgCount = 0;
-    for (File sgDir : sgDirs) {
-      if (!sgDir.isDirectory()) {
-        sgCount++;
-      }
-    }
+  private void asyncRecover(ExecutorService pool, List<Future<Void>> futures) {
+
+    Map<String, List<String>> localDataRegionInfo = getLocalDataRegionInfo();
+    readyDataRegionNum = new AtomicInteger(0);
     // init wal recover manager
     WALRecoverManager.getInstance()
-        .setAllDataRegionScannedLatch(new CountDownLatch(sgCount * config.getDataRegionNum()));
+        .setAllDataRegionScannedLatch(
+            new CountDownLatch(localDataRegionInfo.size() * config.getDataRegionNum()));
+    for (Map.Entry<String, List<String>> entry : localDataRegionInfo.entrySet()) {
+      String sgName = entry.getKey();
+      for (String dataRegionId : entry.getValue()) {
+        Callable<Void> recoverDataRegionTask =
+            () -> {
+              DataRegion dataRegion = null;
+              try {
+                dataRegion = buildNewDataRegion(sgName, dataRegionId, Long.MAX_VALUE);
+              } catch (DataRegionException e) {
+                logger.error("Failed to recover data region {}[{}]", sgName, dataRegionId, e);
+              }
+              dataRegionMap.put(new DataRegionId(Integer.parseInt(dataRegionId)), dataRegion);
+              logger.info(
+                  "Data regions have been recovered {}", readyDataRegionNum.incrementAndGet());

Review Comment:
   You can log readyDataRegionNum.incrementAndGet() / localDataRegionInfo.size() here.



##########
server/src/main/java/org/apache/iotdb/db/engine/StorageEngineV2.java:
##########
@@ -229,44 +239,54 @@ public void recover() {
     recoverEndTrigger.start();
   }
 
-  private void getLocalDataRegion() throws MetadataException, DataRegionException {
-    File system = SystemFileFactory.INSTANCE.getFile(systemDir);
-    File[] sgDirs = system.listFiles();
-    int sgCount = 0;
-    for (File sgDir : sgDirs) {
-      if (!sgDir.isDirectory()) {
-        sgCount++;
-      }
-    }
+  private void asyncRecover(ExecutorService pool, List<Future<Void>> futures) {
+
+    Map<String, List<String>> localDataRegionInfo = getLocalDataRegionInfo();
+    readyDataRegionNum = new AtomicInteger(0);
     // init wal recover manager
     WALRecoverManager.getInstance()
-        .setAllDataRegionScannedLatch(new CountDownLatch(sgCount * config.getDataRegionNum()));
+        .setAllDataRegionScannedLatch(
+            new CountDownLatch(localDataRegionInfo.size() * config.getDataRegionNum()));

Review Comment:
   Only localDataRegionInfo.size() is OK



-- 
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: reviews-unsubscribe@iotdb.apache.org

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