Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-11649. Recon ListKeys API: Simplify filter predicates #7395

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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