TransactionTrace xact = (TransactionTrace)element;
if (!xact.getCatalogItemName().equals("neworder")) continue;
int w_id = ((Long)xact.getParam(0)).intValue();
warehouse_ids.add(w_id);
if (!histograms.containsKey(w_id)) {
histograms.put(w_id, new ObjectHistogram());
}
}
} // FOR
int num_warehouses = warehouse_ids.size();
System.out.println("Num of Warehouses: " + num_warehouses);
assert(num_warehouses <= 40);
int changed_cnt = 0;
int total = 0;
Random rand = new Random();
for (AbstractTraceElement<?> element : args.workload) {
if (element instanceof TransactionTrace) {
TransactionTrace xact = (TransactionTrace)element;
if (!xact.getCatalogItemName().equals("neworder")) continue;
int param_idx = 5;
total++;
Object ol_supply_ids[] = xact.getParam(param_idx);
int orig_w_id = ((Long)xact.getParam(0)).intValue();
RandomDistribution.DiscreteRNG rng = distributions.get(orig_w_id);
if (rng == null) {
LOG.error("Original Warehouse Id: " + orig_w_id);
LOG.error(distributions);
System.exit(0);
}
//
// Let there be some probability that we are going to go to another warehouse
// to grab our data. For now we'll have all the remote items be in the same
// warehouse
//
Integer remote_w_id = null;
int updated_items = 0;
if (rand.nextInt(100) <= OL_SUPPLY_REMOTE) {
remote_w_id = rng.nextInt();
if (remote_w_id >= num_warehouses) remote_w_id = (remote_w_id % num_warehouses) + 1;
histograms.get(orig_w_id).put(remote_w_id);
} else {
histograms.get(orig_w_id).put(orig_w_id);
}
for (int i = 0; i < ol_supply_ids.length; i++) {
if (remote_w_id != null && rand.nextInt(100) <= OL_SUPPLY_REMOTE_ITEM) {
ol_supply_ids[i] = remote_w_id;
updated_items++;
int getStockInfo_cnt = 0;
int updateStock_cnt = 0;
int createOrderLine_cnt = 0;
for (QueryTrace query : xact.getQueries()) {
if (query.getCatalogItemName().startsWith("getStockInfo")) {
if (getStockInfo_cnt++ == i) query.setParam(1, ol_supply_ids[i]);
} else if (query.getCatalogItemName().equals("updateStock")) {
if (updateStock_cnt++ == i) query.setParam(5, ol_supply_ids[i]);
} else if (query.getCatalogItemName().equals("createOrderLine")) {
if (createOrderLine_cnt++ == i) query.setParam(5, ol_supply_ids[i]);
}
} // FOR
//System.out.println(xact.debug(catalog_db));
//System.exit(1);
//
// If we're not changing it, at least make sure it's the same value as the procedure param
//
} else {
ol_supply_ids[i] = orig_w_id;
}
} // FOR
xact.setParam(param_idx, ol_supply_ids);
if (updated_items > 0) changed_cnt++;
}
} // FOR
LOG.info("Updated " + changed_cnt + "/" + total + " transactions");
StringBuilder buffer = new StringBuilder();
buffer.append("Warehouse Histograms:\n");
for (Integer w_id : histograms.keySet()) {
ObjectHistogram hist = histograms.get(w_id);
buffer.append("Partition: " + w_id + " [" + distributions.get(w_id).getMin() + "]\n");
buffer.append(hist).append("\n");
hist.save(new File("histograms/" + w_id + ".hist"));
} // FOR
LOG.info(buffer.toString());
return;
}