来自Cassandra上键的哈希值 [英] Hash value from keys on Cassandra

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

问题描述

我正在使用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.

推荐答案

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

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

    } 

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

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