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

sumitagrawal 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 6c1d187995 HDDS-9101. Recon - Overview Page shows incorrect count of 
keys and buckets. (#5133)
6c1d187995 is described below

commit 6c1d18799502688543fcd33cf1a4bc9f233b420d
Author: Arafat2198 <[email protected]>
AuthorDate: Tue Aug 1 20:13:01 2023 +0530

    HDDS-9101. Recon - Overview Page shows incorrect count of keys and buckets. 
(#5133)
---
 .../ozone/recon/tasks/OmTableInsightTask.java      |  2 +-
 .../ozone/recon/api/TestOmDBInsightEndPoint.java   | 98 +++++++++++++++++-----
 2 files changed, 79 insertions(+), 21 deletions(-)

diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OmTableInsightTask.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OmTableInsightTask.java
index 9a009d9ee0..c814d9d9e3 100644
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OmTableInsightTask.java
+++ 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/OmTableInsightTask.java
@@ -489,7 +489,7 @@ public class OmTableInsightTask implements ReconOmTask {
   }
 
   public static String getTableCountKeyFromTable(String tableName) {
-    return tableName + "TableCount";
+    return tableName + "Count";
   }
 
   public static String getReplicatedSizeKeyFromTable(String tableName) {
diff --git 
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestOmDBInsightEndPoint.java
 
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestOmDBInsightEndPoint.java
index c88a26b877..8301537980 100644
--- 
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestOmDBInsightEndPoint.java
+++ 
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestOmDBInsightEndPoint.java
@@ -211,33 +211,84 @@ public class TestOmDBInsightEndPoint extends 
AbstractReconSqlDBTest {
         keyInsightInfoResp.getNonFSOKeyInfoList().get(0).getPath());
   }
 
+  @Test
+  public void testKeyCountsForValidAndInvalidKeyPrefix() {
+    Timestamp now = new Timestamp(System.currentTimeMillis());
+    GlobalStatsDao statsDao = omdbInsightEndpoint.getDao();
+
+    // Insert valid key count with valid key prefix
+    insertGlobalStatsRecords(statsDao, now,
+        "openKeyTable" + "Count", 3L);
+    insertGlobalStatsRecords(statsDao, now,
+        "openFileTable" + "Count", 3L);
+    insertGlobalStatsRecords(statsDao, now,
+        "openKeyTable" + "ReplicatedDataSize", 150L);
+    insertGlobalStatsRecords(statsDao, now,
+        "openFileTable" + "ReplicatedDataSize", 150L);
+    insertGlobalStatsRecords(statsDao, now,
+        "openKeyTable" + "UnReplicatedDataSize", 50L);
+    insertGlobalStatsRecords(statsDao, now,
+        "openFileTable" + "UnReplicatedDataSize", 50L);
+
+    Response openKeyInfoResp =
+        omdbInsightEndpoint.getOpenKeyInfo(-1, "", true, true);
+    KeyInsightInfoResponse keyInsightInfoResp = (KeyInsightInfoResponse)
+        openKeyInfoResp.getEntity();
+    Assertions.assertNotNull(keyInsightInfoResp);
+    Map<String, Long> summary = keyInsightInfoResp.getKeysSummary();
+    // Assert that the key prefix format is accepted in the global stats
+    Assertions.assertEquals(6L, summary.get("totalOpenKeys"));
+    Assertions.assertEquals(300L, summary.get("totalReplicatedDataSize"));
+    Assertions.assertEquals(100L, summary.get("totalUnreplicatedDataSize"));
+
+    // Delete the previous records and Update the new value for valid key 
prefix
+    statsDao.deleteById("openKeyTable" + "Count",
+        "openFileTable" + "Count",
+        "openKeyTable" + "ReplicatedDataSize",
+        "openFileTable" + "ReplicatedDataSize",
+        "openKeyTable" + "UnReplicatedDataSize",
+        "openFileTable" + "UnReplicatedDataSize");
+
+    // Insert new record for a key with invalid prefix
+    insertGlobalStatsRecords(statsDao, now, "openKeyTable" + "InvalidPrefix",
+        3L);
+    insertGlobalStatsRecords(statsDao, now, "openFileTable" + "InvalidPrefix",
+        3L);
+
+    openKeyInfoResp =
+        omdbInsightEndpoint.getOpenKeyInfo(-1, "", true, true);
+    keyInsightInfoResp = (KeyInsightInfoResponse)
+        openKeyInfoResp.getEntity();
+    Assertions.assertNotNull(keyInsightInfoResp);
+    summary = keyInsightInfoResp.getKeysSummary();
+    // Assert that the key format is not accepted in the global stats
+    Assertions.assertEquals(0L, summary.get("totalOpenKeys"));
+    Assertions.assertEquals(0L, summary.get("totalReplicatedDataSize"));
+    Assertions.assertEquals(0L, summary.get("totalUnreplicatedDataSize"));
+  }
+
   @Test
   public void testKeysSummaryAttribute() {
     Timestamp now = new Timestamp(System.currentTimeMillis());
     GlobalStatsDao statsDao = omdbInsightEndpoint.getDao();
     // Insert records for replicated and unreplicated data sizes
-    GlobalStats newRecord =
-        new GlobalStats("openFileTableReplicatedDataSize", 30L, now);
-    statsDao.insert(newRecord);
-    newRecord = new GlobalStats("openKeyTableReplicatedDataSize", 30L, now);
-    statsDao.insert(newRecord);
-    newRecord = new GlobalStats("deletedTableReplicatedDataSize", 30L, now);
-    statsDao.insert(newRecord);
-    newRecord = new GlobalStats("openFileTableUnReplicatedDataSize", 10L, now);
-    statsDao.insert(newRecord);
-    newRecord = new GlobalStats("openKeyTableUnReplicatedDataSize", 10L, now);
-    statsDao.insert(newRecord);
-    newRecord = new GlobalStats("deletedTableUnReplicatedDataSize", 10L, now);
-    statsDao.insert(newRecord);
-
+    insertGlobalStatsRecords(statsDao, now, "openFileTableReplicatedDataSize",
+        30L);
+    insertGlobalStatsRecords(statsDao, now, "openKeyTableReplicatedDataSize",
+        30L);
+    insertGlobalStatsRecords(statsDao, now, "deletedTableReplicatedDataSize",
+        30L);
+    insertGlobalStatsRecords(statsDao, now, 
"openFileTableUnReplicatedDataSize",
+        10L);
+    insertGlobalStatsRecords(statsDao, now, "openKeyTableUnReplicatedDataSize",
+        10L);
+    insertGlobalStatsRecords(statsDao, now, "deletedTableUnReplicatedDataSize",
+        10L);
 
     // Insert records for table counts
-    newRecord = new GlobalStats("openKeyTableTableCount", 3L, now);
-    statsDao.insert(newRecord);
-    newRecord = new GlobalStats("openFileTableTableCount", 3L, now);
-    statsDao.insert(newRecord);
-    newRecord = new GlobalStats("deletedTableTableCount", 3L, now);
-    statsDao.insert(newRecord);
+    insertGlobalStatsRecords(statsDao, now, "openKeyTableCount", 3L);
+    insertGlobalStatsRecords(statsDao, now, "openFileTableCount", 3L);
+    insertGlobalStatsRecords(statsDao, now, "deletedTableCount", 3L);
 
     // Call the API of Open keys to get the response
     Response openKeyInfoResp =
@@ -262,6 +313,13 @@ public class TestOmDBInsightEndPoint extends 
AbstractReconSqlDBTest {
     Assertions.assertEquals(3L, summary.get("totalDeletedKeys"));
   }
 
+  private void insertGlobalStatsRecords(GlobalStatsDao statsDao,
+                                        Timestamp timestamp, String key,
+                                        long value) {
+    GlobalStats newRecord = new GlobalStats(key, value, timestamp);
+    statsDao.insert(newRecord);
+  }
+
   @Test
   public void testGetOpenKeyInfoLimitParam() throws Exception {
     OmKeyInfo omKeyInfo1 =


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

Reply via email to