@Override
    public void doAnAction() throws Exception {
      long iteration = numBulkLoads.getAndIncrement();
      Path dir = UTIL.getDataTestDirOnTestFS(String.format("bulkLoad_%08d", iteration));

      // create HFiles for different column families
      FileSystem fs = UTIL.getTestFileSystem();
      byte[] val = Bytes.toBytes(String.format("%010d", iteration));
      Map<byte[], List<Path>> family2Files = new TreeMap<>(Bytes.BYTES_COMPARATOR);
      for (int i = 0; i < NUM_CFS; i++) {
        Path hfile = new Path(dir, family(i));
        byte[] fam = Bytes.toBytes(family(i));
        createHFile(fs, hfile, fam, QUAL, val, 1000);
        family2Files.put(fam, Collections.singletonList(hfile));
      }
      // bulk load HFiles
      BulkLoadHFiles.create(UTIL.getConfiguration()).bulkLoad(tableName, family2Files);
      final Connection conn = UTIL.getConnection();
      // Periodically do compaction to reduce the number of open file handles.
      if (numBulkLoads.get() % 5 == 0) {
        // 5 * 50 = 250 open file handles!
        try (RegionLocator locator = conn.getRegionLocator(tableName)) {
          HRegionLocation loc = locator.getRegionLocation(Bytes.toBytes("aaa"), true);
          conn.getAdmin().compactRegion(loc.getRegion().getRegionName());
          numCompactions.incrementAndGet();
        }
      }
    }
Thread that does full scans of the table looking for any partially completed rows. Each
iteration of this loads 10 hdfs files, which occupies 5 file open file handles. So every 10
iterations (500 file handles) it does a region compaction to reduce the number of open file
handles.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionServerBulkLoad.java