swagle commented on a change in pull request #1055: HDDS-1705. Recon: Add 
estimatedTotalCount to the response of ...
URL: https://github.com/apache/hadoop/pull/1055#discussion_r300187951
 
 

 ##########
 File path: 
hadoop-ozone/ozone-recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/ContainerDBServiceProviderImpl.java
 ##########
 @@ -271,8 +332,54 @@ public void deleteContainerMapping(ContainerKeyPrefix 
containerKeyPrefix)
     containerKeyTable.delete(containerKeyPrefix);
   }
 
+  /**
+   * Get total count of containers.
+   *
+   * @return total count of containers.
+   */
+  @Override
+  public long getCountForContainers() {
+    GlobalStats containerCountRecord =
+        globalStatsDao.fetchOneByKey(CONTAINER_COUNT_KEY);
+
+    return (containerCountRecord == null) ? 0L :
+        containerCountRecord.getValue();
+  }
+
   @Override
   public TableIterator getContainerTableIterator() {
     return containerKeyTable.iterator();
   }
+
+  /**
+   * Store the total count of containers into the container DB store.
+   *
+   * @param count count of the containers present in the system.
+   */
+  @Override
+  public void storeContainerCount(Long count) {
+    // Get the current timestamp
+    Timestamp now =
+        using(sqlConfiguration).fetchValue(select(currentTimestamp()));
+    GlobalStats containerCountRecord =
+        globalStatsDao.fetchOneByKey(CONTAINER_COUNT_KEY);
+    GlobalStats globalStatsRecord =
+        new GlobalStats(CONTAINER_COUNT_KEY, count, now);
+
+    // Insert a new record for CONTAINER_COUNT_KEY if it does not exist
+    if (containerCountRecord == null) {
+      globalStatsDao.insert(globalStatsRecord);
+    } else {
+      globalStatsDao.update(globalStatsRecord);
+    }
+  }
+
+  /**
+   * Increment the total count for containers in the system.
+   */
+  @Override
+  public void incrementContainerCount() {
+    long containersCount = getCountForContainers();
+    storeContainerCount(++containersCount);
 
 Review comment:
   Since we are counting the total, we should do a batch commit here, if Jooq 
has this functionality. Maybe future Jira.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to