String indexTableName;
@Override
public void setUp(State state) throws Exception {
Connector conn = state.getConnector();
Instance instance = state.getInstance();
SortedSet<Text> splits = new TreeSet<Text>();
for (int i = 1; i < 256; i++) {
splits.add(new Text(String.format("%04x", i << 8)));
}
String hostname = InetAddress.getLocalHost().getHostName().replaceAll("[-.]", "_");
String pid = state.getPid();
imageTableName = String.format("img_%s_%s_%d", hostname, pid, System.currentTimeMillis());
state.set("imageTableName", imageTableName);
indexTableName = String.format("img_ndx_%s_%s_%d", hostname, pid, System.currentTimeMillis());
state.set("indexTableName", indexTableName);
try {
conn.tableOperations().create(imageTableName);
conn.tableOperations().addSplits(imageTableName, splits);
log.debug("Created table " + imageTableName + " (id:" + Tables.getNameToIdMap(instance).get(imageTableName) + ")");
} catch (TableExistsException e) {
log.error("Table " + imageTableName + " already exists.");
throw e;
}
try {
conn.tableOperations().create(indexTableName);
log.debug("Created table " + indexTableName + " (id:" + Tables.getNameToIdMap(instance).get(indexTableName) + ")");
} catch (TableExistsException e) {
log.error("Table " + imageTableName + " already exists.");
throw e;
}
Random rand = new Random();
if (rand.nextInt(10) < 5) {
// setup locality groups
Map<String,Set<Text>> groups = getLocalityGroups();
conn.tableOperations().setLocalityGroups(imageTableName, groups);
log.debug("Configured locality groups for " + imageTableName + " groups = " + groups);
}
state.set("numWrites", Long.valueOf(0));
state.set("totalWrites", Long.valueOf(0));