You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "aryangupta1998 (via GitHub)" <gi...@apache.org> on 2025/01/08 12:14:18 UTC

[PR] HDDS-11714. resetDeletedBlockRetryCount with --all may fail and can cause long db lock in large cluster [ozone]

aryangupta1998 opened a new pull request, #7665:
URL: https://github.com/apache/ozone/pull/7665

   ## What changes were proposed in this pull request?
   
   In case of resetDeletedBlockRetryCount with --all option, scm takes [lock](https://github.com/apache/ozone/blob/12419fae1f0418793d952227364b04f1d2c3583b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogImpl.java#L126) and tries to get all the transaction with max retry and then updates DB with 0 count. In some large scale env this count can be huge which can lead to multiple problem.
   
   i) Lock can lead to block all other normal operation.
   
   ii) Since message is passed through ratis, which will fail because of size.
   
   Instead of doing like above we should do this operation in batches to avoid long lock and ratis message size failure.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-11714
   
   ## How was this patch tested?
   
   Tested Manually.
   


-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11714. resetDeletedBlockRetryCount with --all may fail and can cause long db lock in large cluster [ozone]

Posted by "aryangupta1998 (via GitHub)" <gi...@apache.org>.
aryangupta1998 commented on PR #7665:
URL: https://github.com/apache/ozone/pull/7665#issuecomment-2632943904

   Thanks @nandakumar131, fixed the test case!


-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11714. resetDeletedBlockRetryCount with --all may fail and can cause long db lock in large cluster [ozone]

Posted by "aryangupta1998 (via GitHub)" <gi...@apache.org>.
aryangupta1998 commented on code in PR #7665:
URL: https://github.com/apache/ozone/pull/7665#discussion_r1911496529


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogImpl.java:
##########
@@ -121,6 +120,33 @@ public DeletedBlockLogImpl(ConfigurationSource conf,
             containerManager, this.scmContext, metrics, scmCommandTimeoutMs);
   }
 
+  @Override
+  public List<DeletedBlocksTransaction> getFailedTransactionsBatch(
+      int batchSize, long startTxId) throws IOException {
+    List<DeletedBlocksTransaction> failedTXs = new ArrayList<>();
+
+    lock.lock();
+    try {
+      try (
+          TableIterator<Long, ? extends Table.KeyValue<Long, DeletedBlocksTransaction>> iter =
+              deletedBlockLogStateManager.getReadOnlyIterator()) {
+
+        iter.seek(startTxId);
+
+        while (iter.hasNext() && failedTXs.size() < batchSize) {
+          DeletedBlocksTransaction delTX = iter.next().getValue();
+          if (delTX.getCount() == -1) {
+            failedTXs.add(delTX);
+          }
+        }
+      }
+    } finally {
+      lock.unlock();
+    }
+
+    return failedTXs;
+  }
+

