in src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/BulkImport.java [95:141]
public void visit(State state, RandWalkEnv env, Properties props) throws Exception {
AccumuloClient client = env.getAccumuloClient();
String tableName = state.getRandomTableName();
Random rand = state.getRandom();
FileSystem fs = FileSystem.get(env.getHadoopConfiguration());
String bulkDir = env.getHdfsRoot() + "/tmp/concurrent_bulk/b_"
+ String.format("%016x", rand.nextLong() & 0x7fffffffffffffffL);
fs.mkdirs(new Path(bulkDir));
fs.mkdirs(new Path(bulkDir + "_f"));
try {
try (BatchWriter bw = new RFileBatchWriter(env.getHadoopConfiguration(), fs,
bulkDir + "/file01.rf")) {
TreeSet<Long> rows = new TreeSet<>();
int numRows = rand.nextInt(100000);
for (int i = 0; i < numRows; i++) {
rows.add(rand.nextLong() & 0x7fffffffffffffffL);
}
for (Long row : rows) {
Mutation m = new Mutation(String.format("%016x", row));
long val = rand.nextLong() & 0x7fffffffffffffffL;
for (int j = 0; j < 10; j++) {
m.put("cf", "cq" + j, new Value(String.format("%016x", val).getBytes(UTF_8)));
}
bw.addMutation(m);
}
}
client.tableOperations().importDirectory(bulkDir).to(tableName).tableTime(rand.nextBoolean())
.load();
log.debug("BulkImported to " + tableName);
} catch (TableNotFoundException e) {
log.debug("BulkImport " + tableName + " failed, doesnt exist");
} catch (TableOfflineException toe) {
log.debug("BulkImport " + tableName + " failed, offline");
} finally {
fs.delete(new Path(bulkDir), true);
fs.delete(new Path(bulkDir + "_f"), true);
}
}