You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by ru...@apache.org on 2021/03/01 06:46:33 UTC

[ozone] branch HDDS-2823 updated: HDDS-4761. Implement increment count optimization in DeletedBlockLog V2 (#1914)

This is an automated email from the ASF dual-hosted git repository.

runzhiwang pushed a commit to branch HDDS-2823
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/HDDS-2823 by this push:
     new 762fb00  HDDS-4761. Implement increment count optimization in DeletedBlockLog V2 (#1914)
762fb00 is described below

commit 762fb000639186defc85ea0ae9218b8aae633a67
Author: Rui Wang <am...@163.com>
AuthorDate: Sun Feb 28 22:46:14 2021 -0800

    HDDS-4761. Implement increment count optimization in DeletedBlockLog V2 (#1914)
---
 .../hdds/scm/block/DeletedBlockLogImplV2.java      | 28 +++++++++++++--
 .../scm/block/DeletedBlockLogStateManagerImpl.java | 19 +++++-----
 .../apache/hadoop/hdds/scm/ha/SCMStateMachine.java |  2 +-
 .../hadoop/hdds/scm/block/TestDeletedBlockLog.java | 41 ----------------------
 4 files changed, 34 insertions(+), 56 deletions(-)

diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogImplV2.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogImplV2.java
index 86e32d3..fee81e7 100644
--- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogImplV2.java
+++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogImplV2.java
@@ -79,6 +79,8 @@ public class DeletedBlockLogImplV2
   private final Lock lock;
   // Maps txId to set of DNs which are successful in committing the transaction
   private Map<Long, Set<UUID>> transactionToDNsCommitMap;
+  // Maps txId to its retry counts;
+  private Map<Long, Integer> transactionToRetryCountMap;
   // The access to DeletedBlocksTXTable is protected by
   // DeletedBlockLogStateManager.
   private final DeletedBlockLogStateManager deletedBlockLogStateManager;
@@ -101,6 +103,7 @@ public class DeletedBlockLogImplV2
 
     // maps transaction to dns which have committed it.
     transactionToDNsCommitMap = new ConcurrentHashMap<>();
+    transactionToRetryCountMap = new ConcurrentHashMap<>();
     this.deletedBlockLogStateManager = DeletedBlockLogStateManagerImpl
         .newBuilder()
         .setConfiguration(conf)
@@ -145,8 +148,25 @@ public class DeletedBlockLogImplV2
   public void incrementCount(List<Long> txIDs) throws IOException {
     lock.lock();
     try {
-      deletedBlockLogStateManager
-          .increaseRetryCountOfTransactionInDB(new ArrayList<>(txIDs));
+      ArrayList<Long> txIDsToUpdate = new ArrayList<>();
+      for (Long txID : txIDs) {
+        int currentCount =
+            transactionToRetryCountMap.getOrDefault(txID, 0);
+        if (currentCount > maxRetry) {
+          continue;
+        } else {
+          currentCount += 1;
+          if (currentCount > maxRetry) {
+            txIDsToUpdate.add(txID);
+          }
+          transactionToRetryCountMap.put(txID, currentCount);
+        }
+      }
+
+      if (!txIDsToUpdate.isEmpty()) {
+        deletedBlockLogStateManager
+            .increaseRetryCountOfTransactionInDB(txIDsToUpdate);
+      }
     } finally {
       lock.unlock();
     }
@@ -216,6 +236,7 @@ public class DeletedBlockLogImplV2
                 .collect(Collectors.toList());
             if (dnsWithCommittedTxn.containsAll(containerDns)) {
               transactionToDNsCommitMap.remove(txID);
+              transactionToRetryCountMap.remove(txID);
               if (LOG.isDebugEnabled()) {
                 LOG.debug("Purging txId={} from block deletion log", txID);
               }
@@ -281,8 +302,9 @@ public class DeletedBlockLogImplV2
    * Called in SCMStateMachine#notifyLeaderChanged when current SCM becomes
    *  leader.
    */
-  public void clearTransactionToDNsCommitMap() {
+  public void onBecomeLeader() {
     transactionToDNsCommitMap.clear();
+    transactionToRetryCountMap.clear();
   }
 
   /**
diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogStateManagerImpl.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogStateManagerImpl.java
index f02d016..28a7098 100644
--- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogStateManagerImpl.java
+++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/block/DeletedBlockLogStateManagerImpl.java
@@ -49,7 +49,8 @@ public class DeletedBlockLogStateManagerImpl
   private final Table<Long, DeletedBlocksTransaction> deletedTable;
   private final DBTransactionBuffer transactionBuffer;
   private final int maxRetry;
-  private Set<Long> deletingTxIDs;
+  private final Set<Long> deletingTxIDs;
+  private final Set<Long> skippingRetryTxIDs;
 
   public DeletedBlockLogStateManagerImpl(
       ConfigurationSource conf,
@@ -60,6 +61,7 @@ public class DeletedBlockLogStateManagerImpl
     this.deletedTable = deletedTable;
     this.transactionBuffer = txBuffer;
     this.deletingTxIDs = ConcurrentHashMap.newKeySet();
+    this.skippingRetryTxIDs = ConcurrentHashMap.newKeySet();
   }
 
   public TableIterator<Long, TypedTable.KeyValue<Long,
@@ -87,7 +89,8 @@ public class DeletedBlockLogStateManagerImpl
             throw new IllegalStateException("");
           }
 
-          if (!deletingTxIDs.contains(txID)) {
+          if (!deletingTxIDs.contains(txID) &&
+              !skippingRetryTxIDs.contains(txID)) {
             nextTx = next;
             if (LOG.isTraceEnabled()) {
               LOG.trace("DeletedBlocksTransaction matching txID:{}",
@@ -187,26 +190,20 @@ public class DeletedBlockLogStateManagerImpl
         }
         continue;
       }
-      DeletedBlocksTransaction.Builder builder = block.toBuilder();
-      int currentCount = block.getCount();
-      if (currentCount > -1) {
-        builder.setCount(++currentCount);
-      }
       // if the retry time exceeds the maxRetry value
       // then set the retry value to -1, stop retrying, admins can
       // analyze those blocks and purge them manually by SCMCli.
-      if (currentCount > maxRetry) {
-        builder.setCount(-1);
-      }
+      DeletedBlocksTransaction.Builder builder = block.toBuilder().setCount(-1);
       deletedTable.putWithBatch(
           transactionBuffer.getCurrentBatchOperation(), txID, builder.build());
+      skippingRetryTxIDs.add(txID);
     }
   }
 
 
   public void onFlush() {
     deletingTxIDs.clear();
-    LOG.info("Clear cached deletingTxIDs.");
+    skippingRetryTxIDs.clear();
   }
 
   public static Builder newBuilder() {
diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMStateMachine.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMStateMachine.java
index 921a17e..c856ae3 100644
--- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMStateMachine.java
+++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMStateMachine.java
@@ -186,7 +186,7 @@ public class SCMStateMachine extends BaseStateMachine {
     Preconditions.checkArgument(
         deletedBlockLog instanceof DeletedBlockLogImplV2);
     ((DeletedBlockLogImplV2) deletedBlockLog)
-          .clearTransactionToDNsCommitMap();
+          .onBecomeLeader();
   }
 
   @Override
diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/block/TestDeletedBlockLog.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/block/TestDeletedBlockLog.java
index 4650165..0fbdbf4 100644
--- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/block/TestDeletedBlockLog.java
+++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/block/TestDeletedBlockLog.java
@@ -259,47 +259,6 @@ public class TestDeletedBlockLog {
   }
 
   @Test
-  public void testIncrementCountLessFrequentWritingToDB() throws Exception {
-    OzoneConfiguration testConf = OzoneConfiguration.of(conf);
-    testConf.setInt(OZONE_SCM_BLOCK_DELETION_MAX_RETRY, 120);
-
-    deletedBlockLog.addTransactions(generateData(1));
-
-    List<DeletedBlocksTransaction> blocks =
-        getTransactions(40 * BLOCKS_PER_TXN);
-    List<Long> txIDs = blocks.stream().map(DeletedBlocksTransaction::getTxID)
-        .collect(Collectors.toList());
-
-    for (int i = 0; i < 50; i++) {
-      deletedBlockLog.incrementCount(txIDs);
-    }
-    blocks = getTransactions(40 * BLOCKS_PER_TXN);
-    for (DeletedBlocksTransaction block : blocks) {
-      // block count should not be updated as there are only 50 retries.
-      Assert.assertEquals(0, block.getCount());
-    }
-
-    for (int i = 0; i < 60; i++) {
-      deletedBlockLog.incrementCount(txIDs);
-    }
-    blocks = getTransactions(40 * BLOCKS_PER_TXN);
-    for (DeletedBlocksTransaction block : blocks) {
-      // block count should be updated to 100 as there are already 110 retries.
-      Assert.assertEquals(100, block.getCount());
-    }
-
-    for (int i = 0; i < 50; i++) {
-      deletedBlockLog.incrementCount(txIDs);
-    }
-    blocks = getTransactions(40 * BLOCKS_PER_TXN);
-    for (DeletedBlocksTransaction block : blocks) {
-      // block count should be updated to -1 as retry count exceeds maxRetry
-      // (i.e. 160 > maxRetry which is 120).
-      Assert.assertEquals(-1, block.getCount());
-    }
-  }
-
-  @Test
   public void testCommitTransactions() throws Exception {
     addTransactions(generateData(50));
     List<DeletedBlocksTransaction> blocks =


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