public static void buildHFiles(FileSystem fs, Path dir, int value) throws IOException { byte[] val = value(value); for (int i = 0; i < NUM_CFS; i++) { Path testIn = new Path(dir, family(i)); TestHRegionServerBulkLoad.createHFile(fs, new Path(testIn, "hfile_" + i), Bytes.toBytes(family(i)), QUAL, val, ROWCOUNT); } }
private ClientServiceCallable<Void> generateFileToLoad( TableName tn, int numFiles, int numRowsPerFile) throws Exception { Connection conn = TEST_UTIL.getConnection(); FileSystem fs = TEST_UTIL.getTestFileSystem(); Configuration conf = TEST_UTIL.getConfiguration(); Path baseDir = new Path(fs.getHomeDirectory(), testName.getMethodName() + "_files"); fs.mkdirs(baseDir); final List<Pair<byte[], String>> famPaths = new ArrayList<Pair<byte[], String>>(); for (int i = 1; i <= numFiles; i++) { Path hfile = new Path(baseDir, "file" + i); TestHRegionServerBulkLoad.createHFile( fs, hfile, Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"), Bytes.toBytes("reject"), numRowsPerFile); famPaths.add(new Pair<>(Bytes.toBytes(SpaceQuotaHelperForTests.F1), hfile.toString())); } // bulk load HFiles Table table = conn.getTable(tn); final String bulkToken = new SecureBulkLoadClient(conf, table).prepareBulkLoad(conn); return new ClientServiceCallable<Void>(conn, tn, Bytes.toBytes("row"), new RpcControllerFactory(conf).newController(), HConstants.PRIORITY_UNSET) { @Override public Void rpcCall() throws Exception { SecureBulkLoadClient secureClient = null; byte[] regionName = getLocation().getRegionInfo().getRegionName(); try (Table table = conn.getTable(getTableName())) { secureClient = new SecureBulkLoadClient(conf, table); secureClient.secureBulkLoadHFiles(getStub(), famPaths, regionName, true, null, bulkToken); } return null; } }; }