Пример #1
0
  public RowMutation dropFromSchema(long timestamp) {
    RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, SystemTable.getSchemaKSKey(name));
    rm.delete(new QueryPath(SystemTable.SCHEMA_KEYSPACES_CF), timestamp);
    rm.delete(new QueryPath(SystemTable.SCHEMA_COLUMNFAMILIES_CF), timestamp);
    rm.delete(new QueryPath(SystemTable.SCHEMA_COLUMNS_CF), timestamp);

    return rm;
  }
Пример #2
0
  private void testDontPurgeAccidentaly(String k, String cfname)
      throws IOException, ExecutionException, 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);
    RowMutation rm = new RowMutation(KEYSPACE1, key.key);
    rm.add(
        cfname,
        CompositeType.build(ByteBufferUtil.bytes("sc"), ByteBufferUtil.bytes("c")),
        ByteBufferUtil.EMPTY_BYTE_BUFFER,
        0);
    rm.apply();

    cfs.forceBlockingFlush();

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

    QueryFilter filter = QueryFilter.getIdentityFilter(key, cfname, System.currentTimeMillis());
    assert !(cfs.getColumnFamily(filter).getColumnCount() == 0);

    // Remove key
    rm = new RowMutation(KEYSPACE1, key.key);
    rm.delete(cfname, 2);
    rm.apply();

    ColumnFamily cf = cfs.getColumnFamily(filter);
    assert cf == null || cf.getColumnCount() == 0 : "should be empty: " + cf;

    // 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);
    assert cf == null || cf.getColumnCount() == 0 : "should be empty: " + cf;
  }
Пример #3
0
  public void remove(
      String table,
      String key,
      ColumnPathOrParent column_path_or_parent,
      long timestamp,
      int consistency_level)
      throws InvalidRequestException, UnavailableException {
    if (logger.isDebugEnabled()) logger.debug("remove");
    ThriftValidation.validateColumnPathOrParent(table, column_path_or_parent);

    RowMutation rm = new RowMutation(table, key.trim());
    rm.delete(new QueryPath(column_path_or_parent), timestamp);

    doInsert(consistency_level, rm);
  }
  @Test
  public void testGetSliceFromBasic() throws Throwable {
    // tests slicing against data from one row in a memtable and then flushed to an sstable
    final Table table = Table.open("Keyspace1");
    final ColumnFamilyStore cfStore = table.getColumnFamilyStore("Standard1");
    final String ROW = "row1";

    RowMutation rm = new RowMutation("Keyspace1", ROW);
    ColumnFamily cf = ColumnFamily.create("Keyspace1", "Standard1");
    cf.addColumn(column("col1", "val1", 1L));
    cf.addColumn(column("col3", "val3", 1L));
    cf.addColumn(column("col4", "val4", 1L));
    cf.addColumn(column("col5", "val5", 1L));
    cf.addColumn(column("col7", "val7", 1L));
    cf.addColumn(column("col9", "val9", 1L));
    rm.add(cf);
    rm.apply();

    rm = new RowMutation("Keyspace1", ROW);
    rm.delete(new QueryPath("Standard1", null, "col4".getBytes()), 2L);
    rm.apply();

    Runnable verify =
        new WrappedRunnable() {
          public void runMayThrow() throws Exception {
            ColumnFamily cf;

            cf =
                cfStore.getColumnFamily(
                    ROW,
                    new QueryPath("Standard1"),
                    "col5".getBytes(),
                    ArrayUtils.EMPTY_BYTE_ARRAY,
                    false,
                    2);
            assertColumns(cf, "col5", "col7");

            cf =
                cfStore.getColumnFamily(
                    ROW,
                    new QueryPath("Standard1"),
                    "col4".getBytes(),
                    ArrayUtils.EMPTY_BYTE_ARRAY,
                    false,
                    2);
            assertColumns(cf, "col4", "col5", "col7");
            assertColumns(ColumnFamilyStore.removeDeleted(cf, Integer.MAX_VALUE), "col5", "col7");

            cf =
                cfStore.getColumnFamily(
                    ROW,
                    new QueryPath("Standard1"),
                    "col5".getBytes(),
                    ArrayUtils.EMPTY_BYTE_ARRAY,
                    true,
                    2);
            assertColumns(cf, "col3", "col4", "col5");

            cf =
                cfStore.getColumnFamily(
                    ROW,
                    new QueryPath("Standard1"),
                    "col6".getBytes(),
                    ArrayUtils.EMPTY_BYTE_ARRAY,
                    true,
                    2);
            assertColumns(cf, "col3", "col4", "col5");

            cf =
                cfStore.getColumnFamily(
                    ROW,
                    new QueryPath("Standard1"),
                    ArrayUtils.EMPTY_BYTE_ARRAY,
                    ArrayUtils.EMPTY_BYTE_ARRAY,
                    true,
                    2);
            assertColumns(cf, "col7", "col9");

            cf =
                cfStore.getColumnFamily(
                    ROW,
                    new QueryPath("Standard1"),
                    "col95".getBytes(),
                    ArrayUtils.EMPTY_BYTE_ARRAY,
                    false,
                    2);
            assertColumns(cf);

            cf =
                cfStore.getColumnFamily(
                    ROW,
                    new QueryPath("Standard1"),
                    "col0".getBytes(),
                    ArrayUtils.EMPTY_BYTE_ARRAY,
                    true,
                    2);
            assertColumns(cf);
          }
        };

    reTest(table.getColumnFamilyStore("Standard1"), verify);
  }