Skip to content

Commit

Permalink
rename ServerVersionUtils to ServerVersionSupport and move it to serv…
Browse files Browse the repository at this point in the history
…er.version
  • Loading branch information
agrgr committed Dec 18, 2023
1 parent 5a6c8e7 commit 80b023f
Show file tree
Hide file tree
Showing 32 changed files with 150 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.springframework.data.aerospike.query.cache.IndexRefresher;
import org.springframework.data.aerospike.query.cache.IndexesCacheUpdater;
import org.springframework.data.aerospike.query.cache.InternalIndexOperations;
import org.springframework.data.aerospike.utility.ServerVersionUtils;
import org.springframework.data.aerospike.server.version.ServerVersionSupport;

@Slf4j
@Configuration
Expand All @@ -45,9 +45,9 @@ public AerospikeTemplate aerospikeTemplate(IAerospikeClient aerospikeClient,
AerospikeMappingContext aerospikeMappingContext,
AerospikeExceptionTranslator aerospikeExceptionTranslator,
QueryEngine queryEngine, IndexRefresher indexRefresher,
ServerVersionUtils serverVersionUtils) {
ServerVersionSupport serverVersionSupport) {
return new AerospikeTemplate(aerospikeClient, nameSpace(), mappingAerospikeConverter,
aerospikeMappingContext, aerospikeExceptionTranslator, queryEngine, indexRefresher, serverVersionUtils);
aerospikeMappingContext, aerospikeExceptionTranslator, queryEngine, indexRefresher, serverVersionSupport);
}

@Bean(name = "aerospikeQueryEngine")
Expand Down Expand Up @@ -78,9 +78,9 @@ public AerospikePersistenceEntityIndexCreator aerospikePersistenceEntityIndexCre

