public void run() {
// done waiting.
singleRollupReadContext.getWaitHist().update(System.currentTimeMillis() - startWait);
Granularity srcGran;
try {
srcGran = singleRollupReadContext.getRollupGranularity().finer();
} catch (GranularityException ex) {
executionContext.decrementReadCounter();
return; // no work to be done.
}
if (log.isDebugEnabled()) {
log.trace("Executing rollup from {} for {} {}", new Object[] {
srcGran.shortName(),
singleRollupReadContext.getRange().toString(),
singleRollupReadContext.getLocator()});
}
// start timing this action.
Timer.Context timerContext = singleRollupReadContext.getExecuteTimer().time();
try {
Timer.Context calcrollupContext = calcTimer.time();
// Read data and compute rollup
Points input;
Rollup rollup = null;
RollupType rollupType = RollupType.fromString((String) rollupTypeCache.get(
singleRollupReadContext.getLocator(), MetricMetadata.ROLLUP_TYPE.name().toLowerCase()));
Class<? extends Rollup> rollupClass = RollupType.classOf(rollupType, srcGran.coarser());
ColumnFamily<Locator, Long> srcCF = CassandraModel.getColumnFamily(rollupClass, srcGran);
ColumnFamily<Locator, Long> dstCF = CassandraModel.getColumnFamily(rollupClass, srcGran.coarser());
try {
// first, get the points.
input = AstyanaxReader.getInstance().getDataToRoll(rollupClass,
singleRollupReadContext.getLocator(), singleRollupReadContext.getRange(), srcCF);
if (input.isEmpty()) {
noPointsToCalculateRollup.mark();
return;
}
// next, compute the rollup.
rollup = RollupRunnable.getRollupComputer(rollupType, srcGran).compute(input);
} finally {
calcrollupContext.stop();
}
// now enqueue the new rollup for writing.
rollupBatchWriter.enqueueRollupForWrite(new SingleRollupWriteContext(rollup, singleRollupReadContext, dstCF));
RollupService.lastRollupTime.set(System.currentTimeMillis());
//Emit a rollup event to eventemitter
RollupEventEmitter.getInstance().emit(RollupEventEmitter.ROLLUP_EVENT_NAME,
new RollupEvent(singleRollupReadContext.getLocator(), rollup,
AstyanaxReader.getUnitString(singleRollupReadContext.getLocator()),
singleRollupReadContext.getRollupGranularity().name(),
singleRollupReadContext.getRange().getStart()));
} catch (Exception e) {
log.error("Rollup failed; Locator: {}, Source Granularity: {}, For period: {}", new Object[] {
singleRollupReadContext.getLocator(),
singleRollupReadContext.getRange().toString(),
srcGran.name(),
e});
} finally {
executionContext.decrementReadCounter();
timerContext.stop();
}