コード例 #1
0
 @Override
 public IColumn localCopy(ColumnFamilyStore cfs) {
   return new ExpiringColumn(
       cfs.internOrCopy(name, HeapAllocator.instance),
       ByteBufferUtil.clone(value),
       timestamp,
       timeToLive,
       localExpirationTime);
 }
コード例 #2
0
 @Override
 public void write(Object key, List<ByteBuffer> values) {
   prepareWriter();
   // To ensure Crunch doesn't reuse CQLSSTableWriter's objects
   List<ByteBuffer> bb = Lists.newArrayList();
   for (ByteBuffer v : values) {
     bb.add(ByteBufferUtil.clone(v));
   }
   values = bb;
   try {
     ((CQLSSTableWriter) writer).rawAddRow(values);
     if (null != progress) progress.progress();
     if (null != context) HadoopCompat.progress(context);
   } catch (InvalidRequestException | IOException e) {
     LOG.error(e.getMessage());
     throw new CrunchRuntimeException("Error adding row : " + e.getMessage());
   }
 }
コード例 #3
0
 /**
  * Returns the specified {@link ByteBuffer} as a byte array.
  *
  * @param byteBuffer a {@link ByteBuffer} to be converted to a byte array.
  * @return the byte array representation of the {@code byteBuffer}.
  */
 public static byte[] asArray(ByteBuffer byteBuffer) {
   ByteBuffer bb = ByteBufferUtil.clone(byteBuffer);
   byte[] bytes = new byte[bb.remaining()];
   bb.get(bytes);
   return bytes;
 }
コード例 #4
0
  @Test
  public void testDiff() throws UnknownHostException {
    ContextState left;
    ContextState right;

    CounterColumn leftCol;
    CounterColumn rightCol;

    // timestamp
    leftCol = new CounterColumn(ByteBufferUtil.bytes("x"), 0, 1L);
    rightCol = new CounterColumn(ByteBufferUtil.bytes("x"), 0, 2L);

    assert rightCol == leftCol.diff(rightCol);
    assert null == rightCol.diff(leftCol);

    // timestampOfLastDelete
    leftCol = new CounterColumn(ByteBufferUtil.bytes("x"), 0, 1L, 1L);
    rightCol = new CounterColumn(ByteBufferUtil.bytes("x"), 0, 1L, 2L);

    assert rightCol == leftCol.diff(rightCol);
    assert null == rightCol.diff(leftCol);

    // equality: equal nodes, all counts same
    left = ContextState.allocate(3, 0);
    left.writeElement(NodeId.fromInt(3), 3L, 0L);
    left.writeElement(NodeId.fromInt(6), 2L, 0L);
    left.writeElement(NodeId.fromInt(9), 1L, 0L);
    right = new ContextState(ByteBufferUtil.clone(left.context), 2);

    leftCol = new CounterColumn(ByteBufferUtil.bytes("x"), left.context, 1L);
    rightCol = new CounterColumn(ByteBufferUtil.bytes("x"), right.context, 1L);
    assert null == leftCol.diff(rightCol);

    // greater than: left has superset of nodes (counts equal)
    left = ContextState.allocate(4, 0);
    left.writeElement(NodeId.fromInt(3), 3L, 0L);
    left.writeElement(NodeId.fromInt(6), 2L, 0L);
    left.writeElement(NodeId.fromInt(9), 1L, 0L);
    left.writeElement(NodeId.fromInt(12), 0L, 0L);

    right = ContextState.allocate(3, 0);
    right.writeElement(NodeId.fromInt(3), 3L, 0L);
    right.writeElement(NodeId.fromInt(6), 2L, 0L);
    right.writeElement(NodeId.fromInt(9), 1L, 0L);

    leftCol = new CounterColumn(ByteBufferUtil.bytes("x"), left.context, 1L);
    rightCol = new CounterColumn(ByteBufferUtil.bytes("x"), right.context, 1L);
    assert null == leftCol.diff(rightCol);

    // less than: right has subset of nodes (counts equal)
    assert leftCol == rightCol.diff(leftCol);

    // disjoint: right and left have disjoint node sets
    left = ContextState.allocate(3, 0);
    left.writeElement(NodeId.fromInt(3), 1L, 0L);
    left.writeElement(NodeId.fromInt(4), 1L, 0L);
    left.writeElement(NodeId.fromInt(9), 1L, 0L);

    right = ContextState.allocate(3, 0);
    right.writeElement(NodeId.fromInt(3), 1L, 0L);
    right.writeElement(NodeId.fromInt(6), 1L, 0L);
    right.writeElement(NodeId.fromInt(9), 1L, 0L);

    leftCol = new CounterColumn(ByteBufferUtil.bytes("x"), left.context, 1L);
    rightCol = new CounterColumn(ByteBufferUtil.bytes("x"), right.context, 1L);
    assert rightCol == leftCol.diff(rightCol);
    assert leftCol == rightCol.diff(leftCol);
  }