コード例 #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
ファイル: Util.java プロジェクト: hobinyoon/mutants-cassandra
 public static void addMutation(
     Mutation rm,
     String columnFamilyName,
     String superColumnName,
     long columnName,
     String value,
     long timestamp) {
   CellName cname =
       superColumnName == null
           ? CellNames.simpleDense(getBytes(columnName))
           : CellNames.compositeDense(ByteBufferUtil.bytes(superColumnName), getBytes(columnName));
   rm.add(columnFamilyName, cname, ByteBufferUtil.bytes(value), timestamp);
 }
コード例 #3
0
  @Test
  public void testRowCacheRange() {
    CompactionManager.instance.disableAutoCompaction();

    Keyspace keyspace = Keyspace.open(KEYSPACE_CACHED);
    String cf = "CachedIntCF";
    ColumnFamilyStore cachedStore = keyspace.getColumnFamilyStore(cf);
    long startRowCacheHits = cachedStore.metric.rowCacheHit.getCount();
    long startRowCacheOutOfRange = cachedStore.metric.rowCacheHitOutOfRange.getCount();
    // empty the row cache
    CacheService.instance.invalidateRowCache();

    // set global row cache size to 1 MB
    CacheService.instance.setRowCacheCapacityInMB(1);

    ByteBuffer key = ByteBufferUtil.bytes("rowcachekey");
    DecoratedKey dk = cachedStore.partitioner.decorateKey(key);
    RowCacheKey rck = new RowCacheKey(cachedStore.metadata.ksAndCFName, dk);
    Mutation mutation = new Mutation(KEYSPACE_CACHED, key);
    for (int i = 0; i < 200; i++)
      mutation.add(
          cf, Util.cellname(i), ByteBufferUtil.bytes("val" + i), System.currentTimeMillis());
    mutation.applyUnsafe();

    // populate row cache, we should not get a row cache hit;
    cachedStore.getColumnFamily(
        QueryFilter.getSliceFilter(
            dk, cf, Composites.EMPTY, Composites.EMPTY, false, 10, System.currentTimeMillis()));
    assertEquals(startRowCacheHits, cachedStore.metric.rowCacheHit.getCount());

    // do another query, limit is 20, which is < 100 that we cache, we should get a hit and it
    // should be in range
    cachedStore.getColumnFamily(
        QueryFilter.getSliceFilter(
            dk, cf, Composites.EMPTY, Composites.EMPTY, false, 20, System.currentTimeMillis()));
    assertEquals(++startRowCacheHits, cachedStore.metric.rowCacheHit.getCount());
    assertEquals(startRowCacheOutOfRange, cachedStore.metric.rowCacheHitOutOfRange.getCount());

    // get a slice from 95 to 105, 95->99 are in cache, we should not get a hit and then row cache
    // is out of range
    cachedStore.getColumnFamily(
        QueryFilter.getSliceFilter(
            dk,
            cf,
            CellNames.simpleDense(ByteBufferUtil.bytes(95)),
            CellNames.simpleDense(ByteBufferUtil.bytes(105)),
            false,
            10,
            System.currentTimeMillis()));
    assertEquals(startRowCacheHits, cachedStore.metric.rowCacheHit.getCount());
    assertEquals(++startRowCacheOutOfRange, cachedStore.metric.rowCacheHitOutOfRange.getCount());

    // get a slice with limit > 100, we should get a hit out of range.
    cachedStore.getColumnFamily(
        QueryFilter.getSliceFilter(
            dk, cf, Composites.EMPTY, Composites.EMPTY, false, 101, System.currentTimeMillis()));
    assertEquals(startRowCacheHits, cachedStore.metric.rowCacheHit.getCount());
    assertEquals(++startRowCacheOutOfRange, cachedStore.metric.rowCacheHitOutOfRange.getCount());

    CacheService.instance.invalidateRowCache();

    // try to populate row cache with a limit > rows to cache, we should still populate row cache;
    cachedStore.getColumnFamily(
        QueryFilter.getSliceFilter(
            dk, cf, Composites.EMPTY, Composites.EMPTY, false, 105, System.currentTimeMillis()));
    assertEquals(startRowCacheHits, cachedStore.metric.rowCacheHit.getCount());
    // validate the stuff in cache;
    ColumnFamily cachedCf = (ColumnFamily) CacheService.instance.rowCache.get(rck);
    assertEquals(cachedCf.getColumnCount(), 100);
    int i = 0;
    for (Cell c : cachedCf) {
      assertEquals(c.name(), Util.cellname(i++));
    }
  }
コード例 #4
0
ファイル: Util.java プロジェクト: hobinyoon/mutants-cassandra
 public static CellName cellname(ByteBuffer... bbs) {
   if (bbs.length == 1) return CellNames.simpleDense(bbs[0]);
   else return CellNames.compositeDense(bbs);
 }
コード例 #5
0
ファイル: Util.java プロジェクト: hobinyoon/mutants-cassandra
 public static RangeTombstone tombstone(
     String start, String finish, long timestamp, int localtime) {
   Composite startName = CellNames.simpleDense(ByteBufferUtil.bytes(start));
   Composite endName = CellNames.simpleDense(ByteBufferUtil.bytes(finish));
   return new RangeTombstone(startName, endName, timestamp, localtime);
 }
コード例 #6
0
ファイル: Util.java プロジェクト: hobinyoon/mutants-cassandra
 public static CellName cellname(long l) {
   return CellNames.simpleDense(ByteBufferUtil.bytes(l));
 }
コード例 #7
0
ファイル: Util.java プロジェクト: hobinyoon/mutants-cassandra
 public static CellName cellname(int i) {
   return CellNames.simpleDense(ByteBufferUtil.bytes(i));
 }