@Bean(name = "aerospikeIndexRefresher")
public IndexRefresher indexRefresher(IAerospikeClient aerospikeClient, IndexesCacheUpdater indexesCacheUpdater,
ServerVersionUtils serverVersionUtils) {
ServerVersionSupport serverVersionSupport) {
IndexRefresher refresher = new IndexRefresher(aerospikeClient, aerospikeClient.getInfoPolicyDefault(),
new InternalIndexOperations(new IndexInfoParser()), indexesCacheUpdater, serverVersionUtils);
new InternalIndexOperations(new IndexInfoParser()), indexesCacheUpdater, serverVersionSupport);
refresher.refreshIndexes();
int refreshFrequency = aerospikeDataSettings().getIndexCacheRefreshFrequencySeconds();
processCacheRefreshFrequency(refreshFrequency, refresher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.springframework.data.aerospike.query.cache.IndexesCacheUpdater;
import org.springframework.data.aerospike.query.cache.InternalIndexOperations;
import org.springframework.data.aerospike.query.cache.ReactorIndexRefresher;
import org.springframework.data.aerospike.utility.ServerVersionUtils;
import org.springframework.data.aerospike.server.version.ServerVersionSupport;

/**
* Configuration with beans needed for reactive stuff
Expand All @@ -55,10 +55,10 @@ public ReactiveAerospikeTemplate reactiveAerospikeTemplate(MappingAerospikeConve
IAerospikeReactorClient aerospikeReactorClient,
ReactorQueryEngine reactorQueryEngine,
ReactorIndexRefresher reactorIndexRefresher,
ServerVersionUtils serverVersionUtils) {
ServerVersionSupport serverVersionSupport) {
return new ReactiveAerospikeTemplate(aerospikeReactorClient, nameSpace(), mappingAerospikeConverter,
aerospikeMappingContext, aerospikeExceptionTranslator, reactorQueryEngine, reactorIndexRefresher,
serverVersionUtils);
serverVersionSupport);
}

@Bean(name = "reactiveAerospikeQueryEngine")
Expand All @@ -79,10 +79,10 @@ public ReactorQueryEngine reactorQueryEngine(IAerospikeReactorClient aerospikeRe
@Bean(name = "reactiveAerospikeIndexRefresher")
public ReactorIndexRefresher reactorIndexRefresher(IAerospikeReactorClient aerospikeReactorClient,
IndexesCacheUpdater indexesCacheUpdater,
ServerVersionUtils serverVersionUtils) {
ServerVersionSupport serverVersionSupport) {
ReactorIndexRefresher refresher = new ReactorIndexRefresher(aerospikeReactorClient,
aerospikeReactorClient.getInfoPolicyDefault(),
new InternalIndexOperations(new IndexInfoParser()), indexesCacheUpdater, serverVersionUtils);
new InternalIndexOperations(new IndexInfoParser()), indexesCacheUpdater, serverVersionSupport);
refresher.refreshIndexes().block();
return refresher;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.springframework.data.aerospike.query.StatementBuilder;
import org.springframework.data.aerospike.query.cache.IndexesCache;
import org.springframework.data.aerospike.query.cache.IndexesCacheHolder;
import org.springframework.data.aerospike.utility.ServerVersionUtils;
import org.springframework.data.aerospike.server.version.ServerVersionSupport;
import org.springframework.data.annotation.Persistent;
import org.springframework.data.mapping.model.FieldNamingStrategy;
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
Expand Down Expand Up @@ -121,11 +121,11 @@ public AerospikeIndexResolver aerospikeIndexResolver() {
return new AerospikeIndexResolver();
}

@Bean(name = "aerospikeServerVersionUtils")
public ServerVersionUtils serverVersionUtils(IAerospikeClient aerospikeClient) {
ServerVersionUtils serverUtils = new ServerVersionUtils(aerospikeClient);
log.debug("Found server version {}", serverUtils.getServerVersion());
return serverUtils;
@Bean(name = "aerospikeServerVersionSupport")
public ServerVersionSupport serverVersionSupport(IAerospikeClient aerospikeClient) {
ServerVersionSupport serverSupport = new ServerVersionSupport(aerospikeClient);
log.debug("Found server version {}", serverSupport.getServerVersion());
return serverSupport;
}

protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.springframework.data.aerospike.query.QueryEngine;
import org.springframework.data.aerospike.query.cache.IndexRefresher;
import org.springframework.data.aerospike.repository.query.Query;
import org.springframework.data.aerospike.utility.ServerVersionUtils;
import org.springframework.data.aerospike.server.version.ServerVersionSupport;
import org.springframework.data.aerospike.utility.Utils;
import org.springframework.data.domain.Sort;
import org.springframework.data.mapping.PropertyHandler;
Expand Down Expand Up @@ -99,9 +99,9 @@ public AerospikeTemplate(IAerospikeClient client,
AerospikeExceptionTranslator exceptionTranslator,
QueryEngine queryEngine,
IndexRefresher indexRefresher,
ServerVersionUtils serverVersionUtils) {
ServerVersionSupport serverVersionSupport) {
super(namespace, converter, mappingContext, exceptionTranslator, client.getWritePolicyDefault(),
serverVersionUtils);
serverVersionSupport);
this.client = client;
this.queryEngine = queryEngine;
this.indexRefresher = indexRefresher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.springframework.data.aerospike.mapping.BasicAerospikePersistentEntity;
import org.springframework.data.aerospike.mapping.Field;
import org.springframework.data.aerospike.repository.query.Query;
import org.springframework.data.aerospike.utility.ServerVersionUtils;
import org.springframework.data.aerospike.server.version.ServerVersionSupport;
import org.springframework.data.domain.Sort;
import org.springframework.data.keyvalue.core.IterableConverter;
import org.springframework.data.mapping.PersistentPropertyAccessor;
Expand Down Expand Up @@ -80,7 +80,7 @@ abstract class BaseAerospikeTemplate {
protected final AerospikeExceptionTranslator exceptionTranslator;
protected final WritePolicy writePolicyDefault;
protected final BatchWritePolicy batchWritePolicyDefault;
protected final ServerVersionUtils serverVersionUtils;
protected final ServerVersionSupport serverVersionSupport;
protected final int SERVER_VERSION_6 = 6;
protected final String SAVE_OPERATION = "save";
protected final String INSERT_OPERATION = "insert";
Expand All @@ -91,7 +91,7 @@ abstract class BaseAerospikeTemplate {
AerospikeMappingContext mappingContext,
AerospikeExceptionTranslator exceptionTranslator,
WritePolicy writePolicyDefault,
ServerVersionUtils serverVersionUtils) {
ServerVersionSupport serverVersionSupport) {
Assert.notNull(writePolicyDefault, "Write policy must not be null!");
Assert.notNull(namespace, "Namespace cannot be null");
Assert.hasLength(namespace, "Namespace cannot be empty");
Expand All @@ -102,7 +102,7 @@ abstract class BaseAerospikeTemplate {
this.mappingContext = mappingContext;
this.writePolicyDefault = writePolicyDefault;
this.batchWritePolicyDefault = getFromWritePolicy(writePolicyDefault);
this.serverVersionUtils = serverVersionUtils;
this.serverVersionSupport = serverVersionSupport;

loggerSetup();
}
Expand Down Expand Up @@ -474,6 +474,6 @@ protected boolean batchRecordFailed(BatchRecord batchRecord) {
}

protected boolean batchWriteSupported() {
return serverVersionUtils.isBatchWriteSupported();
return serverVersionSupport.batchWrite();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.springframework.data.aerospike.query.ReactorQueryEngine;
import org.springframework.data.aerospike.query.cache.ReactorIndexRefresher;
import org.springframework.data.aerospike.repository.query.Query;
import org.springframework.data.aerospike.utility.ServerVersionUtils;
import org.springframework.data.aerospike.server.version.ServerVersionSupport;
import org.springframework.data.aerospike.utility.Utils;
import org.springframework.data.domain.Sort;
import org.springframework.data.keyvalue.core.IterableConverter;
Expand Down Expand Up @@ -94,9 +94,9 @@ public ReactiveAerospikeTemplate(IAerospikeReactorClient reactorClient,
AerospikeMappingContext mappingContext,
AerospikeExceptionTranslator exceptionTranslator,
ReactorQueryEngine queryEngine, ReactorIndexRefresher reactorIndexRefresher,
ServerVersionUtils serverVersionUtils) {
ServerVersionSupport serverVersionSupport) {
super(namespace, converter, mappingContext, exceptionTranslator, reactorClient.getWritePolicyDefault(),
serverVersionUtils);
serverVersionSupport);
Assert.notNull(reactorClient, "Aerospike reactor client must not be null!");
this.reactorClient = reactorClient;
this.reactorQueryEngine = queryEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.aerospike.query.model.IndexesInfo;
import org.springframework.data.aerospike.utility.ServerVersionUtils;
import org.springframework.data.aerospike.server.version.ServerVersionSupport;

import java.util.Arrays;
import java.util.concurrent.Executors;
Expand All @@ -39,19 +39,19 @@ public class IndexRefresher {

private final IAerospikeClient client;
private final InfoPolicy infoPolicy;
private final ServerVersionUtils serverVersionUtils;
private final ServerVersionSupport serverVersionSupport;
private final InternalIndexOperations indexOperations;
private final IndexesCacheUpdater indexesCacheUpdater;
private final ScheduledExecutorService executorService;

public IndexRefresher(IAerospikeClient client, InfoPolicy infoPolicy, InternalIndexOperations indexOperations,
IndexesCacheUpdater indexesCacheUpdater, ServerVersionUtils serverVersionUtils) {
IndexesCacheUpdater indexesCacheUpdater, ServerVersionSupport serverVersionSupport) {
this.client = client;
this.infoPolicy = infoPolicy;
this.indexOperations = indexOperations;
this.indexesCacheUpdater = indexesCacheUpdater;
this.executorService = Executors.newSingleThreadScheduledExecutor();
this.serverVersionUtils = serverVersionUtils;
this.serverVersionSupport = serverVersionSupport;
}

public void scheduleRefreshIndexes(long intervalSeconds) {
Expand All @@ -68,7 +68,7 @@ public void refreshIndexes() {
.map(node -> Info.request(infoPolicy, node, indexOperations.buildGetIndexesCommand()))
.map(response -> {
IndexesInfo indexesInfo = indexOperations.parseIndexesInfo(response);
indexOperations.enrichIndexesWithCardinality(client, indexesInfo.indexes, serverVersionUtils);
indexOperations.enrichIndexesWithCardinality(client, indexesInfo.indexes, serverVersionSupport);
return indexesInfo;
})
.orElse(IndexesInfo.empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.springframework.data.aerospike.query.model.Index;
import org.springframework.data.aerospike.query.model.IndexKey;
import org.springframework.data.aerospike.query.model.IndexesInfo;
import org.springframework.data.aerospike.utility.ServerVersionUtils;
import org.springframework.data.aerospike.server.version.ServerVersionSupport;

import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -69,17 +69,17 @@ public String buildGetIndexesCommand() {
}

public void enrichIndexesWithCardinality(IAerospikeClient client, Map<IndexKey, Index> indexes,
ServerVersionUtils serverVersionUtils) {
ServerVersionSupport serverVersionSupport) {
log.debug("Enriching secondary indexes with cardinality");
indexes.values().forEach(
index -> index.setBinValuesRatio(getIndexBinValuesRatio(client, serverVersionUtils, index.getNamespace(),
index -> index.setBinValuesRatio(getIndexBinValuesRatio(client, serverVersionSupport, index.getNamespace(),
index.getName()))
);
}

public int getIndexBinValuesRatio(IAerospikeClient client, ServerVersionUtils serverVersionUtils,
public int getIndexBinValuesRatio(IAerospikeClient client, ServerVersionSupport serverVersionSupport,
String namespace, String indexName) {
if (serverVersionUtils.isSIndexCardinalitySupported()) {
if (serverVersionSupport.sIndexCardinality()) {
try {
String indexStatData = Info.request(null, client.getCluster().getRandomNode(),
String.format("sindex-stat:ns=%s;indexname=%s", namespace, indexName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.aerospike.query.model.IndexesInfo;
import org.springframework.data.aerospike.utility.ServerVersionUtils;
import org.springframework.data.aerospike.server.version.ServerVersionSupport;
import reactor.core.publisher.Mono;

/**
Expand All @@ -32,18 +32,18 @@ public class ReactorIndexRefresher {

private final IAerospikeReactorClient client;
private final InfoPolicy infoPolicy;
private final ServerVersionUtils serverVersionUtils;
private final ServerVersionSupport serverVersionSupport;
private final InternalIndexOperations indexOperations;
private final IndexesCacheUpdater indexesCacheUpdater;

public ReactorIndexRefresher(IAerospikeReactorClient client, InfoPolicy infoPolicy,
InternalIndexOperations indexOperations, IndexesCacheUpdater indexesCacheUpdater,
ServerVersionUtils serverVersionUtils) {
ServerVersionSupport serverVersionSupport) {
this.client = client;
this.infoPolicy = infoPolicy;
this.indexOperations = indexOperations;
this.indexesCacheUpdater = indexesCacheUpdater;
this.serverVersionUtils = serverVersionUtils;
this.serverVersionSupport = serverVersionSupport;
}

public Mono<Void> refreshIndexes() {
Expand All @@ -52,7 +52,7 @@ public Mono<Void> refreshIndexes() {
.doOnNext(indexInfo -> {
IndexesInfo cache = indexOperations.parseIndexesInfo(indexInfo);
indexOperations.enrichIndexesWithCardinality(client.getAerospikeClient(), cache.indexes,
serverVersionUtils);
serverVersionSupport);
this.indexesCacheUpdater.update(cache);
log.debug("Loaded indexes: {}", cache.indexes);
}).then();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.springframework.data.aerospike.utility;
package org.springframework.data.aerospike.server.version;

import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.Info;

import java.lang.module.ModuleDescriptor;

public class ServerVersionUtils {
public class ServerVersionSupport {

private static final ModuleDescriptor.Version SERVER_VERSION_6_0_0_0 = ModuleDescriptor.Version.parse("6.0.0.0");
private static final ModuleDescriptor.Version SERVER_VERSION_6_1_0_0 = ModuleDescriptor.Version.parse("6.1.0.0");
Expand All @@ -14,7 +14,7 @@ public class ServerVersionUtils {
private final IAerospikeClient client;
private final String serverVersion;

public ServerVersionUtils(IAerospikeClient client) {
public ServerVersionSupport(IAerospikeClient client) {
this.client = client;
this.serverVersion = findServerVersion();
}
Expand All @@ -40,17 +40,17 @@ public boolean isDropCreateBehaviorUpdated() {
/**
* Since Aerospike Server ver. 6.3.0.0 find by POJO is supported.
*/
public boolean isFindByPojoSupported() {
public boolean findByPojo() {
return ModuleDescriptor.Version.parse(getServerVersion())
.compareTo(SERVER_VERSION_6_3_0_0) >= 0;
}

public boolean isBatchWriteSupported() {
public boolean batchWrite() {
return ModuleDescriptor.Version.parse(getServerVersion())
.compareTo(SERVER_VERSION_6_0_0_0) >= 0;
}

public boolean isSIndexCardinalitySupported() {
public boolean sIndexCardinality() {
return ModuleDescriptor.Version.parse(getServerVersion())
.compareTo(SERVER_VERSION_6_1_0_0) >= 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.data.aerospike.query.QueryEngine;
import org.springframework.data.aerospike.query.cache.IndexRefresher;
import org.springframework.data.aerospike.query.cache.IndexesCache;
import org.springframework.data.aerospike.utility.ServerVersionUtils;
import org.springframework.data.aerospike.server.version.ServerVersionSupport;

import java.util.Collection;

Expand All @@ -30,7 +30,7 @@ public abstract class BaseBlockingIntegrationTests extends BaseIntegrationTests
@Autowired
protected QueryEngine queryEngine;
@Autowired
protected ServerVersionUtils serverVersionUtils;
protected ServerVersionSupport serverVersionSupport;
@Autowired
protected IndexesCache indexesCache;
@Autowired
Expand Down
Loading

0 comments on commit 80b023f

Please sign in to comment.