Cassadra上的键的哈希值 [英] Hash value from keys on Cassadra

查看:201
本文介绍了Cassadra上的键的哈希值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Hector开发Cassandra的机制。
我现在需要知道哪些是要查看哪个节点存储的哈希值(查看每个节点的令牌),并直接询问该节点的值。我的理解是,根据Cassandra使用的分区器,值是独立存储从一个分区器到其他。那么,是否所有密钥的哈希值存储在任何表中?如果没有,我怎么能实现一个通用类,一旦我从System Keyspace读取使用Cassandra的分区器,这个类可以是它的一个实例,而不需要修改代码取决于分区器?我需要它调用getToken方法来计算给定的键的哈希值。
谢谢!

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. Thanks!

推荐答案

最后在测试不同的实现之后,我找到了使用下面的代码获得分区器的方法: / p>

Finally after testing different implementations I found the way to get the partitioner using the next code:

            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());
            }

    } 

这篇关于Cassadra上的键的哈希值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