2

currently I'm starting a ClusterContext that way:

        AstyanaxContext.Builder builder = new AstyanaxContext.Builder()
            .forCluster(clusterName)
            .forKeyspace(keyspaceName)
            .withAstyanaxConfiguration(getAstyanaxProperties(properties))
            .withConnectionPoolConfiguration(getConnectionPoolProperties(properties))
            .withConnectionPoolMonitor(connectionPoolMonitor);

    clusterContext = builder.buildCluster(ThriftFamilyFactory.getInstance());
    clusterContext.start();
    cluster = clusterContext.getEntity();

Running on a single node dev environment. I'm using a ClusterContext, because I also want to create a keyspace, column families etc.

Do I additionally also need to start up a KeyspaceContext? If so, for what purpose or is a single ClusterContext sufficient for keyspace/column family management and read/write scenarios?

If I do start up a KeyspaceContext, I see, according to the connection pool monitor, 2 hosts added and active. If I shutdown the single Cassandra node, I still see 1 marked as active, which is confusing.

Thanks.

tsteinmaurer
  • 409
  • 2
  • 4

1 Answers1

0

Take a look at netflix's documentation for creating a keyspace. It shows that you create keyspaces using the Keyspace object. A little further down the page there are details about creating a column family too.

You initialise an AstyanaxContext with you then use to get your Keyspace object.

AstyanaxContext<Keyspace> ctx = new AstyanaxContext.Builder()
    .forKeyspace("MyKeyspace")
    // Additional configuration parameters
    .buildKeyspace(ThriftFamilyFactory.getInstance());
ctx.start();
Keyspace keyspace = ctx.getClient();

Then you can create a keyspace (below). As a note, it doesnt matter if the keyspace you are specifying in the forKeyspace(...) function isn't created yet.

// Using simple strategy
keyspace.createKeyspace(ImmutableMap.<String, Object>builder()
    .put("strategy_options", ImmutableMap.<String, Object>builder()
        .put("replication_factor", "1")
        .build())
    .put("strategy_class",     "SimpleStrategy")
        .build()
     );

You can now use and reuse this Keyspace to do as many inserts / deletes / keyspace and column-families creations as you wish.

Lyuben Todorov
  • 13,987
  • 5
  • 50
  • 69
  • What's the difference to a ClusterContext then? – tsteinmaurer Jun 27 '13 at 10:17
  • `Do I additionally also need to start up a KeyspaceContext?` Well... if you want to use the `ClusterContext` and you want to query the db yes you will... difference is one can carry out queries. Also I didn't find ClusterContext anywhere in the usage instructions on the Astyanax wiki, so it's clearly better to go with AstyanaxContext. Couldn't find it [in the documentation](http://netflix.github.io/astyanax/javadoc/allclasses-noframe.html) either so i'm not sure why you are using ClusterContext. – Lyuben Todorov Jun 27 '13 at 11:20