如何在hbase协处理器中停止扫描

qhhrdooz  于 2021-06-08  发布在  Hbase
关注(0)|答案(0)|浏览(258)

我使用的是hbase1.2.6。在hbase表中,我创建了一个索引表,因此可以使用辅助索引检索数据。步骤如下:

1. send a scan opration at client
2. parse the filter and create index table scan filter at coprocessor's prescannernext
3. get result set at at coprocessor's prescannernext
4. then stop scan and return result set

我的代码有问题,我找不到它在哪里。
获取结果集后,扫描操作不会停止。扫描区域之后,浪费了几秒钟。
如何在prescannernext停止扫描操作?
这是我的密码:

public boolean preScannerNext(final ObserverContext<RegionCoprocessorEnvironment> e, final InternalScanner s,
        final List<Result> results, final int limit, final boolean hasMore) throws IOException {
    logger.info("result size: " + results.size());

    if (filterList != null) {
        List<Filter> li = filterList.getFilters();
        SingleColumnValueFilter sf = (SingleColumnValueFilter) li.get(0);
        byte[] family = sf.getFamily();
        byte[] qualifier = sf.getQualifier();
        byte[] startValue = sf.getComparator().getValue();
        byte[] endValue = ((SingleColumnValueFilter) li.get(1)).getComparator().getValue();
        String qualifierStr = new String(qualifier);
        String shortQualifier = qualifierStr.split("_", -1)[0].substring(0, 1).toLowerCase()
                + qualifierStr.split("_", -1)[1].substring(0, 1).toLowerCase();
        byte[] startKey = e.getEnvironment().getRegionInfo().getStartKey();
        if (startKey.length == 0) {
            logger.info("filterList first region");
            startKey = "00".getBytes();
        }
        Scan scan = new Scan();
        String scanPre = new String(startKey) + "|" + shortQualifier + "|";
        byte[] startRow = Bytes.add(scanPre.getBytes(), startValue);
        byte[] stopRow = Bytes.add(scanPre.getBytes(), endValue);
        logger.info("filterList scanPre: " + scanPre);
        logger.info("filterList startRow: " + startRow);
        logger.info("filterList stopRow: " + stopRow);
        scan.setStartRow(startRow);
        scan.setStopRow(stopRow);
        Region region = e.getEnvironment().getRegion();
        RegionScanner rs = region.getScanner(scan);
        info = "region scan";
        results.clear();
        try {
            while (true) {
                List<Cell> cells = new ArrayList<Cell>();
                rs.next(cells);
                if (cells.isEmpty()) {
                    break;
                }
                if (cells.size() > 1) {
                    logger.info("filterList finde index to row: " + cells.size());
                }
                for (Cell cell : cells) {
                    String rk = new String(CellUtil.cloneRow(cell)).split("-", -1)[1];
                    Get get = new Get(rk.getBytes());
                    results.add(region.get(get));
                }
            }
        } finally {
            rs.close();
        }
        e.bypass();
        logger.info("filterList here pass scan");
        logger.info("filterList result size: " + results.size());
        filterList = null;
        return false;
    }

    e.bypass();
    logger.info("at last result size: " + results.size());
    logger.info(hasMore ? "1" : "0");
    return hasMore;
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题