3

I'm using official Aerospike Docker image to run it with Testcontainers. I can specify a default namespace as the environment variable. Unfortunately, I cannot create 2 namespaces on container start.

Is there any approach to achieve it?

Semyon Kirekov
  • 1,237
  • 8
  • 20

1 Answers1

5

One cannot declare multiple namespaces with environment variable. But you can pass custom Aerospike configuration file. Take a look at the example below:

static final GenericContainer<?> aerospike =
            new GenericContainer<>(DockerImageName.parse("aerospike/aerospike-server:5.6.0.4"))
                .withClasspathResourceMapping("aerospike.conf", "/opt/aerospike/etc/aerospike.conf", READ_ONLY)
                .withExposedPorts(3000, 3001, 3002)
                .withCommand("--config-file /opt/aerospike/etc/aerospike.conf")
                .waitingFor(Wait.forLogMessage(".*migrations: complete.*", 2));

The withClasspathResourceMapping method copies the aerospike.conf file into container. The file is placed in the src/test/resources directory. Here is an example of Aerospike configuration with two namespaces.

# This stanza must come first.
service {
  user root
  group root
  paxos-single-replica-limit 1 # Number of nodes where the replica count is automatically reduced to 1.
  pidfile /var/run/aerospike/asd.pid
  proto-fd-max 15000
}

logging {
  # Log file must be an absolute path.
  file /dev/null {
    context any info
  }

  # Send log messages to stdout
  console {
    context any info
  }
}

network {
  service {
    address any
    port 3000
  }

  heartbeat {

    address any
    mode mesh
    port 3002

    interval 150
    timeout 10
  }

  fabric {
    address any
    port 3001
  }

}

namespace product-namespace {
  replication-factor 1
  memory-size 1G
  default-ttl 30d
  nsup-period 120

  storage-engine device {
    file /opt/aerospike/data/product_namespace.dat
    filesize 4G
    data-in-memory true # Store data in memory in addition to file.
  }
}

namespace client-namespace {
  replication-factor 1
  memory-size 1G
  default-ttl 30d
  nsup-period 120

  storage-engine device {
    file /opt/aerospike/data/client_namespace.dat
    filesize 4G
    data-in-memory true # Store data in memory in addition to file.
  }
}

In this case, product-namespace and client-namespace will be created.

Semyon Kirekov
  • 1,237
  • 8
  • 20