private int count(final Table countTable, final int flushIndex, boolean concurrent)
    throws Exception {
    LOG.info("Taking out counting scan");
    Scan scan = new Scan();
    for (byte[] qualifier : EXPLICIT_COLS) {
      scan.addColumn(HConstants.CATALOG_FAMILY, qualifier);
    }
    ResultScanner s = countTable.getScanner(scan);
    int count = 0;
    boolean justFlushed = false;
    while (s.next() != null) {
      if (justFlushed) {
        LOG.info("after next() just after next flush");
        justFlushed = false;
      }
      count++;
      if (flushIndex == count) {
        LOG.info("Starting flush at flush index " + flushIndex);
        Thread t = new Thread() {
          @Override
          public void run() {
            try {
              region.flush(true);
              LOG.info("Finishing flush");
            } catch (IOException e) {
              LOG.info("Failed flush cache");
            }
          }
        };
        t.start();
        if (!concurrent) {
          // sync flush
          t.join();
        }
        LOG.info("Continuing on after kicking off background flush");
        justFlushed = true;
      }
    }
    s.close();
    LOG.info("Found " + count + " items");
    return count;
  }
Count table.
@param hri        Region
@param flushIndex At what row we start the flush.
@param concurrent if the flush should be concurrent or sync.
@return Count of rows found.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestScanner.java