*
* @param superstep Superstep to aggregate on
* @return Global statistics aggregated on all worker statistics
*/
private GlobalStats aggregateWorkerStats(long superstep) {
ImmutableClassesGiraphConfiguration conf = getConfiguration();
Class<? extends PartitionStats> partitionStatsClass =
masterGraphPartitioner.createPartitionStats().getClass();
GlobalStats globalStats = new GlobalStats();
// Get the stats from the all the worker selected nodes
String workerFinishedPath =
getWorkerFinishedPath(getApplicationAttempt(), superstep);
List<String> workerFinishedPathList = null;
try {
workerFinishedPathList =
getZkExt().getChildrenExt(
workerFinishedPath, false, false, true);
} catch (KeeperException e) {
throw new IllegalStateException(
"aggregateWorkerStats: KeeperException", e);
} catch (InterruptedException e) {
throw new IllegalStateException(
"aggregateWorkerStats: InterruptedException", e);
}
AggregatedMetrics aggregatedMetrics = new AggregatedMetrics();
allPartitionStatsList.clear();
for (String finishedPath : workerFinishedPathList) {
String hostnamePartitionId = FilenameUtils.getName(finishedPath);
JSONObject workerFinishedInfoObj = null;
try {
byte [] zkData =
getZkExt().getData(finishedPath, false, null);
workerFinishedInfoObj = new JSONObject(new String(zkData));
List<PartitionStats> statsList =
WritableUtils.readListFieldsFromByteArray(
Base64.decode(workerFinishedInfoObj.getString(
JSONOBJ_PARTITION_STATS_KEY)),
partitionStatsClass,
conf);
for (PartitionStats partitionStats : statsList) {
globalStats.addPartitionStats(partitionStats);
allPartitionStatsList.add(partitionStats);
}
globalStats.addMessageCount(
workerFinishedInfoObj.getLong(
JSONOBJ_NUM_MESSAGES_KEY));
if (conf.metricsEnabled() &&
workerFinishedInfoObj.has(JSONOBJ_METRICS_KEY)) {
WorkerSuperstepMetrics workerMetrics = new WorkerSuperstepMetrics();
WritableUtils.readFieldsFromByteArray(
Base64.decode(
workerFinishedInfoObj.getString(
JSONOBJ_METRICS_KEY)),
workerMetrics);
aggregatedMetrics.add(workerMetrics, hostnamePartitionId);
}
} catch (JSONException e) {
throw new IllegalStateException(
"aggregateWorkerStats: JSONException", e);
} catch (KeeperException e) {
throw new IllegalStateException(
"aggregateWorkerStats: KeeperException", e);
} catch (InterruptedException e) {
throw new IllegalStateException(
"aggregateWorkerStats: InterruptedException", e);
} catch (IOException e) {
throw new IllegalStateException(
"aggregateWorkerStats: IOException", e);
}
}
if (conf.metricsEnabled()) {
aggregatedMetrics.print(superstep, System.err);
}
if (LOG.isInfoEnabled()) {
LOG.info("aggregateWorkerStats: Aggregation found " + globalStats +