Skip to content

Commit

Permalink
HDDS-11649. Recon ListKeys API: Simplify filter predicates (apache#7395)
Browse files Browse the repository at this point in the history
  • Loading branch information
sodonnel authored Nov 6, 2024
1 parent 2547ac0 commit 0415c0b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@
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;
Expand Down Expand Up @@ -1231,46 +1227,18 @@ private boolean applyFilters(Table.KeyValue<String, OmKeyInfo> entry, ParamInfo

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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -37,6 +41,8 @@ public class ParamInfo {
*/
private String creationDate;

private long creationDateEpoch = -1;

/**
*
*/
Expand Down Expand Up @@ -87,6 +93,14 @@ public String getCreationDate() {
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;
}
Expand Down

0 comments on commit 0415c0b

Please sign in to comment.