コード例 #1
0
  public <K> void deleteByKeyAsync(
      Iterable<K> keys, Class<?> bean, Session session, ConsistencyLevel consistency) {

    for (K key : keys) {
      session.executeAsync(runDelete(key, bean, consistency));
    }
  }
コード例 #2
0
  @Test
  public void compressionTest() throws Exception {

    // Same as executeTest, but with compression enabled

    cluster
        .getConfiguration()
        .getProtocolOptions()
        .setCompression(ProtocolOptions.Compression.SNAPPY);

    try {

      Session compressedSession = cluster.connect(TestUtils.SIMPLE_KEYSPACE);

      // Simple calls to all versions of the execute/executeAsync methods
      String key = "execute_compressed_test";
      ResultSet rs =
          compressedSession.execute(String.format(INSERT_FORMAT, TABLE, key, "foo", 42, 24.03f));
      assertTrue(rs.isExhausted());

      String SELECT_ALL = String.format(SELECT_ALL_FORMAT + " WHERE k = '%s'", TABLE, key);

      // execute
      checkExecuteResultSet(compressedSession.execute(SELECT_ALL), key);
      checkExecuteResultSet(
          compressedSession.execute(
              new SimpleStatement(SELECT_ALL).setConsistencyLevel(ConsistencyLevel.ONE)),
          key);

      // executeAsync
      checkExecuteResultSet(compressedSession.executeAsync(SELECT_ALL).getUninterruptibly(), key);
      checkExecuteResultSet(
          compressedSession
              .executeAsync(
                  new SimpleStatement(SELECT_ALL).setConsistencyLevel(ConsistencyLevel.ONE))
              .getUninterruptibly(),
          key);

    } finally {
      cluster
          .getConfiguration()
          .getProtocolOptions()
          .setCompression(ProtocolOptions.Compression.NONE);
    }
  }
コード例 #3
0
ファイル: Mover.java プロジェクト: mdykman/gauze
 public List<ListenableFuture<ResultSet>> applyStatements(List<String> ss, boolean sync)
     throws Exception {
   List<ListenableFuture<ResultSet>> list = new ArrayList<>();
   for (String s : ss) {
     System.out.println(s);
     if (sync) {
       session.execute(s);
     } else {
       list.add(session.executeAsync(s));
     }
   }
   return list;
 }
コード例 #4
0
ファイル: IndexStrategy.java プロジェクト: hi3g/freki
    @Override
    public void indexTimeseriesId(
        final LabelId metric, final List<LabelId> tags, final ByteBuffer timeSeriresId) {
      final long longMetric = toLong(metric);
      final Map<Long, Long> longTags = toMap(tags);

      session.executeAsync(
          insertTagsStatement
              .bind()
              .setLong(0, longMetric)
              .setString(1, LabelType.METRIC.toValue())
              .setBytesUnsafe(2, timeSeriresId)
              .setLong(3, longMetric)
              .setMap(4, longTags));

      final Iterator<LabelId> tagIterator = tags.iterator();

      while (tagIterator.hasNext()) {
        session.executeAsync(
            insertTagsStatement
                .bind()
                .setLong(0, toLong(tagIterator.next()))
                .setString(1, LabelType.TAGK.toValue())
                .setBytesUnsafe(2, timeSeriresId)
                .setLong(3, longMetric)
                .setMap(4, longTags));

        session.executeAsync(
            insertTagsStatement
                .bind()
                .setLong(0, toLong(tagIterator.next()))
                .setString(1, LabelType.TAGV.toValue())
                .setBytesUnsafe(2, timeSeriresId)
                .setLong(3, longMetric)
                .setMap(4, longTags));
      }
    }
コード例 #5
0
ファイル: Indexer.java プロジェクト: criteo-forks/zipkin
  ImmutableSet<ListenableFuture<?>> index(List<Span> spans) {
    // First parse each span into partition keys used to support query requests
    Builder<PartitionKeyToTraceId, Long> parsed = ImmutableSetMultimap.builder();
    for (Span span : spans) {
      Long timestamp = guessTimestamp(span);
      if (timestamp == null) continue;
      for (String partitionKey : index.partitionKeys(span)) {
        parsed.put(
            new PartitionKeyToTraceId(index.table(), partitionKey, span.traceId),
            1000 * (timestamp / 1000)); // index precision is millis
      }
    }

    // The parsed results may include inserts that already occur, or are redundant as they don't
    // impact QueryRequest.endTs or QueryRequest.loopback. For example, a parsed timestamp could
    // be between timestamps of rows that already exist for a particular trace.
    ImmutableSetMultimap<PartitionKeyToTraceId, Long> maybeInsert = parsed.build();

    ImmutableSetMultimap<PartitionKeyToTraceId, Long> toInsert;
    if (sharedState == null) { // special-case when caching is disabled.
      toInsert = maybeInsert;
    } else {
      // Optimized results will be smaller when the input includes traces with local spans, or when
      // other threads indexed the same trace.
      toInsert = entriesThatIncreaseGap(sharedState, maybeInsert);

      if (maybeInsert.size() > toInsert.size() && LOG.isDebugEnabled()) {
        int delta = maybeInsert.size() - toInsert.size();
        LOG.debug("optimized out {}/{} inserts into {}", delta, maybeInsert.size(), index.table());
      }
    }

    // For each entry, insert a new row in the index table asynchronously
    ImmutableSet.Builder<ListenableFuture<?>> result = ImmutableSet.builder();
    for (Map.Entry<PartitionKeyToTraceId, Long> entry : toInsert.entries()) {
      BoundStatement bound =
          bindWithName(prepared, boundName)
              .setLong("trace_id", entry.getKey().traceId)
              .setBytesUnsafe("ts", timestampCodec.serialize(entry.getValue()));
      if (indexTtl != null) {
        bound.setInt("ttl_", indexTtl);
      }
      index.bindPartitionKey(bound, entry.getKey().partitionKey);
      result.add(session.executeAsync(bound));
    }
    return result.build();
  }
コード例 #6
0
 public <K> void deleteByKeyAsync(
     K key, Class<?> bean, Session session, ConsistencyLevel consistency) {
   Delete delete = runDelete(key, bean, consistency);
   session.executeAsync(delete);
 }