Review Comment:
   Done



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogImpl.java:
##########
@@ -176,19 +202,72 @@ public void incrementCount(List<Long> txIDs)
    */
   @Override
   public int resetCount(List<Long> txIDs) throws IOException {
-    lock.lock();
+    final int batchSize = 100;
+    int totalProcessed = 0;
+    long startTxId = 0;
+
     try {
+      // If txIDs are not provided, fetch all failed transactions in batches
       if (txIDs == null || txIDs.isEmpty()) {
-        txIDs = getFailedTransactions(LIST_ALL_FAILED_TRANSACTIONS, 0).stream()
-            .map(DeletedBlocksTransaction::getTxID)
-            .collect(Collectors.toList());
+        List<DeletedBlocksTransaction> batch;
+        do {
+          // Fetch the batch of failed transactions
+          batch = getFailedTransactionsBatch(batchSize, startTxId);
+
+          // If the batch is empty, skip further processing
+          if (!batch.isEmpty()) {
+            List<Long> batchTxIDs = batch.stream()
+                .map(DeletedBlocksTransaction::getTxID)
+                .collect(Collectors.toList());
+
+            lock.lock();
+            try {
+              transactionStatusManager.resetRetryCount(batchTxIDs);
+              int batchProcessed = deletedBlockLogStateManager.resetRetryCountOfTransactionInDB(
+                  new ArrayList<>(batchTxIDs));
+
+              totalProcessed += batchProcessed;
+            } finally {
+              lock.unlock();
+            }
+
+            // Update startTxId to continue from the last processed transaction in the next iteration
+            startTxId = batch.get(batch.size() - 1).getTxID() + 1;
+          }
+
+        } while (!batch.isEmpty());
+      } else {
+        // Process txIDs provided by the user in batches

Review Comment:
   Done



-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11714. resetDeletedBlockRetryCount with --all may fail and can cause long db lock in large cluster [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on code in PR #7665:
URL: https://github.com/apache/ozone/pull/7665#discussion_r1926824601


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogImpl.java:
##########
@@ -129,7 +129,7 @@ public List<DeletedBlocksTransaction> getFailedTransactions(int count,
       final List<DeletedBlocksTransaction> failedTXs = Lists.newArrayList();
       try (TableIterator<Long,
           ? extends Table.KeyValue<Long, DeletedBlocksTransaction>> iter =
-               deletedBlockLogStateManager.getReadOnlyIterator()) {
+          deletedBlockLogStateManager.getReadOnlyIterator()) {

Review Comment:
   Please avoid unnecessary formatting.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java:
##########
@@ -912,10 +912,8 @@ public List<DeletedBlocksTransactionInfo> getFailedDeletedBlockTxn(int count,
           SCMAction.GET_FAILED_DELETED_BLOCKS_TRANSACTION, auditMap));
       return result;
     } catch (IOException ex) {
-      AUDIT.logReadFailure(
-          buildAuditMessageForFailure(
-              SCMAction.GET_FAILED_DELETED_BLOCKS_TRANSACTION, auditMap, ex)
-      );

Review Comment:
   Please avoid unnecessary formatting.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogImpl.java:
##########
@@ -176,18 +176,52 @@ public void incrementCount(List<Long> txIDs)
    */
   @Override
   public int resetCount(List<Long> txIDs) throws IOException {

Review Comment:
   You can simplify the whole logic
   ```java
   public int resetCount(List<Long> txIDs) throws IOException {
   
     if (txIDs != null) {
        try {
           lock.lock();
           transactionStatusManager.resetRetryCount(txIDs);
           return deletedBlockLogStateManager.resetRetryCountOfTransactionInDB(
               new ArrayList<>(txIDs));
        } finally {
           lock.unlock();
        } catch (Exception e) {
         throw new IOException("Error during transaction reset", e);
        }
     }
   
     final int batchSize = 1000;
     int totalProcessed = 0;
     long startTxId = 0;
   
     try {
         // If txIDs are not provided, fetch all failed transactions in batches
         List<DeletedBlocksTransaction> batch;
         do {
             // Fetch the batch of failed transactions
             batch = getFailedTransactions(batchSize, startTxId);
             List<Long> batchTxIDs = batch.stream().map(DeletedBlocksTransaction::getTxID).collect(Collectors.toList());
             totalProcessed += resetCount(batchTxIDs);
   
             // Update startTxId to continue from the last processed transaction in the next iteration
             startTxId = batch.get(batch.size() - 1).getTxID() + 1;
         } while (!batch.isEmpty());
      }
      retrun totalProcessed;
   }
   ```



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/TestStorageContainerManager.java:
##########
@@ -298,8 +298,8 @@ private void testBlockDeletionTransactions(MiniOzoneCluster cluster) throws Exce
     // Verify a few TX gets created in the TX log.
     assertThat(delLog.getNumOfValidTransactions()).isGreaterThan(0);
 
-    // These blocks cannot be found in the container, skip deleting them
-    // eventually these TX will success.

Review Comment:
   Please avoid unnecessary formatting.



-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11714. resetDeletedBlockRetryCount with --all may fail and can cause long db lock in large cluster [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on code in PR #7665:
URL: https://github.com/apache/ozone/pull/7665#discussion_r1910579833


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogImpl.java:
##########
@@ -121,6 +120,33 @@ public DeletedBlockLogImpl(ConfigurationSource conf,
             containerManager, this.scmContext, metrics, scmCommandTimeoutMs);
   }
 
+  @Override
+  public List<DeletedBlocksTransaction> getFailedTransactionsBatch(
+      int batchSize, long startTxId) throws IOException {
+    List<DeletedBlocksTransaction> failedTXs = new ArrayList<>();
+
+    lock.lock();
+    try {
+      try (
+          TableIterator<Long, ? extends Table.KeyValue<Long, DeletedBlocksTransaction>> iter =
+              deletedBlockLogStateManager.getReadOnlyIterator()) {
+
+        iter.seek(startTxId);
+
+        while (iter.hasNext() && failedTXs.size() < batchSize) {
+          DeletedBlocksTransaction delTX = iter.next().getValue();
+          if (delTX.getCount() == -1) {
+            failedTXs.add(delTX);
+          }
+        }
+      }
+    } finally {
+      lock.unlock();
+    }
+
+    return failedTXs;
+  }
+

Review Comment:
   Why do we need this additional method? The same thing can be achieved with the existing `getFailedTransactions` method.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogImpl.java:
##########
@@ -176,19 +202,72 @@ public void incrementCount(List<Long> txIDs)
    */
   @Override
   public int resetCount(List<Long> txIDs) throws IOException {
-    lock.lock();
+    final int batchSize = 100;
+    int totalProcessed = 0;
+    long startTxId = 0;
+
     try {
+      // If txIDs are not provided, fetch all failed transactions in batches
       if (txIDs == null || txIDs.isEmpty()) {
-        txIDs = getFailedTransactions(LIST_ALL_FAILED_TRANSACTIONS, 0).stream()
-            .map(DeletedBlocksTransaction::getTxID)
-            .collect(Collectors.toList());
+        List<DeletedBlocksTransaction> batch;
+        do {
+          // Fetch the batch of failed transactions
+          batch = getFailedTransactionsBatch(batchSize, startTxId);
+
+          // If the batch is empty, skip further processing
+          if (!batch.isEmpty()) {
+            List<Long> batchTxIDs = batch.stream()
+                .map(DeletedBlocksTransaction::getTxID)
+                .collect(Collectors.toList());
+
+            lock.lock();
+            try {
+              transactionStatusManager.resetRetryCount(batchTxIDs);
+              int batchProcessed = deletedBlockLogStateManager.resetRetryCountOfTransactionInDB(
+                  new ArrayList<>(batchTxIDs));
+
+              totalProcessed += batchProcessed;
+            } finally {
+              lock.unlock();
+            }
+
+            // Update startTxId to continue from the last processed transaction in the next iteration
+            startTxId = batch.get(batch.size() - 1).getTxID() + 1;
+          }
+
+        } while (!batch.isEmpty());
+      } else {
+        // Process txIDs provided by the user in batches

Review Comment:
   The user provided list of `txIDs` reaches SCM via RPC call, so it's ok to process this in single go.



-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11714. resetDeletedBlockRetryCount with --all may fail and can cause long db lock in large cluster [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on PR #7665:
URL: https://github.com/apache/ozone/pull/7665#issuecomment-2633017115

   Thanks @aryangupta1998 for the contribution. Thanks @sadanand48 for the review.


-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11714. resetDeletedBlockRetryCount with --all may fail and can cause long db lock in large cluster [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 merged PR #7665:
URL: https://github.com/apache/ozone/pull/7665


-- 
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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-11714. resetDeletedBlockRetryCount with --all may fail and can cause long db lock in large cluster [ozone]

Posted by "nandakumar131 (via GitHub)" <gi...@apache.org>.
nandakumar131 commented on PR #7665:
URL: https://github.com/apache/ozone/pull/7665#issuecomment-2612141351

   @aryangupta1998 the test failure seems related to this change, can you take a look at 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: issues-unsubscribe@ozone.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org