0

I'm developing a mechanism for Cassandra using Hector. What I need at this moment is to know which are the hash values of the keys to look at which node is stored (looking at the tokens of each one), and ask directly this node for the value. What I understood is that depending on the partitioner Cassandra uses, the values are stored independently from one partitioner to other. So, are the hash values of all keys stored in any table? In case not, how could I implement a generic class that once I read from System Keyspace the partitioner that is using Cassandra this class could be an instance of it without the necessity of modifying the code depending on the partitioner? I would need it to call the getToken method to calculate the hash value for a given key.

4

4 回答 4

2

Hector 的 CqlQuery 支持很差,而且有问题。您应该改用本机 Java CQL 驱动程序:https ://github.com/datastax/java-driver

于 2013-11-14T15:45:36.557 回答
1

您可以只重用 Cassandra 中定义的分区器:https ://github.com/apache/cassandra/tree/trunk/src/java/org/apache/cassandra/dht ,然后使用您可以进行路由的令牌范围。

于 2013-11-13T07:25:09.060 回答
1

CQL 驱动程序提供开箱即用的令牌感知路由。我会使用它而不是尝试在 Hector 中重新发明轮子,特别是因为 Hector 使用旧版 Thrift API 而不是CQL

于 2013-11-14T15:50:22.513 回答
0

最后在测试了不同的实现之后,我找到了使用下一个代码获取分区器的方法:

            CqlQuery<String, String, String> cqlQuery = new CqlQuery<String, String, String>(
            ksp, StringSerializer.get(), StringSerializer.get(),   StringSerializer.get());
            cqlQuery.setQuery("select partitioner from local");
            QueryResult<CqlRows<String, String, String>> result = cqlQuery.execute();
            CqlRows rows = result.get();
            for (int i = 0; i < rows.getCount(); i++) {
                RowImpl<String, String, String> row = (RowImpl<String, String, String>) rows
                .getList().get(i);
                List<HColumn<String, String>> column = row.getColumnSlice().getColumns();
                for (HColumn<String , String> c: column) {
                    System.out.println(c.getValue());
            }

    } 
于 2013-11-15T13:05:16.537 回答