简体   繁体   English

Astyanax ClusterContext和/或KeyspaceContext?

[英]Astyanax ClusterContext and/or KeyspaceContext?

currently I'm starting a ClusterContext that way: 当前,我以这种方式启动ClusterContext:

        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. 我正在使用ClusterContext,因为我还想创建一个键空间,列族等。

Do I additionally also need to start up a KeyspaceContext? 我是否还需要启动KeyspaceContext? If so, for what purpose or is a single ClusterContext sufficient for keyspace/column family management and read/write scenarios? 如果是这样,那么对于键空间/列族管理和读/写方案而言,单个ClusterContext出于什么目的就足够了?

If I do start up a KeyspaceContext, I see, according to the connection pool monitor, 2 hosts added and active. 如果我确实启动了KeyspaceContext,则根据连接池监视器,我看到添加了2台并且处于活动状态的主机。 If I shutdown the single Cassandra node, I still see 1 marked as active, which is confusing. 如果关闭单个Cassandra节点,我仍然会看到1标记为活动节点,这令人困惑。

Thanks. 谢谢。

Take a look at netflix's documentation for creating a keyspace . 查看netflix的有关创建键空间的文档。 It shows that you create keyspaces using the Keyspace object. 它表明您使用Keyspace对象创建了键空间。 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对象。

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. 请注意,是否尚未创建在forKeyspace(...)函数中指定的键空间也没关系。

// 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. 现在,您可以使用并重复使用此Keyspace来完成所需的任意插入/删除/ keyspace和列族创建操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM