Esempio n. 1
0
 private void doPut(Keyspace keyspace, CacheKey key, Integer dataOffset, Point d)
     throws ConnectionException {
   keyspace
       .prepareQuery(columnFamily)
       .withCql(CQL_STMT)
       .asPreparedStatement()
       .withByteBufferValue(key, cacheKeySerializer)
       .withIntegerValue(dataOffset)
       .withDoubleValue(d.getValue())
       .execute();
 }
Esempio n. 2
0
  @Override
  public CacheBackendPutResult call() throws Exception {
    final Keyspace keyspace = ctx.getClient();
    final AggregationInstance aggregation = key.getAggregation();
    final long size = aggregation.cadence();
    final long columnWidth = size * Cassandra2AggregationCacheBackend.WIDTH;

    for (final Point d : datapoints) {
      final double value = d.getValue();

      if (!Double.isFinite(value)) {
        continue;
      }

      final int index = (int) ((d.getTimestamp() % columnWidth) / size);
      final long base = d.getTimestamp() - d.getTimestamp() % columnWidth;
      final CacheKey key =
          new CacheKey(
              CacheKey.VERSION, this.key.getFilter(), this.key.getGroup(), aggregation, base);
      doPut(keyspace, key, index, d);
    }

    return new CacheBackendPutResult();
  }
Esempio n. 3
0
  @Override
  public void updatePoint(Map<String, String> tags, Point d) {
    final double value = d.getValue();

    while (true) {
      final Cell c = cell.get();

      final long count = c.count + 1;
      final double delta = value - c.mean;
      final double mean = c.mean + delta / count;
      final double s = c.s + delta * (value - mean);

      final Cell n = new Cell(mean, s, count);

      if (cell.compareAndSet(c, n)) {
        break;
      }
    }
  }