I wrote a small application to run an embedded instance of Cassandra 1.2.
I am trying to create a cluster of 3 built-in instances locally by running 3 instances of this application. Each of them looks at a different cassandra.yaml file system. Each file has:
- same cluster name
- blank initial_token
- unique listening address (all mapped to 127.0.0.1 in my hosts file)
- unique rpc, storage and ssl_storage ports
- same seed (listening address (without port) of the first server)
- unique value -Dcom.sun.management.jmxremote.port passed when the application was launched
When I run the application, everything works fine and has a separate memory in the file system. However, when I use nodetool to test each of them, each of them is in the cluster independently:
C:\Program Files\DataStax Community\apache-cassandra\bin>nodetool -h 127.0.0.1 -p 7197 ring
Starting NodeTool
Datacenter: datacenter1
==========
Replicas: 1
Address Rack Status State Load Owns Token
127.0.0.1 rack1 Up Normal 198,15 KB 100,00% 8219116491729144532
C:\Program Files\DataStax Community\apache-cassandra\bin>nodetool -h 127.0.0.2 -p 7198 ring
Starting NodeTool
Datacenter: datacenter1
==========
Replicas: 1
Address Rack Status State Load Owns Token
127.0.0.2 rack1 Up Normal 152,13 KB 100,00% -3632227916915216562
Blogs and documents on the Internet suggest that this should be enough. Is it possible to merge embedded instances? If so, does anyone know how wrong / insufficient configuration or understanding is?
The code to run embedded instances is below. Hope you can help, thanks.
public class EmbeddedCassandraDemo {
private static final String CONF_PATH_FORMAT = "D:\\embedded_cassandra\\Node%d\\";
private ExecutorService executor = Executors.newSingleThreadExecutor();
private CassandraDaemon cassandraDaemon;
private int nodeNumber;
public EmbeddedCassandraDemo(int nodeNumber) {
this.nodeNumber = nodeNumber;
}
public static void main(String [ ] args) throws InterruptedException, ConnectionException {
new EmbeddedCassandraDemo(Integer.parseInt(args[0])).run();
}
private void run() throws InterruptedException, ConnectionException {
setProperties();
activateDeamon();
}
private void activateDeamon() {
executor.execute( new Runnable(){
@Override
public void run() {
cassandraDaemon = new CassandraDaemon();
cassandraDaemon.activate();
}});
}
private void setProperties() {
System.setProperty("cassandra.config", String.format("file:%scassandra.yaml", String.format(CONF_PATH_FORMAT, nodeNumber)));
System.setProperty("log4j.configuration", String.format("file:%slog4j-server.properties", String.format(CONF_PATH_FORMAT, nodeNumber)));
System.setProperty("cassandra-foreground", "true");
}
}
source
share