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

switch off stop-writes-sys-memory-pct metric for the Aerospike Enterprise #1762

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 @@ -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"));
}
}