Пример #1
0
  private void testDontPurgeAccidentaly(String k, String cfname) throws InterruptedException {
    // This test catches the regression of CASSANDRA-2786
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);

    // disable compaction while flushing
    cfs.clearUnsafe();
    cfs.disableAutoCompaction();

    // Add test row
    DecoratedKey key = Util.dk(k);
    Mutation rm = new Mutation(KEYSPACE1, key.getKey());
    rm.add(
        cfname,
        Util.cellname(ByteBufferUtil.bytes("sc"), ByteBufferUtil.bytes("c")),
        ByteBufferUtil.EMPTY_BYTE_BUFFER,
        0);
    rm.applyUnsafe();

    cfs.forceBlockingFlush();

    Collection<SSTableReader> sstablesBefore = cfs.getSSTables();

    QueryFilter filter = QueryFilter.getIdentityFilter(key, cfname, System.currentTimeMillis());
    assertTrue(cfs.getColumnFamily(filter).hasColumns());

    // Remove key
    rm = new Mutation(KEYSPACE1, key.getKey());
    rm.delete(cfname, 2);
    rm.applyUnsafe();

    ColumnFamily cf = cfs.getColumnFamily(filter);
    assertTrue("should be empty: " + cf, cf == null || !cf.hasColumns());

    // Sleep one second so that the removal is indeed purgeable even with gcgrace == 0
    Thread.sleep(1000);

    cfs.forceBlockingFlush();

    Collection<SSTableReader> sstablesAfter = cfs.getSSTables();
    Collection<SSTableReader> toCompact = new ArrayList<SSTableReader>();
    for (SSTableReader sstable : sstablesAfter)
      if (!sstablesBefore.contains(sstable)) toCompact.add(sstable);

    Util.compact(cfs, toCompact);

    cf = cfs.getColumnFamily(filter);
    assertTrue("should be empty: " + cf, cf == null || !cf.hasColumns());
  }
Пример #2
0
  public boolean isFullyCoveredBy(ColumnFamily cf, long now) {
    // cf is the beginning of a partition. It covers this filter if:
    //   1) either this filter requests the head of the partition and request less
    //      than what cf has to offer (note: we do need to use getLiveCount() for that
    //      as it knows if the filter count cells or CQL3 rows).
    //   2) the start and finish bound of this filter are included in cf.
    if (isHeadFilter() && count <= getLiveCount(cf, now)) return true;

    if (start().isEmpty() || finish().isEmpty() || !cf.hasColumns()) return false;

    Composite low = isReversed() ? finish() : start();
    Composite high = isReversed() ? start() : finish();

    CellName first = cf.iterator(ColumnSlice.ALL_COLUMNS_ARRAY).next().name();
    CellName last = cf.reverseIterator(ColumnSlice.ALL_COLUMNS_ARRAY).next().name();

    return cf.getComparator().compare(first, low) <= 0
        && cf.getComparator().compare(high, last) <= 0;
  }