Examples of MutationBatch


Examples of com.netflix.astyanax.MutationBatch

    @Override
    public void deleteRow(String key) throws PaasException {
        invariant();
       
        MutationBatch mb = keyspace.prepareMutationBatch();
        mb.withRow(this.columnFamily, serializers.keyAsByteBuffer(key)).delete();
       
        try {
            mb.execute();
        } catch (ConnectionException e) {
            throw new PaasException(
                    String.format("Failed to update row '%s' in column family '%s.%s'" ,
                                  key, this.keyspace.getKeyspaceName(), this.columnFamily.getName()),
                    e);
View Full Code Here

Examples of com.netflix.astyanax.MutationBatch

    public void updateRow(String key, RowData rowData) throws PaasException {
        LOG.info("Update row: " + rowData.toString());
        invariant();
       
        MutationBatch mb = keyspace.prepareMutationBatch();
        if (rowData.hasSchemalessRows()) {
            ColumnListMutation<ByteBuffer> mbRow = mb.withRow(this.columnFamily, serializers.keyAsByteBuffer(key));
            for (Entry<String, Map<String, String>> row : rowData.getSrows().getRows().entrySet()) {
                for (Entry<String, String> column : row.getValue().entrySet()) {
                    mbRow.putColumn(serializers.columnAsByteBuffer(column.getKey())
                                    serializers.valueAsByteBuffer(column.getKey(), column.getValue()));
                }
            }
        }
       
        try {
            mb.execute();
        } catch (ConnectionException e) {
            throw new PaasException(
                    String.format("Failed to update row '%s' in column family '%s.%s'" ,
                                  key, this.keyspace.getKeyspaceName(), this.columnFamily.getName()),
                    e);
View Full Code Here

Examples of com.netflix.astyanax.MutationBatch

    @Override
    public void updateColumn(String key, String column, String value) throws NotFoundException, PaasException {
        LOG.info("Update row");
        invariant();
       
        MutationBatch mb = keyspace.prepareMutationBatch();
        ColumnListMutation<ByteBuffer> mbRow = mb.withRow(this.columnFamily, serializers.keyAsByteBuffer(key));
        mbRow.putColumn(serializers.columnAsByteBuffer(column)
                        serializers.valueAsByteBuffer(column, value));
       
        try {
            mb.execute();
        } catch (ConnectionException e) {
            throw new PaasException(
                    String.format("Failed to update row '%s' in column family '%s.%s'" ,
                                  key, this.keyspace.getKeyspaceName(), this.columnFamily.getName()),
                    e);
View Full Code Here

Examples of com.netflix.astyanax.MutationBatch

    @Override
    public void deleteColumn(String key, String column) throws PaasException {
        LOG.info("Update row");
        invariant();
       
        MutationBatch mb = keyspace.prepareMutationBatch();
        ColumnListMutation<ByteBuffer> mbRow = mb.withRow(this.columnFamily, serializers.keyAsByteBuffer(key));
        mbRow.deleteColumn(serializers.columnAsByteBuffer(column));
        try {
            mb.execute();
        } catch (ConnectionException e) {
            throw new PaasException(
                    String.format("Failed to update row '%s' in column family '%s.%s'" ,
                                  key, this.keyspace.getKeyspaceName(), this.columnFamily.getName()),
                    e);
View Full Code Here

Examples of com.netflix.astyanax.MutationBatch

    // single column updates).
    public void insertFull(Collection<Metric> metrics) throws ConnectionException {
        Timer.Context ctx = Instrumentation.getWriteTimerContext(CassandraModel.CF_METRICS_FULL);

        try {
            MutationBatch mutationBatch = keyspace.prepareMutationBatch();
            for (Metric metric: metrics) {
                final Locator locator = metric.getLocator();

                final boolean isString = metric.isString();
                final boolean isBoolean = metric.isBoolean();

                if (!shouldPersist(metric)) {
                    log.trace("Metric shouldn't be persisted, skipping insert", metric.getLocator().toString());
                    continue;
                }

                // key = shard
                // col = locator (acct + entity + check + dimension.metric)
                // value = <nothing>
                // do not do it for string or boolean metrics though.
                if (!AstyanaxWriter.isLocatorCurrent(locator)) {
                    if (!isString && !isBoolean && mutationBatch != null)
                        insertLocator(locator, mutationBatch);
                    AstyanaxWriter.setLocatorCurrent(locator);
                }

                insertMetric(metric, mutationBatch);
                Instrumentation.markFullResMetricWritten();
            }
            // insert it
            try {
                mutationBatch.execute();
            } catch (ConnectionException e) {
                Instrumentation.markWriteError(e);
                log.error("Connection exception during insertFull", e);
                throw e;
            }
View Full Code Here

Examples of com.netflix.astyanax.MutationBatch

    }

    public void writeMetadata(Table<Locator, String, String> metaTable) throws ConnectionException {
        ColumnFamily cf = CassandraModel.CF_METRIC_METADATA;
        Timer.Context ctx = Instrumentation.getBatchWriteTimerContext(cf);
        MutationBatch batch = keyspace.prepareMutationBatch();

        try {
            for (Locator locator : metaTable.rowKeySet()) {
                Map<String, String> metaRow = metaTable.row(locator);
                ColumnListMutation<String> mutation = batch.withRow(cf, locator);

                for (Map.Entry<String, String> meta : metaRow.entrySet()) {
                    mutation.putColumn(meta.getKey(), meta.getValue(), StringMetadataSerializer.get(), null);
                }
            }
            try {
                batch.execute();
            } catch (ConnectionException e) {
                Instrumentation.markWriteError(e);
                log.error("Connection exception persisting metadata", e);
                throw e;
            }
View Full Code Here

Examples of com.netflix.astyanax.MutationBatch

   
    // generic IMetric insertion. All other metric insertion methods could use this one.
    public void insertMetrics(Collection<IMetric> metrics, ColumnFamily cf) throws ConnectionException {
        Timer.Context ctx = Instrumentation.getWriteTimerContext(cf);
        Multimap<Locator, IMetric> map = asMultimap(metrics);
        MutationBatch batch = keyspace.prepareMutationBatch();
        try {
            for (Locator locator : map.keySet()) {
                ColumnListMutation<Long> mutation = batch.withRow(cf, locator);
               
                // we want to insert a locator only for non-string, non-boolean metrics. If there happen to be string or
                // boolean metrics mixed in with numeric metrics, we still want to insert a locator.  If all metrics
                // are boolean or string, we DO NOT want to insert a locator.
                boolean locatorInsertOk = false;
               
                for (IMetric metric : map.get(locator)) {
                   
                    boolean shouldPersist = true;
                    // todo: MetricsPersistenceOptimizerFactory interface needs to be retooled to accept IMetric
                    if (metric instanceof Metric) {
                        final boolean isString = DataType.isStringMetric(metric.getMetricValue());
                        final boolean isBoolean = DataType.isBooleanMetric(metric.getMetricValue());
                       
                       
                        if (!isString && !isBoolean)
                            locatorInsertOk = true;
                        shouldPersist = shouldPersist((Metric)metric);
                    } else {
                        locatorInsertOk = true;
                    }
                   
                    if (shouldPersist) {
                        mutation.putColumn(
                                metric.getCollectionTime(),
                                metric.getMetricValue(),
                                (AbstractSerializer) (NumericSerializer.serializerFor(metric.getMetricValue().getClass())),
                                metric.getTtlInSeconds());
                    }
                }
               
                if (!AstyanaxWriter.isLocatorCurrent(locator)) {
                    if (locatorInsertOk)
                        insertLocator(locator, batch);
                    AstyanaxWriter.setLocatorCurrent(locator);
                }
            }
            try {
                batch.execute();
            } catch (ConnectionException e) {
                Instrumentation.markWriteError(e);
                log.error("Connection exception persisting data", e);
                throw e;
            }
View Full Code Here

Examples of com.netflix.astyanax.MutationBatch

    }

    public void persistShardState(int shard, Map<Granularity, Map<Integer, UpdateStamp>> updates) throws ConnectionException {
        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());
                    /*
                      Note: we used to set the timestamp of the column to entry.getValue().getTimestamp() * 1000 over here.
                      This block of code is dangerous. Consider you are getting out of order metrics M1 and M2, with collection times T1 and T2 with T2>T1, belonging to same slot
                      Assume M2 arrives first. The slot gets marked active and rolled up and the state is set as Rolled. Now, assume M1 arrives. We update the slot state to active,
                      set the slot timestamp to T1, and while persisting we set it, we set the column timestamp to be T1*1000, but because the T1 < T2, the new slot state will never
                      get reflected.
                     */
                }
            }
            if (!mutationBatch.isEmpty())
                try {
                    mutationBatch.execute();
                } catch (ConnectionException e) {
                    Instrumentation.markWriteError(e);
                    log.error("Error persisting shard state", e);
                    throw e;
                }
View Full Code Here

Examples of com.netflix.astyanax.MutationBatch

    public void insertRollups(ArrayList<SingleRollupWriteContext> writeContexts) throws ConnectionException {
        if (writeContexts.size() == 0) {
            return;
        }
        Timer.Context ctx = Instrumentation.getBatchWriteTimerContext(writeContexts.get(0).getDestinationCF());
        MutationBatch mb = keyspace.prepareMutationBatch();
        for (SingleRollupWriteContext writeContext : writeContexts) {
            Rollup rollup = writeContext.getRollup();
            int ttl;
            try {
                ttl = (int)TTL_PROVIDER.getTTL(
                    writeContext.getLocator().getTenantId(),
                    writeContext.getGranularity(),
                    writeContext.getRollup().getRollupType()).toSeconds();
            } catch (Exception ex) {
                log.warn(ex.getMessage(), ex);
                ttl = (int)SafetyTtlProvider.getInstance().getSafeTTL(
                        writeContext.getGranularity(),
                        writeContext.getRollup().getRollupType()).toSeconds();
            }
            AbstractSerializer serializer = NumericSerializer.serializerFor(rollup.getClass());
            try {
                mb.withRow(writeContext.getDestinationCF(), writeContext.getLocator())
                        .putColumn(writeContext.getTimestamp(),
                                rollup,
                                serializer,
                                ttl);
            } catch (RuntimeException ex) {
                // let's not let stupidness prevent the rest of this put.
                log.warn(String.format("Cannot save %s", writeContext.getLocator().toString()), ex);
            }
        }
        try {
            mb.execute();
        } catch (ConnectionException e) {
            Instrumentation.markWriteError(e);
            log.error("Error writing rollup batch", e);
            throw e;
        } finally {
View Full Code Here

Examples of com.netflix.astyanax.MutationBatch

    private void populateMetricsFull() throws Exception {
        final long collectionTimeInSecs = 12345;

        // add a metric to locator
        AstyanaxTester at = new AstyanaxTester();
        MutationBatch mb = at.createMutationBatch();
        mb.withRow(at.getFullCF(), locator)
                .putColumn(collectionTimeInSecs,
                        NumericSerializer.serializerFor(Integer.class).toByteBuffer(123));

        // add another metric
        mb.withRow(at.getFullCF(), locator)
                .putColumn(collectionTimeInSecs + 1,
                        NumericSerializer.serializerFor(Integer.class).toByteBuffer(456));

        mb.execute();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.