Source:
public void storeCountersInZooKeeper(boolean allSuperstepsDone) { Set<CustomCounter> additionalCounters = CustomCounters.getCustomCounters(); JSONArray jsonCounters = new JSONArray(); Mapper.Context context = getContext(); Counter counter; for (CustomCounter customCounter : additionalCounters) { String groupName = customCounter.getGroupName(); String counterName = customCounter.getCounterName(); counter = context.getCounter(groupName, counterName); customCounter.setValue(counter.getValue()); jsonCounters.put(Base64.encodeBytes( WritableUtils.writeToByteArray(customCounter))); } Map<String, Set<String>> nettyCounters = NettyClient.getCounterGroupsAndNames(); for (Map.Entry<String, Set<String>> entry : nettyCounters.entrySet()) { String groupName = entry.getKey(); for (String counterName: entry.getValue()) { CustomCounter customCounter = new CustomCounter(groupName, counterName, CustomCounter.AGGREGATION.SUM); counter = context.getCounter(groupName, counterName); customCounter.setValue(counter.getValue()); jsonCounters.put(Base64.encodeBytes( WritableUtils.writeToByteArray(customCounter))); } } long superStep = getSuperstep() + (allSuperstepsDone ? 1 : 0); String finishedWorkerPath = getWorkerFinishedPath( getApplicationAttempt(), superStep, true) + "/" + workerInfo.getHostnameId(); LOG.info("worker finished path: " + finishedWorkerPath); try { getZkExt().createExt(finishedWorkerPath, jsonCounters.toString().getBytes( Charset.defaultCharset()), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, true); } catch (KeeperException.NodeExistsException e) { LOG.warn("finishSuperstep: finished worker path " + finishedWorkerPath + " already exists!"); } catch (KeeperException e) { throw new IllegalStateException("Creating " + finishedWorkerPath + " failed with KeeperException", e); } catch (InterruptedException e) { throw new IllegalStateException("Creating " + finishedWorkerPath + " failed with InterruptedException", e); } }

Target:
public void storeCountersInZooKeeper(boolean allSuperstepsDone) { Set<CustomCounter> additionalCounters = CustomCounters.getCustomCounters(); JSONArray jsonCounters = new JSONArray(); Mapper.Context context = getContext(); Counter counter; for (CustomCounter customCounter : additionalCounters) { String groupName = customCounter.getGroupName(); String counterName = customCounter.getCounterName(); counter = context.getCounter(groupName, counterName); customCounter.setValue(counter.getValue()); jsonCounters.put(Base64.encodeBytes( WritableUtils.writeToByteArray(customCounter))); } Map<String, Set<String>> nettyCounters = NettyClient.getCounterGroupsAndNames(); for (Map.Entry<String, Set<String>> entry : nettyCounters.entrySet()) { String groupName = entry.getKey(); for (String counterName: entry.getValue()) { CustomCounter customCounter = new CustomCounter(groupName, counterName, CustomCounter.Aggregation.SUM); counter = context.getCounter(groupName, counterName); customCounter.setValue(counter.getValue()); jsonCounters.put(Base64.encodeBytes( WritableUtils.writeToByteArray(customCounter))); } } long superStep = getSuperstep() + (allSuperstepsDone ? 1 : 0); String finishedWorkerPath = getWorkerCountersFinishedPath(getApplicationAttempt(), superStep) + "/" + workerInfo.getHostnameId(); LOG.info(String.format("Writing counters to zookeeper for superstep: %d", superStep)); try { getZkExt().createExt(finishedWorkerPath, jsonCounters.toString().getBytes( Charset.defaultCharset()), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, true); } catch (KeeperException.NodeExistsException e) { LOG.warn("storeCountersInZookeeper: finished worker path " + finishedWorkerPath + " already exists!"); } catch (KeeperException e) { LOG.warn("Creating " + finishedWorkerPath + " failed with KeeperException", e); } catch (InterruptedException e) { LOG.warn("Creating " + finishedWorkerPath + " failed with InterruptedException", e); } }