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

prashantpogde pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 085a7f6531 HDDS-9004. [Snapshot] Pause the compaction log append if 
tarball creation is in progress (#5070)
085a7f6531 is described below

commit 085a7f65317fcf7248d4c2f40d7884e898f62914
Author: Hemant Kumar <[email protected]>
AuthorDate: Sat Jul 15 08:08:42 2023 -0700

    HDDS-9004. [Snapshot] Pause the compaction log append if tarball creation 
is in progress (#5070)
---
 .../hadoop/hdds/utils/DBCheckpointServlet.java     | 12 ++++++++
 .../ozone/rocksdiff/RocksDBCheckpointDiffer.java   | 35 +++++++++++++++++++++-
 .../hadoop/ozone/om/TestOMDbCheckpointServlet.java |  5 +++-
 3 files changed, 50 insertions(+), 2 deletions(-)

diff --git 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/DBCheckpointServlet.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/DBCheckpointServlet.java
index e5e6682aa9..4fe82a4781 100644
--- 
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/DBCheckpointServlet.java
+++ 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/DBCheckpointServlet.java
@@ -172,7 +172,12 @@ public class DBCheckpointServlet extends HttpServlet
     }
 
     try (BootstrapStateHandler.Lock lock = getBootstrapStateLock().lock()) {
+      if (dbStore.getRocksDBCheckpointDiffer() != null) {
+        dbStore.getRocksDBCheckpointDiffer().incrementTarballRequestCount();
+      }
+
       checkpoint = dbStore.getCheckpoint(flush);
+
       if (checkpoint == null || checkpoint.getCheckpointLocation() == null) {
         LOG.error("Unable to process metadata snapshot request. " +
             "Checkpoint request returned null.");
@@ -215,6 +220,13 @@ public class DBCheckpointServlet extends HttpServlet
       response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
       dbMetrics.incNumCheckpointFails();
     } finally {
+      if (dbStore.getRocksDBCheckpointDiffer() != null) {
+        synchronized (dbStore.getRocksDBCheckpointDiffer()) {
+          dbStore.getRocksDBCheckpointDiffer().decrementTarballRequestCount();
+          dbStore.getRocksDBCheckpointDiffer().notifyAll();
+        }
+      }
+
       if (checkpoint != null) {
         try {
           checkpoint.cleanupCheckpoint();
diff --git 
a/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java
 
b/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java
index f26609f7bb..653556c4eb 100644
--- 
a/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java
+++ 
b/hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDBCheckpointDiffer.java
@@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.commons.collections.CollectionUtils;
@@ -179,6 +180,7 @@ public class RocksDBCheckpointDiffer implements 
AutoCloseable,
       = new BootstrapStateHandler.Lock();
 
   private ColumnFamilyHandle snapshotInfoTableCFHandle;
+  private final AtomicInteger tarballRequestCount;
 
   /**
    * This is a package private constructor and should not be used other than
@@ -240,6 +242,7 @@ public class RocksDBCheckpointDiffer implements 
AutoCloseable,
     } else {
       this.executor = null;
     }
+    this.tarballRequestCount = new AtomicInteger(0);
   }
 
   private String createCompactionLogDir(String metadataDirName,
@@ -481,7 +484,6 @@ public class RocksDBCheckpointDiffer implements 
AutoCloseable,
       @Override
       public void onCompactionBegin(RocksDB db,
                                     CompactionJobInfo compactionJobInfo) {
-
         if (compactionJobInfo.inputFiles().size() == 0) {
           LOG.error("Compaction input files list is empty");
           return;
@@ -588,6 +590,8 @@ public class RocksDBCheckpointDiffer implements 
AutoCloseable,
             return;
           }
 
+          waitForTarballCreation();
+
           // Write input and output file names to compaction log
           appendToCurrentCompactionLog(content);
 
@@ -601,6 +605,22 @@ public class RocksDBCheckpointDiffer implements 
AutoCloseable,
     };
   }
 
+  /**
+   * Check if there is any in_progress tarball creation request and wait till
+   * all tarball creation finish, and it gets notified.
+   */
+  private void waitForTarballCreation() {
+    while (tarballRequestCount.get() != 0) {
+      try {
+        wait(Integer.MAX_VALUE);
+      } catch (InterruptedException e) {
+        Thread.currentThread().interrupt();
+        LOG.error("Compaction log thread {} is interrupted.",
+            Thread.currentThread().getName());
+      }
+    }
+  }
+
   /**
    * Creates a hard link between provided link and source.
    * It doesn't throw any exception if {@link Files#createLink} throws
@@ -1495,6 +1515,19 @@ public class RocksDBCheckpointDiffer implements 
AutoCloseable,
     }
   }
 
+  public void incrementTarballRequestCount() {
+    tarballRequestCount.incrementAndGet();
+  }
+
+  public void decrementTarballRequestCount() {
+    tarballRequestCount.decrementAndGet();
+  }
+
+  @VisibleForTesting
+  public int getTarballRequestCount() {
+    return tarballRequestCount.get();
+  }
+
   @VisibleForTesting
   public boolean debugEnabled(Integer level) {
     return DEBUG_LEVEL.contains(level);
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMDbCheckpointServlet.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMDbCheckpointServlet.java
index b57fbbb78e..cc82632fa6 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMDbCheckpointServlet.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMDbCheckpointServlet.java
@@ -86,7 +86,6 @@ import static 
org.apache.hadoop.ozone.OzoneConsts.OZONE_DB_CHECKPOINT_REQUEST_FL
 import static 
org.apache.hadoop.ozone.OzoneConsts.OZONE_DB_CHECKPOINT_REQUEST_TO_EXCLUDE_SST;
 import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HTTP_AUTH_TYPE;
 
-
 import org.apache.ozone.test.GenericTestUtils;
 
 import org.junit.Assert;
@@ -397,6 +396,10 @@ public class TestOMDbCheckpointServlet {
     // Get the tarball.
     when(responseMock.getOutputStream()).thenReturn(servletOutputStream);
     omDbCheckpointServletMock.doGet(requestMock, responseMock);
+
+    // Verify that tarball request count reaches to zero once doGet completes.
+    Assertions.assertEquals(0,
+        dbStore.getRocksDBCheckpointDiffer().getTarballRequestCount());
     dbCheckpoint = realCheckpoint.get();
 
     // Untar the file into a temp folder to be examined.


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

Reply via email to