예제 #1
0
public class CounterCacheKey implements CacheKey {
  private static final long EMPTY_SIZE =
      ObjectSizes.measure(
              new CounterCacheKey(
                  null,
                  ByteBufferUtil.EMPTY_BYTE_BUFFER,
                  CellNames.simpleDense(ByteBuffer.allocate(1))))
          + ObjectSizes.measure(new UUID(0, 0));

  public final UUID cfId;
  public final byte[] partitionKey;
  public final byte[] cellName;

  private CounterCacheKey(UUID cfId, ByteBuffer partitionKey, CellName cellName) {
    this.cfId = cfId;
    this.partitionKey = ByteBufferUtil.getArray(partitionKey);
    this.cellName = ByteBufferUtil.getArray(cellName.toByteBuffer());
  }

  public static CounterCacheKey create(UUID cfId, ByteBuffer partitionKey, CellName cellName) {
    return new CounterCacheKey(cfId, partitionKey, cellName);
  }

  public UUID getCFId() {
    return cfId;
  }

  public long unsharedHeapSize() {
    return EMPTY_SIZE + ObjectSizes.sizeOfArray(partitionKey) + ObjectSizes.sizeOfArray(cellName);
  }

  @Override
  public String toString() {
    return String.format(
        "CounterCacheKey(%s, %s, %s)",
        cfId,
        ByteBufferUtil.bytesToHex(ByteBuffer.wrap(partitionKey)),
        ByteBufferUtil.bytesToHex(ByteBuffer.wrap(cellName)));
  }

  @Override
  public int hashCode() {
    return Arrays.deepHashCode(new Object[] {cfId, partitionKey, cellName});
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;

    if (!(o instanceof CounterCacheKey)) return false;

    CounterCacheKey cck = (CounterCacheKey) o;

    return cfId.equals(cck.cfId)
        && Arrays.equals(partitionKey, cck.partitionKey)
        && Arrays.equals(cellName, cck.cellName);
  }
}
예제 #2
0
 private static int estimateRowOverhead(final int count) {
   // calculate row overhead
   try (final OpOrder.Group group = new OpOrder().start()) {
     int rowOverhead;
     MemtableAllocator allocator = MEMORY_POOL.newAllocator();
     ConcurrentNavigableMap<PartitionPosition, Object> partitions = new ConcurrentSkipListMap<>();
     final Object val = new Object();
     for (int i = 0; i < count; i++)
       partitions.put(
           allocator.clone(
               new BufferDecoratedKey(new LongToken(i), ByteBufferUtil.EMPTY_BYTE_BUFFER), group),
           val);
     double avgSize = ObjectSizes.measureDeep(partitions) / (double) count;
     rowOverhead =
         (int) ((avgSize - Math.floor(avgSize)) < 0.05 ? Math.floor(avgSize) : Math.ceil(avgSize));
     rowOverhead -= ObjectSizes.measureDeep(new LongToken(0));
     rowOverhead += AtomicBTreePartition.EMPTY_SIZE;
     allocator.setDiscarding();
     allocator.setDiscarded();
     return rowOverhead;
   }
 }
예제 #3
0
public class SimpleDenseCellName extends SimpleComposite implements CellName {
  private static final long EMPTY_SIZE =
      ObjectSizes.measure(new SimpleDenseCellName(ByteBuffer.allocate(1)));

  // Not meant to be used directly, you should use the CellNameType method instead
  SimpleDenseCellName(ByteBuffer element) {
    super(element);
  }

  public int clusteringSize() {
    return 1;
  }

  public ColumnIdentifier cql3ColumnName(CFMetaData metadata) {
    return null;
  }

  public ByteBuffer collectionElement() {
    return null;
  }

  public boolean isCollectionCell() {
    return false;
  }

  public boolean isSameCQL3RowAs(CellNameType type, CellName other) {
    // Dense cell imply one cell by CQL row so no other cell will be the same row.
    return type.compare(this, other) == 0;
  }

  @Override
  public long unsharedHeapSize() {
    return EMPTY_SIZE + ObjectSizes.sizeOnHeapOf(element);
  }

  @Override
  public long unsharedHeapSizeExcludingData() {
    return EMPTY_SIZE + ObjectSizes.sizeOnHeapExcludingData(element);
  }

  // If cellnames were sharing some prefix components, this will break it, so
  // we might want to try to do better.
  @Override
  public CellName copy(CFMetaData cfm, AbstractAllocator allocator) {
    return new SimpleDenseCellName(allocator.clone(element));
  }
}
예제 #4
0
 @Override
 public long unsharedHeapSizeExcludingData() {
   return EMPTY_SIZE + ObjectSizes.sizeOnHeapExcludingData(element);
 }
예제 #5
0
 @Override
 public long unsharedHeapSize() {
   return EMPTY_SIZE + ObjectSizes.sizeOnHeapOf(element);
 }
예제 #6
0
 public long unsharedHeapSize() {
   return EMPTY_SIZE + ObjectSizes.sizeOfArray(partitionKey) + ObjectSizes.sizeOfArray(cellName);
 }