@Override
@Timed("snapshot_reduplicate")
public Snapshot reduplicate(DeduplicatedSnapshot deduplicatedSnapshot) throws CodingException {
LOG.info("Starting reduplication.");
Snapshot snapshot = new Snapshot(deduplicatedSnapshot.getPartialSnapshot());
if (!deduplicatedSnapshot.isSetTaskConfigs()) {
LOG.warning("Got deduplicated snapshot with unset task configs.");
return snapshot;
}
for (DeduplicatedScheduledTask partialTask : deduplicatedSnapshot.getPartialTasks()) {
ScheduledTask scheduledTask = new ScheduledTask(partialTask.getPartialScheduledTask());
int taskConfigId = partialTask.getTaskConfigId();
TaskConfig config;
try {
config = deduplicatedSnapshot.getTaskConfigs().get(taskConfigId);
} catch (IndexOutOfBoundsException e) {
throw new CodingException(
"DeduplicatedScheduledTask referenced invalid task index " + taskConfigId, e);
}
scheduledTask.getAssignedTask().setTask(config);
snapshot.addToTasks(scheduledTask);
}
int numInputTasks = deduplicatedSnapshot.getTaskConfigsSize();
int numOutputTasks = snapshot.getTasksSize();
LOG.info(String.format(
"Finished reduplicating snapshot. Compression ratio: %d/%d = %.2f%%.",
numInputTasks,
numOutputTasks,
100.0 * numInputTasks / numOutputTasks));