public void visit()

in src/main/java/org/apache/accumulo/testing/randomwalk/multitable/Write.java [43:101]


  public void visit(State state, RandWalkEnv env, Properties props) throws Exception {

    @SuppressWarnings("unchecked")
    List<String> tables = (List<String>) state.get("tableList");

    if (tables.isEmpty()) {
      log.trace("No tables to ingest into");
      return;
    }

    String tableName = tables.get(env.getRandom().nextInt(tables.size()));

    BatchWriter bw;
    try {
      bw = env.getMultiTableBatchWriter().getBatchWriter(tableName);
    } catch (TableOfflineException e) {
      log.debug("Table " + tableName + " is offline");
      return;
    } catch (TableNotFoundException e) {
      log.debug("Table " + tableName + " not found");
      tables.remove(tableName);
      return;
    }

    Text meta = new Text("meta");
    String uuid = UUID.randomUUID().toString();

    Mutation m = new Mutation(new Text(uuid));

    // create a fake payload between 4KB and 16KB
    int numBytes = env.getRandom().nextInt(12000) + 4000;
    byte[] payloadBytes = new byte[numBytes];
    env.getRandom().nextBytes(payloadBytes);
    m.put(meta, new Text("payload"), new Value(payloadBytes));

    // store size
    m.put(meta, new Text("size"), new Value(String.format("%d", numBytes).getBytes(UTF_8)));

    // store hash
    MessageDigest alg = MessageDigest.getInstance("SHA-1");
    alg.update(payloadBytes);
    m.put(meta, new Text("sha1"), new Value(alg.digest()));

    try {
      // add mutation
      bw.addMutation(m);
      state.set("numWrites", state.getLong("numWrites") + 1);
    } catch (TableOfflineException e) {
      log.debug("BatchWrite " + tableName + " failed, offline");
    } catch (MutationsRejectedException mre) {
      if (mre.getCause() instanceof TableDeletedException) {
        log.debug("BatchWrite " + tableName + " failed, table deleted");
        tables.remove(tableName);
      } else if (mre.getCause() instanceof TableOfflineException)
        log.debug("BatchWrite " + tableName + " failed, offline");
      else
        throw mre;
    }
  }