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

sodonnell 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 0415c0b4f7 HDDS-11649. Recon ListKeys API: Simplify filter predicates 
(#7395)
0415c0b4f7 is described below

commit 0415c0b4f7179e56e76ac57bb1974915729c3ef7
Author: Stephen O'Donnell <[email protected]>
AuthorDate: Wed Nov 6 17:46:13 2024 +0000

    HDDS-11649. Recon ListKeys API: Simplify filter predicates (#7395)
---
 .../ozone/recon/api/OMDBInsightEndpoint.java       | 52 +++++-----------------
 .../hadoop/ozone/recon/api/types/ParamInfo.java    | 14 ++++++
 2 files changed, 24 insertions(+), 42 deletions(-)

diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java
index d28275e547..8611abe88c 100644
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java
+++ 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java
@@ -61,10 +61,6 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.TimeZone;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 import static org.apache.commons.lang3.StringUtils.isNotBlank;
 import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
@@ -1231,46 +1227,18 @@ public class OMDBInsightEndpoint {
 
     LOG.debug("Applying filters on : {}", entry.getKey());
 
-    long epochMillis =
-        ReconUtils.convertToEpochMillis(paramInfo.getCreationDate(), 
"MM-dd-yyyy HH:mm:ss", TimeZone.getDefault());
-    Predicate<Table.KeyValue<String, OmKeyInfo>> keyAgeFilter = keyData -> {
-      try {
-        return keyData.getValue().getCreationTime() >= epochMillis;
-      } catch (IOException e) {
-        throw new RuntimeException(e);
-      }
-    };
-    Predicate<Table.KeyValue<String, OmKeyInfo>> keyReplicationFilter =
-        keyData -> {
-          try {
-            return 
keyData.getValue().getReplicationConfig().getReplicationType().name()
-                .equals(paramInfo.getReplicationType());
-          } catch (IOException e) {
-            try {
-              throw new IOException(e);
-            } catch (IOException ex) {
-              throw new RuntimeException(ex);
-            }
-          }
-        };
-    Predicate<Table.KeyValue<String, OmKeyInfo>> keySizeFilter = keyData -> {
-      try {
-        return keyData.getValue().getDataSize() >= paramInfo.getKeySize();
-      } catch (IOException e) {
-        throw new RuntimeException(e);
-      }
-    };
-
-    List<Table.KeyValue<String, OmKeyInfo>> filteredKeyList = Stream.of(entry)
-        .filter(keyData -> !StringUtils.isEmpty(paramInfo.getCreationDate()) ? 
keyAgeFilter.test(keyData) : true)
-        .filter(
-            keyData -> !StringUtils.isEmpty(paramInfo.getReplicationType()) ? 
keyReplicationFilter.test(keyData) : true)
-        .filter(keySizeFilter)
-        .collect(Collectors.toList());
+    if (!StringUtils.isEmpty(paramInfo.getCreationDate())
+        && (entry.getValue().getCreationTime() < 
paramInfo.getCreationDateEpoch())) {
+      return false;
+    }
 
-    LOG.debug("After applying filter on : {}, filtered list size: {}", 
entry.getKey(), filteredKeyList.size());
+    if (!StringUtils.isEmpty(paramInfo.getReplicationType())
+        && 
!entry.getValue().getReplicationConfig().getReplicationType().name().equals(
+            paramInfo.getReplicationType())) {
+      return false;
+    }
 
-    return (filteredKeyList.size() > 0);
+    return entry.getValue().getDataSize() >= paramInfo.getKeySize();
   }
 
   /**
diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/ParamInfo.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/ParamInfo.java
index 345b042907..e4bcea47b4 100644
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/ParamInfo.java
+++ 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/ParamInfo.java
@@ -17,6 +17,10 @@
  */
 package org.apache.hadoop.ozone.recon.api.types;
 
+import org.apache.hadoop.ozone.recon.ReconUtils;
+
+import java.util.TimeZone;
+
 /**
  * Wrapper object for statistics of records of a page in API response.
  */
@@ -37,6 +41,8 @@ public class ParamInfo {
    */
   private String creationDate;
 
+  private long creationDateEpoch = -1;
+
   /**
    *
    */
@@ -87,6 +93,14 @@ public class ParamInfo {
     return creationDate;
   }
 
+  public long getCreationDateEpoch() {
+    if (creationDateEpoch == -1) {
+      creationDateEpoch = ReconUtils.convertToEpochMillis(
+          getCreationDate(), "MM-dd-yyyy HH:mm:ss", TimeZone.getDefault());
+    }
+    return creationDateEpoch;
+  }
+
   public String getReplicationType() {
     return replicationType;
   }


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

Reply via email to