Skip to content

Commit

Permalink
add scheduled reading of server version
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Dec 18, 2023
1 parent 6c65c54 commit c8ff954
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public AerospikeIndexResolver aerospikeIndexResolver() {
@Bean(name = "aerospikeServerVersionSupport")
public ServerVersionSupport serverVersionSupport(IAerospikeClient aerospikeClient) {
ServerVersionSupport serverSupport = new ServerVersionSupport(aerospikeClient);
log.debug("Found server version {}", serverSupport.getServerVersion());
serverSupport.scheduleServerVersionRefresh();
return serverSupport;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,45 @@

import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.Info;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.aerospike.query.cache.IndexRefresher;

import java.lang.module.ModuleDescriptor;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ServerVersionSupport {

private final Logger log = LoggerFactory.getLogger(IndexRefresher.class);
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");
private static final ModuleDescriptor.Version SERVER_VERSION_6_1_0_1 = ModuleDescriptor.Version.parse("6.1.0.1");
private static final ModuleDescriptor.Version SERVER_VERSION_6_3_0_0 = ModuleDescriptor.Version.parse("6.3.0.0");
private final IAerospikeClient client;
@Getter
private final String serverVersion;
private final ScheduledExecutorService executorService;
private final long intervalSeconds = 1800;

public ServerVersionSupport(IAerospikeClient client) {
this.client = client;
this.serverVersion = findServerVersion();
this.executorService = Executors.newSingleThreadScheduledExecutor();
}

private String findServerVersion() {
String versionString = Info.request(client.getCluster().getRandomNode(), "version");
return versionString.substring(versionString.lastIndexOf(' ') + 1);
public void scheduleServerVersionRefresh() {
executorService.scheduleWithFixedDelay(this::findServerVersion, intervalSeconds, intervalSeconds,
TimeUnit.SECONDS);
}

public String getServerVersion() {
return serverVersion;
private String findServerVersion() {
String versionString = Info.request(client.getCluster().getRandomNode(), "version");
versionString = versionString.substring(versionString.lastIndexOf(' ') + 1);
log.debug("Found server version {}", versionString);
return versionString;
}

/**
Expand Down

0 comments on commit c8ff954

Please sign in to comment.