You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/10/11 20:09:34 UTC

[GitHub] [ozone] smengcl commented on a diff in pull request #3821: HDDS-7146. Recon: Add button to trigger OM DB Sync (Backend)

smengcl commented on code in PR #3821:
URL: https://github.com/apache/ozone/pull/3821#discussion_r992716689


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/OzoneManagerServiceProviderImpl.java:
##########
@@ -237,22 +239,53 @@ public void start() {
             ReconServerConfigKeys.RECON_OM_SNAPSHOT_TASK_INITIAL_DELAY,
             OZONE_RECON_OM_SNAPSHOT_TASK_INITIAL_DELAY_DEFAULT),
         TimeUnit.MILLISECONDS);
+    startSyncDataFromOM(initialDelay);
+  }
+
+  private void startSyncDataFromOM(long initialDelay) {
+
     long interval = configuration.getTimeDuration(
         OZONE_RECON_OM_SNAPSHOT_TASK_INTERVAL_DELAY,
         configuration.get(
             ReconServerConfigKeys.RECON_OM_SNAPSHOT_TASK_INTERVAL_DELAY,
             OZONE_RECON_OM_SNAPSHOT_TASK_INTERVAL_DEFAULT),
         TimeUnit.MILLISECONDS);
+    LOG.info("Before the new scheduleWithFixedDelay");

Review Comment:
   ```suggestion
       LOG.debug("Triggering XYZ");
   ```



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMSyncEndpoint.java:
##########
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.recon.api;
+
+import org.apache.hadoop.ozone.recon.spi.OzoneManagerServiceProvider;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+/**
+ * Endpoint to trigger the OM DB sync between Recon and OM.
+ */
+@Path("/omsync")

Review Comment:
   ```suggestion
   @Path("/triggerdbsync")
   ```



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/OzoneManagerServiceProviderImpl.java:
##########
@@ -443,62 +476,68 @@ void innerGetAndApplyDeltaUpdatesFromOM(long fromSequenceNumber,
    */
   @VisibleForTesting
   public void syncDataFromOM() {

Review Comment:
   ```suggestion
     public boolean syncDataFromOM() {
   ```



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/OzoneManagerServiceProviderImpl.java:
##########
@@ -237,22 +239,53 @@ public void start() {
             ReconServerConfigKeys.RECON_OM_SNAPSHOT_TASK_INITIAL_DELAY,
             OZONE_RECON_OM_SNAPSHOT_TASK_INITIAL_DELAY_DEFAULT),
         TimeUnit.MILLISECONDS);
+    startSyncDataFromOM(initialDelay);
+  }
+
+  private void startSyncDataFromOM(long initialDelay) {
+
     long interval = configuration.getTimeDuration(
         OZONE_RECON_OM_SNAPSHOT_TASK_INTERVAL_DELAY,
         configuration.get(
             ReconServerConfigKeys.RECON_OM_SNAPSHOT_TASK_INTERVAL_DELAY,
             OZONE_RECON_OM_SNAPSHOT_TASK_INTERVAL_DEFAULT),
         TimeUnit.MILLISECONDS);
+    LOG.info("Before the new scheduleWithFixedDelay");
     scheduler.scheduleWithFixedDelay(() -> {
       try {
-        syncDataFromOM();
+        if (!isSyncDataFromOMRunning) {
+          syncDataFromOM();
+        }

Review Comment:
   `else`: `LOG.debug("OM DB sync is already running")`



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMSyncEndpoint.java:
##########
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.recon.api;
+
+import org.apache.hadoop.ozone.recon.spi.OzoneManagerServiceProvider;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+/**
+ * Endpoint to trigger the OM DB sync between Recon and OM.
+ */
+@Path("/omsync")
+@Produces(MediaType.APPLICATION_JSON)
+public class OMSyncEndpoint {
+
+  private OzoneManagerServiceProvider ozoneManagerServiceProvider;
+
+  @Inject
+  public OMSyncEndpoint(
+      OzoneManagerServiceProvider ozoneManagerServiceProvider) {
+    this.ozoneManagerServiceProvider = ozoneManagerServiceProvider;
+  }
+
+  @GET
+  @Path("trigger")

Review Comment:
   ```suggestion
     @Path("om")
   ```



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/OzoneManagerServiceProviderImpl.java:
##########
@@ -443,62 +476,68 @@ void innerGetAndApplyDeltaUpdatesFromOM(long fromSequenceNumber,
    */
   @VisibleForTesting
   public void syncDataFromOM() {
-    LOG.info("Syncing data from Ozone Manager.");
-    long currentSequenceNumber = getCurrentOMDBSequenceNumber();
-    LOG.debug("Seq number of Recon's OM DB : {}", currentSequenceNumber);
-    boolean fullSnapshot = false;
+    isSyncDataFromOMRunning = true;

Review Comment:
   ```suggestion
       if (isSyncDataFromOMRunning == true) {
         LOG.debug("syncDataFromOM is already running");
         return false;
       }
       isSyncDataFromOMRunning = true;
   ```



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMSyncEndpoint.java:
##########
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.recon.api;
+
+import org.apache.hadoop.ozone.recon.spi.OzoneManagerServiceProvider;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+/**
+ * Endpoint to trigger the OM DB sync between Recon and OM.
+ */
+@Path("/omsync")
+@Produces(MediaType.APPLICATION_JSON)
+public class OMSyncEndpoint {

Review Comment:
   ```suggestion
   public class TriggerDBSyncEndpoint {
   ```



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/OzoneManagerServiceProviderImpl.java:
##########
@@ -443,62 +476,68 @@ void innerGetAndApplyDeltaUpdatesFromOM(long fromSequenceNumber,
    */
   @VisibleForTesting
   public void syncDataFromOM() {
-    LOG.info("Syncing data from Ozone Manager.");
-    long currentSequenceNumber = getCurrentOMDBSequenceNumber();
-    LOG.debug("Seq number of Recon's OM DB : {}", currentSequenceNumber);
-    boolean fullSnapshot = false;
+    isSyncDataFromOMRunning = true;
 
-    if (currentSequenceNumber <= 0) {
-      fullSnapshot = true;
-    } else {
-      try (OMDBUpdatesHandler omdbUpdatesHandler =
-               new OMDBUpdatesHandler(omMetadataManager)) {
-        LOG.info("Obtaining delta updates from Ozone Manager");
-        // Get updates from OM and apply to local Recon OM DB.
-        getAndApplyDeltaUpdatesFromOM(currentSequenceNumber,
-            omdbUpdatesHandler);
-        // Update timestamp of successful delta updates query.
-        ReconTaskStatus reconTaskStatusRecord = new ReconTaskStatus(
-            OmSnapshotTaskName.OmDeltaRequest.name(),
-                System.currentTimeMillis(), getCurrentOMDBSequenceNumber());
-        reconTaskStatusDao.update(reconTaskStatusRecord);
-
-        // Pass on DB update events to tasks that are listening.
-        reconTaskController.consumeOMEvents(new OMUpdateEventBatch(
-            omdbUpdatesHandler.getEvents()), omMetadataManager);
-      } catch (InterruptedException intEx) {
-        Thread.currentThread().interrupt();
-      } catch (Exception e) {
-        metrics.incrNumDeltaRequestsFailed();
-        LOG.warn("Unable to get and apply delta updates from OM.", e);
-        fullSnapshot = true;
-      }
-    }
+    try {
+      LOG.info("Syncing data from Ozone Manager.");
+      long currentSequenceNumber = getCurrentOMDBSequenceNumber();
+      LOG.debug("Seq number of Recon's OM DB : {}", currentSequenceNumber);
+      boolean fullSnapshot = false;
 
-    if (fullSnapshot) {
-      try {
-        metrics.incrNumSnapshotRequests();
-        LOG.info("Obtaining full snapshot from Ozone Manager");
-        // Update local Recon OM DB to new snapshot.
-        boolean success = updateReconOmDBWithNewSnapshot();
-        // Update timestamp of successful delta updates query.
-        if (success) {
-          ReconTaskStatus reconTaskStatusRecord =
-              new ReconTaskStatus(
-                  OmSnapshotTaskName.OmSnapshotRequest.name(),
-                  System.currentTimeMillis(), getCurrentOMDBSequenceNumber());
+      if (currentSequenceNumber <= 0) {
+        fullSnapshot = true;
+      } else {
+        try (OMDBUpdatesHandler omdbUpdatesHandler =
+            new OMDBUpdatesHandler(omMetadataManager)) {
+          LOG.info("Obtaining delta updates from Ozone Manager");
+          // Get updates from OM and apply to local Recon OM DB.
+          getAndApplyDeltaUpdatesFromOM(currentSequenceNumber,
+              omdbUpdatesHandler);
+          // Update timestamp of successful delta updates query.
+          ReconTaskStatus reconTaskStatusRecord = new ReconTaskStatus(
+              OmSnapshotTaskName.OmDeltaRequest.name(),
+              System.currentTimeMillis(), getCurrentOMDBSequenceNumber());
           reconTaskStatusDao.update(reconTaskStatusRecord);
 
-          // Reinitialize tasks that are listening.
-          LOG.info("Calling reprocess on Recon tasks.");
-          reconTaskController.reInitializeTasks(omMetadataManager);
+          // Pass on DB update events to tasks that are listening.
+          reconTaskController.consumeOMEvents(new OMUpdateEventBatch(
+              omdbUpdatesHandler.getEvents()), omMetadataManager);
+        } catch (InterruptedException intEx) {
+          Thread.currentThread().interrupt();
+        } catch (Exception e) {
+          metrics.incrNumDeltaRequestsFailed();
+          LOG.warn("Unable to get and apply delta updates from OM.", e);
+          fullSnapshot = true;
+        }
+      }
+
+      if (fullSnapshot) {
+        try {
+          metrics.incrNumSnapshotRequests();
+          LOG.info("Obtaining full snapshot from Ozone Manager");
+          // Update local Recon OM DB to new snapshot.
+          boolean success = updateReconOmDBWithNewSnapshot();
+          // Update timestamp of successful delta updates query.
+          if (success) {
+            ReconTaskStatus reconTaskStatusRecord =
+                new ReconTaskStatus(
+                    OmSnapshotTaskName.OmSnapshotRequest.name(),
+                    System.currentTimeMillis(), getCurrentOMDBSequenceNumber());
+            reconTaskStatusDao.update(reconTaskStatusRecord);
+
+            // Reinitialize tasks that are listening.
+            LOG.info("Calling reprocess on Recon tasks.");
+            reconTaskController.reInitializeTasks(omMetadataManager);
+          }
+        } catch (InterruptedException intEx) {
+          Thread.currentThread().interrupt();
+        } catch (Exception e) {
+          metrics.incrNumSnapshotRequestsFailed();
+          LOG.error("Unable to update Recon's metadata with new OM DB. ", e);
         }
-      } catch (InterruptedException intEx) {
-        Thread.currentThread().interrupt();
-      } catch (Exception e) {
-        metrics.incrNumSnapshotRequestsFailed();
-        LOG.error("Unable to update Recon's metadata with new OM DB. ", e);
       }
+    } finally {
+      isSyncDataFromOMRunning = false;
     }

Review Comment:
   ```suggestion
       }
       return true;
   ```



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