使用hbase作为键值存储,需要使用java提取值

时间:2015-03-13 01:42:33

标签: java hbase key-value-coding key-value-store

我正在使用Hbase作为键值存储,其中我们有一个具有单个值的列族。 java过滤器在不到一秒的时间内获取行,但在尝试检索该值时需要15秒。如果有人可以调查并给我指针,那将非常有帮助。这是代码: -

        Scan scan1 = new Scan();
        scan1.addColumn(Bytes.toBytes("column_family"), Bytes.toBytes("column_name"));
        Filter filter1 = new RowFilter(CompareFilter.CompareOp.EQUAL,
          new BinaryComparator(Bytes.toBytes("hashvalue")));
        scan1.setFilter(filter1);
        long startTime = System.nanoTime();
        ResultScanner scanner1 = table.getScanner(scan1);
        System.out.println(scanner1.next().getColumnLatestCell(Bytes.toBytes("column_family"), Bytes.toBytes("column_name")));            
        long endTime = System.nanoTime();
        double seconds = (double)(endTime - startTime) / 1000000000.0;
        System.out.println("Scan with row key using scan: " + seconds);            
        scanner1.close();

1 个答案:

答案 0 :(得分:1)

如果您知道密钥的确切值,则无需进行扫描,而是可以执行Get,这应该是超级高效的。

Result result = table.get(Bytes.toBytes("hashvalue")) 

触发next时花费太长时间的原因是因为对next的每次通话都是RPC来电(HBase}本身,{可以使用setCachingHBase的单次旅行中获得一定数量的行。