Skip to content

Commit

Permalink
feat: switch off stop-writes-sys-memory-pct metric for the Aerospike …
Browse files Browse the repository at this point in the history
…Enterprise
  • Loading branch information
Volchkov Andrey authored and Fameing committed Feb 15, 2024
1 parent ad82cb2 commit d24a053
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.playtika.testcontainer.aerospike.AerospikeProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.testcontainers.containers.Container;
import org.testcontainers.containers.GenericContainer;

import java.io.IOException;
Expand All @@ -21,20 +20,23 @@ public void configure(GenericContainer<?> aerospikeContainer) throws IOException
"Pay attention to license details: https://github.com/aerospike/aerospike-server.docker/blob/master/enterprise/ENTERPRISE_LICENSE");
}

setupDisallowExpunge(aerospikeContainer);
}

private void setupDisallowExpunge(GenericContainer<?> aerospikeContainer) throws IOException, InterruptedException {
if (!enterpriseProperties.isDurableDeletes()) {
return;
}
log.info("Setting up 'disallow-expunge' to true...");
String namespace = aerospikeProperties.getNamespace();
Container.ExecResult result = aerospikeContainer.execInContainer("asadm", "-e",
String.format("enable; manage config namespace %s param disallow-expunge to true", namespace));
if (result.getExitCode() != 0) {
throw new IllegalStateException("Failed to set up 'disallow-expunge' to true: " + result.getStderr());
AsadmCommandExecutor asadmCommandExecutor = new AsadmCommandExecutor(aerospikeContainer);

/*
By default, the value of this metric is 90%, we set it to 100% to prevent stopping writes for the Aerospike
Enterprise container during high consumption of system memory. For the Aerospike Community Edition, this metric is not used.
Documentation: https://aerospike.com/docs/server/reference/configuration#stop-writes-sys-memory-pct
*/
log.info("Switching off 'stop-writes-sys-memory-pct'... ");
asadmCommandExecutor.execute(String.format("manage config namespace %s param stop-writes-sys-memory-pct to 100", namespace));
log.info("Success switching off 'stop-writes-sys-memory-pct'");

if (enterpriseProperties.isDurableDeletes()) {
log.info("Setting up 'disallow-expunge' to true...");
asadmCommandExecutor.execute(String.format("manage config namespace %s param disallow-expunge to true", namespace));
log.info("Success setting up 'disallow-expunge' to true");
}
log.info("Success setting up 'disallow-expunge' to true");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.playtika.testcontainers.aerospike.enterprise;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.testcontainers.containers.Container;
import org.testcontainers.containers.GenericContainer;

import java.io.IOException;

@RequiredArgsConstructor
@Slf4j
public class AsadmCommandExecutor {

private final GenericContainer<?> aerospikeContainer;

public void execute(String command) throws IOException, InterruptedException {
Container.ExecResult result = aerospikeContainer.execInContainer("asadm", "--enable", "-e", command);
logStdout(result);
if (result.getExitCode() != 0 || isBadResponse(result)) {
throw new IllegalStateException(String.format("Failed to execute \"asadm --enable -e '%s'\":\nstdout:\n%s\nstderr:\n%s",
command, result.getStdout(), result.getStderr()));
}
}

private boolean isBadResponse(Container.ExecResult execResult) {
String stdout = execResult.getStdout();
/*
Example of the stdout without error:
~Set Namespace Param stop-writes-sys-memory-pct to 100~
Node|Response
728bb242e58c:3000|ok
Number of rows: 1
*/
return !stdout.contains("|ok");
}

private static void logStdout(Container.ExecResult result) {
log.debug("Aerospike asadm util stdout: \n{}\n{}", result.getStdout(), result.getStderr());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.playtika.testcontainers.aerospike.enterprise;

import com.playtika.testcontainer.aerospike.AerospikeProperties;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.testcontainers.containers.GenericContainer;

import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

public class AsadmCommandExecutorTest extends BaseEnterpriseAerospikeTest {

@Autowired
@Qualifier(AerospikeProperties.BEAN_NAME_AEROSPIKE)
private GenericContainer<?> aerospikeContainer;

@Test
public void shouldFailCommandExecutionWithBadOption() {
AsadmCommandExecutor commandExecutor = new AsadmCommandExecutor(aerospikeContainer);
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> commandExecutor.execute("-tttttt"));
}

@Test
public void shouldFailCommandExecutionWithBadCommand() {
AsadmCommandExecutor commandExecutor = new AsadmCommandExecutor(aerospikeContainer);
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> commandExecutor.execute("manage config namespace NAMESPACE_NOT_EXISTS param disallow-expunge to true"));
}
}

0 comments on commit d24a053

Please sign in to comment.