Skip to content

Commit

Permalink
Polish: use primitives where possible, @slf4j rather than Logger, sim…
Browse files Browse the repository at this point in the history
…plify conditions
  • Loading branch information
roimenashe committed Nov 14, 2023
1 parent acc3c09 commit f97b47a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void setFilterFromMultipleQualifiers(Statement stmt, Qualifier qualifier
int currBinValuesRatio = getMinBinValuesRatioForQualifier(stmt, innerQualifier);
// Compare the cardinality of each qualifier and select the qualifier that has the index with
// the lowest bin values ratio
if (currBinValuesRatio < minBinValuesRatio && currBinValuesRatio != 0) {
if (currBinValuesRatio != 0 && currBinValuesRatio < minBinValuesRatio) {
minBinValuesRatio = currBinValuesRatio;
minBinValuesRatioQualifier = innerQualifier;
}
Expand Down Expand Up @@ -145,9 +145,6 @@ private int getMinBinValuesRatioForQualifier(Statement stmt, Qualifier qualifier
.filter(index -> index.getBinValuesRatio() != 0)
.min(Comparator.comparing(Index::getBinValuesRatio));

if (minBinValuesRatio.isPresent()) {
return minBinValuesRatio.get().getBinValuesRatio();
}
return 0;
return minBinValuesRatio.map(Index::getBinValuesRatio).orElse(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.Info;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.aerospike.query.model.Index;
import org.springframework.data.aerospike.query.model.IndexKey;
import org.springframework.data.aerospike.query.model.IndexesInfo;
Expand All @@ -37,15 +36,14 @@
*
* @author Sergii Karpenko
*/
@Slf4j
public class InternalIndexOperations {

// Base64 will return index context as a base64 response
private static final String SINDEX_WITH_BASE64 = "sindex-list:;b64=true";

private final IndexInfoParser indexInfoParser;

private final Logger log = LoggerFactory.getLogger(InternalIndexOperations.class);

public InternalIndexOperations(IndexInfoParser indexInfoParser) {
this.indexInfoParser = indexInfoParser;
}
Expand Down Expand Up @@ -77,14 +75,14 @@ public void enrichIndexesWithCardinality(IAerospikeClient client, Map<IndexKey,
);
}

public Integer getIndexBinValuesRatio(IAerospikeClient client, String namespace, String indexName) {
public int getIndexBinValuesRatio(IAerospikeClient client, String namespace, String indexName) {
if (ServerVersionUtils.isSIndexCardinalitySupported(client)) {

try {
String indexStatData = Info.request(null, client.getCluster().getRandomNode(),
String.format("sindex-stat:ns=%s;indexname=%s", namespace, indexName));

return Integer.valueOf(
return Integer.parseInt(
Arrays.stream(indexStatData.split(";"))
.map(String::trim)
.toList().stream()
Expand All @@ -94,7 +92,7 @@ public Integer getIndexBinValuesRatio(IAerospikeClient client, String namespace,
.collect(Collectors.toMap(t -> t.get(0), t -> t.get(1)))
.get("entries_per_bval"));
} catch (Exception e) {
log.warn("Failed to fetch secondary index %s cardinality".formatted(indexName), e);
log.warn("Failed to fetch secondary index {} cardinality", indexName, e);
}
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Index {
private final IndexCollectionType indexCollectionType;
private final CTX[] ctx;
@Setter
private Integer binValuesRatio;
private int binValuesRatio;

public Index(String name, String namespace, String set, String bin, IndexType indexType,
IndexCollectionType indexCollectionType) {
Expand Down

0 comments on commit f97b47a

Please sign in to comment.