Package com.rackspacecloud.blueflood.rollup

Examples of com.rackspacecloud.blueflood.rollup.Granularity


        return INSTANCE;
    }

    @Override
    public ByteBuffer toByteBuffer(SlotState state) {
        Granularity gran = state.getGranularity();
        String stringRep = new StringBuilder().append(gran == null ? "null" : gran.name())
                .append(",").append(state.getSlot())
                .append(",").append(state == null ? "null" : state.getState().code())
                .toString();

        return StringSerializer.get().toByteBuffer(stringRep);
View Full Code Here


    }

    @Override
    public SlotState fromByteBuffer(ByteBuffer byteBuffer) {
        String stringRep = StringSerializer.get().fromByteBuffer(byteBuffer);
        Granularity g = granularityFromStateCol(stringRep);
        Integer slot = slotFromStateCol(stringRep);
        UpdateStamp.State state = stateFromCode(stateCodeFromStateCol(stringRep));

        return new SlotState(g, slot, state);
    }
View Full Code Here

        Timer.Context ctx = Instrumentation.getWriteTimerContext(CassandraModel.CF_METRICS_STATE);
        try {
            MutationBatch mutationBatch = keyspace.prepareMutationBatch();
            ColumnListMutation<SlotState> mutation = mutationBatch.withRow(CassandraModel.CF_METRICS_STATE, (long)shard);
            for (Map.Entry<Granularity, Map<Integer, UpdateStamp>> granEntry : updates.entrySet()) {
                Granularity g = granEntry.getKey();
                for (Map.Entry<Integer, UpdateStamp> entry : granEntry.getValue().entrySet()) {
                    // granularity,slot,state
                    SlotState slotState = new SlotState(g, entry.getKey(), entry.getValue().getState());
                    mutation.putColumn(slotState, entry.getValue().getTimestamp());
                    /*
 
View Full Code Here

import java.nio.ByteBuffer;

public class SlotStateSerializerTest {
    @Test
    public void testGranularityFromStateCol() {
        Granularity myGranularity = SlotStateSerializer.granularityFromStateCol("metrics_full,1,okay");
        Assert.assertNotNull(myGranularity);
        Assert.assertEquals(myGranularity, Granularity.FULL);

        myGranularity = SlotStateSerializer.granularityFromStateCol("FULL");
        Assert.assertNull(myGranularity);
View Full Code Here

        super(executionContext, singleRollupReadContext, rollupBatchWriter);
    }

    public void run() {
        singleRollupReadContext.getWaitHist().update(System.currentTimeMillis() - startWait);
        Granularity dstGran = singleRollupReadContext.getRollupGranularity();
        Granularity srcGran;
        try {
            singleRollupReadContext.getRollupGranularity().finer();
        } catch (GranularityException ex) {
            executionContext.decrementReadCounter();
            return; // no work to be done.
        }

        if (dstGran.isCoarser(Granularity.MIN_5)) {
            srcGran = Granularity.MIN_5;
        } else {
            srcGran = Granularity.FULL;
        }

        if (log.isDebugEnabled()) {
            log.debug("Executing histogram rollup from {} for {} {}", new Object[] {
                    srcGran.shortName(),
                    singleRollupReadContext.getRange().toString(),
                    singleRollupReadContext.getLocator()});
        }

        Timer.Context timerContext = singleRollupReadContext.getExecuteTimer().time();
        try {
            // Read data and compute rollup
            Points<HistogramRollup> input;
            Rollup rollup = null;
            ColumnFamily<Locator, Long> srcCF;
            ColumnFamily<Locator, Long> dstCF = CassandraModel.getColumnFamily(HistogramRollup.class, dstGran);
            RollupType rollupType = RollupType.fromString((String) rollupTypeCache.get(singleRollupReadContext.getLocator(),
                    MetricMetadata.ROLLUP_TYPE.name().toLowerCase()));

            if (rollupType != RollupType.BF_BASIC) { // Do not compute histogram for statsd metrics.
                executionContext.decrementReadCounter();
                timerContext.stop();
                return;
            }

            if (srcGran == Granularity.MIN_5) {
                srcCF = CassandraModel.CF_METRICS_FULL;
            } else {
                // Coarser histograms are always computed from 5 MIN histograms for error minimization
                srcCF = CassandraModel.CF_METRICS_HIST_5M;
            }

            Timer.Context calcrollupContext = calcTimer.time();
            try {
                input = AstyanaxReader.getInstance().getDataToRoll(
                            HistogramRollup.class,
                            singleRollupReadContext.getLocator(),
                            singleRollupReadContext.getRange(),
                            srcCF);

                // next, compute the rollup.
                rollup =  RollupRunnable.getRollupComputer(RollupType.BF_HISTOGRAMS, srcGran).compute(input);
            } finally {
                calcrollupContext.stop();
            }

            if (rollup != null) {
                rollupBatchWriter.enqueueRollupForWrite(new SingleRollupWriteContext(rollup, singleRollupReadContext, dstCF));
            }
            RollupService.lastRollupTime.set(System.currentTimeMillis());
        } catch (Throwable th) {
            log.error("Histogram rollup failed; Locator : ", singleRollupReadContext.getLocator()
                    + ", Source Granularity: " + srcGran.name());
        } finally {
            executionContext.decrementReadCounter();
            timerContext.stop();
        }
    }
View Full Code Here

    }

    public void setAllCoarserSlotsDirtyForSlot(int shard, Granularity suppliedGranularity,
                                               int suppliedSlot) {
        boolean done = false;
        Granularity coarserGran = suppliedGranularity;
        int coarserSlot = suppliedSlot;

        while (!done) {
            try {
                coarserGran = coarserGran.coarser();
                coarserSlot = coarserGran.slotFromFinerSlot(coarserSlot);
                ConcurrentMap<Integer, UpdateStamp> updateStampsBySlotMap = getSlotStateManager(shard, coarserGran).slotToUpdateStampMap;
                UpdateStamp coarseSlotStamp = updateStampsBySlotMap.get(coarserSlot);

                if (coarseSlotStamp == null) {
                    log.debug("No stamp for coarser slot: " + coarserGran.formatLocatorKey(coarserSlot, shard) +
                        " ; supplied slot: " + suppliedGranularity.formatLocatorKey(suppliedSlot, shard));
                    updateStampsBySlotMap.putIfAbsent(coarserSlot,
                            new UpdateStamp(serverTimeMillisecondTicker.read(), UpdateStamp.State.Active, true));
                    continue;
                }

                UpdateStamp.State coarseSlotState = coarseSlotStamp.getState();
                if (coarseSlotState != UpdateStamp.State.Active) {
                    parentBeforeChild.mark();
                    log.debug("Coarser slot not in active state when finer slot "
                            + suppliedGranularity.formatLocatorKey(suppliedSlot, shard)
                            + " just got rolled up. Marking coarser slot "
                            + coarserGran.formatLocatorKey(coarserSlot, shard) + " dirty");
                    coarseSlotStamp.setState(UpdateStamp.State.Active);
                    coarseSlotStamp.setDirty(true);
                    coarseSlotStamp.setTimestamp(serverTimeMillisecondTicker.read());
                }
            } catch (GranularityException ex) {
View Full Code Here

        log.info("\t~\tCompleted");
    }

    private void rollupCf(final ColumnFamily<Locator, Long> columnFamily) {

        final Granularity gran = Granularity.fromString(columnFamily.getName());
        Function<Row<Long, Locator>, Boolean> rowFunction = new Function<Row<Long, Locator>, Boolean>() {

            @Override
            public Boolean apply(@Nullable Row<Long, Locator> row) {
View Full Code Here

        }

        httpHandler = new HttpRollupsQueryHandler();

        // generate every level of rollup for the raw data
        Granularity g = Granularity.FULL;
        while (g != Granularity.MIN_1440) {
            g = g.coarser();
            for (Locator locator : locators) {
                generateRollups(locator, baseMillis, baseMillis + 86400000, g);
            }
        }
View Full Code Here

    }

    private void testGetRollupByResolution() throws Exception {
        for (Locator locator : locators) {
            for (Resolution resolution : Resolution.values()) {
                Granularity g = Granularity.granularities()[resolution.getValue()];
                testHTTPHandlersGetByResolution(locator, resolution, baseMillis, baseMillis + 86400000,
                        answers.get(locator).get(g));
            }
        }
    }
View Full Code Here

                                      String metric,
                                      long from,
                                      long to,
                                      int points) throws SerializationException {
        rollupsByPointsMeter.mark();
        Granularity g = Granularity.granularityFromPointsInInterval(from, to, points);
        return getRollupByGranularity(tenantId, metric, from, to, g);
    }
View Full Code Here

TOP

Related Classes of com.rackspacecloud.blueflood.rollup.Granularity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.