ashishkumar50 commented on code in PR #4880:
URL: https://github.com/apache/ozone/pull/4880#discussion_r1238482462


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/ScmTableCountTask.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * 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.tasks;
+
+import com.google.common.collect.Iterators;
+import org.apache.hadoop.hdds.utils.db.DBStore;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.hdds.utils.db.TableIterator;
+import org.apache.hadoop.ozone.recon.scm.ReconScmTask;
+import org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade;
+import org.hadoop.ozone.recon.schema.UtilizationSchemaDefinition;
+import org.hadoop.ozone.recon.schema.tables.daos.ReconTaskStatusDao;
+import org.hadoop.ozone.recon.schema.tables.daos.ScmTableCountDao;
+import org.hadoop.ozone.recon.schema.tables.pojos.ScmTableCount;
+import org.jooq.DSLContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import static 
org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition.DELETED_BLOCKS;
+import static 
org.hadoop.ozone.recon.schema.UtilizationSchemaDefinition.SCM_TABLE_COUNT_TABLE_NAME;
+
+
+/**
+ * Any background task that tracks SCM's table counts.
+ */
+public class ScmTableCountTask extends ReconScmTask {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(ScmTableCountTask.class);
+
+  private final DBStore scmDBStore;
+  private final ScmTableCountDao scmTableCountDao;
+  private final DSLContext dslContext;
+  private final long interval;
+  private ReadWriteLock lock = new ReentrantReadWriteLock(true);
+  private static final long NANOSECONDS_IN_MILLISECOND = 1_000_000;
+
+  public ScmTableCountTask(ReconStorageContainerManagerFacade reconSCM,
+                           ReconTaskStatusDao reconTaskStatusDao,
+                           ReconTaskConfig reconTaskConfig,
+                           ScmTableCountDao scmTableCountDao,
+                           UtilizationSchemaDefinition schemaDefinition) {
+    super(reconTaskStatusDao);
+    this.scmDBStore = reconSCM.getScmDBStore();
+    this.scmTableCountDao = scmTableCountDao;
+    this.dslContext = schemaDefinition.getDSLContext();
+    this.interval = reconTaskConfig.getScmTableCountTaskInterval().toMillis();
+  }
+
+  @Override
+  protected synchronized void run() {
+    try {
+      while (canRun()) {
+        wait(interval);
+        runTableCountProcess();
+      }
+    } catch (Throwable t) {
+      LOG.error("Error while running ScmTableCountTask: {}", t);
+      if (t instanceof InterruptedException) {
+        Thread.currentThread().interrupt();
+      }
+    }
+  }
+
+  private void runTableCountProcess() {
+    try {
+      long startTime, endTime, duration, durationMilliseconds;
+
+      int execute = dslContext.truncate(SCM_TABLE_COUNT_TABLE_NAME).execute();
+      LOG.info("Deleted {} records from {}", execute,
+          SCM_TABLE_COUNT_TABLE_NAME);
+
+      startTime = System.nanoTime();
+      processTableCount();
+      endTime = System.nanoTime();
+      duration = endTime - startTime;
+      durationMilliseconds = duration / NANOSECONDS_IN_MILLISECOND;
+      LOG.info(
+          "Elapsed Time in milliseconds for processTableCount() execution: {}",
+          durationMilliseconds);
+    } catch (Exception e) {
+      LOG.error("An error occurred while performing table count: {}", e);
+    }
+  }
+
+  /**
+   * Processes the table count by iterating over SCM tables and retrieving the
+   * counts of objects in each table. The counts are then stored in the Recon
+   * database.
+   *
+   * @throws IOException if an I/O error occurs during table count processing.
+   */
+  public void processTableCount() throws IOException {
+    try {

Review Comment:
   Removed throws IOException, It's fine now.



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