yandrey321 commented on code in PR #9947:
URL: https://github.com/apache/ozone/pull/9947#discussion_r3119297363


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/HddsVolume.java:
##########
@@ -306,20 +307,34 @@ public synchronized VolumeCheckResult check(@Nullable 
Boolean unused)
 
   @VisibleForTesting
   public VolumeCheckResult checkDbHealth(File dbFile) throws 
InterruptedException {
-    if (!getDiskCheckEnabled()) {
+    if (!(getDiskCheckEnabled() && 
getDatanodeConfig().isRocksDbDiskCheckEnabled())) {
       return VolumeCheckResult.HEALTHY;
     }
 
-    try (ManagedOptions managedOptions = new ManagedOptions();
-         ManagedRocksDB ignored = ManagedRocksDB.openReadOnly(managedOptions, 
dbFile.toString())) {
-      // Do nothing. Only check if rocksdb is accessible.
-      LOG.debug("Successfully opened the database at \"{}\" for HDDS volume 
{}.", dbFile, getStorageDir());
-    } catch (Exception e) {
-      if (Thread.currentThread().isInterrupted()) {
-        throw new InterruptedException("Check of database for volume " + this 
+ " interrupted.");
+    // We attempt to open RocksDb twice to ignore any transient errors
+    // and to confirm that we actually cannot open RocksDb in readonly mode.
+    final int maxAttempts = getDatanodeConfig().getDiskCheckRetryAttempts();
+    final Duration maxRetryGap = getDatanodeConfig().getDiskCheckRetryGap();
+    for (int attempt = 0; attempt < maxAttempts; attempt++) {
+      try (ManagedOptions managedOptions = new ManagedOptions();
+           ManagedRocksDB ignored =
+               ManagedRocksDB.openAsSecondary(managedOptions, 
dbFile.toString(), getTmpDir().getPath())) {
+        // Do nothing. Only check if rocksdb is accessible.
+        LOG.debug("Successfully opened the database at \"{}\" for HDDS volume 
{}.", dbFile, getStorageDir());
+        break;
+      } catch (Exception e) {
+        if (Thread.currentThread().isInterrupted()) {
+          throw new InterruptedException("Check of database for volume " + 
this + " interrupted.");
+        }
+
+        if (attempt == maxAttempts - 1) {
+          LOG.error("Could not open Volume DB located at {}", dbFile, e);
+          getIoTestSlidingWindow().add();
+        } else {
+          LOG.warn("Could not open Volume DB located at {}", dbFile, e);
+          Thread.sleep(maxRetryGap.toMillis());

Review Comment:
   do we want to track thread interruption for this sleep?



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to