Search in sources :

Example 1 with RowMutation

use of org.apache.cassandra.db.RowMutation in project eiger by wlloyd.

the class CleanupHelper method insertData.

protected void insertData(String keyspace, String columnFamily, int offset, int numberOfRows) throws IOException {
    for (int i = offset; i < offset + numberOfRows; i++) {
        ByteBuffer key = ByteBufferUtil.bytes("key" + i);
        RowMutation rowMutation = new RowMutation(keyspace, key);
        QueryPath path = new QueryPath(columnFamily, null, ByteBufferUtil.bytes("col" + i));
        rowMutation.add(path, ByteBufferUtil.bytes("val" + i), System.currentTimeMillis());
        rowMutation.applyUnsafe();
    }
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) RowMutation(org.apache.cassandra.db.RowMutation) ByteBuffer(java.nio.ByteBuffer)

Example 2 with RowMutation

use of org.apache.cassandra.db.RowMutation in project eiger by wlloyd.

the class CompactionsPurgeTest method testMinorCompactionPurge.

@Test
public void testMinorCompactionPurge() throws IOException, ExecutionException, InterruptedException {
    CompactionManager.instance.disableAutoCompaction();
    Table table = Table.open(TABLE2);
    String cfName = "Standard1";
    ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
    RowMutation rm;
    for (int k = 1; k <= 2; ++k) {
        DecoratedKey key = Util.dk("key" + k);
        // inserts
        rm = new RowMutation(TABLE2, key.key);
        for (int i = 0; i < 10; i++) {
            rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
        }
        rm.apply();
        cfs.forceBlockingFlush();
        // deletes
        for (int i = 0; i < 10; i++) {
            rm = new RowMutation(TABLE2, key.key);
            rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), 1);
            rm.apply();
        }
        cfs.forceBlockingFlush();
    }
    DecoratedKey key1 = Util.dk("key1");
    DecoratedKey key2 = Util.dk("key2");
    // flush, remember the current sstable and then resurrect one column
    // for first key. Then submit minor compaction on remembered sstables.
    cfs.forceBlockingFlush();
    Collection<SSTableReader> sstablesIncomplete = cfs.getSSTables();
    rm = new RowMutation(TABLE2, key1.key);
    rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(5))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 2);
    rm.apply();
    cfs.forceBlockingFlush();
    new CompactionTask(cfs, sstablesIncomplete, Integer.MAX_VALUE).execute(null);
    // verify that minor compaction does not GC when key is present
    // in a non-compacted sstable
    ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key1, new QueryPath(cfName)));
    assert cf.getColumnCount() == 10;
    // verify that minor compaction does GC when key is provably not
    // present in a non-compacted sstable
    cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key2, new QueryPath(cfName)));
    assert cf == null;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) Table(org.apache.cassandra.db.Table) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RowMutation(org.apache.cassandra.db.RowMutation) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 3 with RowMutation

use of org.apache.cassandra.db.RowMutation in project eiger by wlloyd.

the class CompactionsPurgeTest method testMajorCompactionPurge.

@Test
public void testMajorCompactionPurge() throws IOException, ExecutionException, InterruptedException {
    CompactionManager.instance.disableAutoCompaction();
    Table table = Table.open(TABLE1);
    String cfName = "Standard1";
    ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
    DecoratedKey key = Util.dk("key1");
    RowMutation rm;
    // inserts
    rm = new RowMutation(TABLE1, key.key);
    for (int i = 0; i < 10; i++) {
        rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
    }
    rm.apply();
    cfs.forceBlockingFlush();
    // deletes
    for (int i = 0; i < 10; i++) {
        rm = new RowMutation(TABLE1, key.key);
        rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), 1);
        rm.apply();
    }
    cfs.forceBlockingFlush();
    // resurrect one column
    rm = new RowMutation(TABLE1, key.key);
    rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(5))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 2);
    rm.apply();
    cfs.forceBlockingFlush();
    // major compact and test that all columns but the resurrected one is completely gone
    CompactionManager.instance.submitMaximal(cfs, Integer.MAX_VALUE).get();
    cfs.invalidateCachedRow(key);
    ColumnFamily cf = cfs.getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName)));
    assertColumns(cf, "5");
    assert cf.getColumn(ByteBufferUtil.bytes(String.valueOf(5))) != null;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) Table(org.apache.cassandra.db.Table) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RowMutation(org.apache.cassandra.db.RowMutation) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 4 with RowMutation

use of org.apache.cassandra.db.RowMutation in project eiger by wlloyd.

the class CompactionsPurgeTest method testCompactionPurgeOneFile.

@Test
public void testCompactionPurgeOneFile() throws IOException, ExecutionException, InterruptedException {
    CompactionManager.instance.disableAutoCompaction();
    Table table = Table.open(TABLE1);
    String cfName = "Standard2";
    ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
    DecoratedKey key = Util.dk("key1");
    RowMutation rm;
    // inserts
    rm = new RowMutation(TABLE1, key.key);
    for (int i = 0; i < 5; i++) {
        rm.add(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
    }
    rm.apply();
    // deletes
    for (int i = 0; i < 5; i++) {
        rm = new RowMutation(TABLE1, key.key);
        rm.delete(new QueryPath(cfName, null, ByteBufferUtil.bytes(String.valueOf(i))), 1);
        rm.apply();
    }
    cfs.forceBlockingFlush();
    // inserts & deletes were in the same memtable -> only deletes in sstable
    assert cfs.getSSTables().size() == 1 : cfs.getSSTables();
    // compact and test that the row is completely gone
    Util.compactAll(cfs).get();
    assert cfs.getSSTables().isEmpty();
    ColumnFamily cf = table.getColumnFamilyStore(cfName).getColumnFamily(QueryFilter.getIdentityFilter(key, new QueryPath(cfName)));
    assert cf == null : cf;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) Table(org.apache.cassandra.db.Table) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RowMutation(org.apache.cassandra.db.RowMutation) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 5 with RowMutation

use of org.apache.cassandra.db.RowMutation in project titan by thinkaurelius.

the class CassandraEmbeddedStoreManager method mutateMany.

/*
      * This implementation can't handle counter columns.
      *
      * The private method internal_batch_mutate in CassandraServer as of 1.2.0
      * provided most of the following method after transaction handling.
      */
@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws StorageException {
    Preconditions.checkNotNull(mutations);
    final Timestamp timestamp = getTimestamp(txh);
    int size = 0;
    for (Map<StaticBuffer, KCVMutation> mutation : mutations.values()) size += mutation.size();
    Map<StaticBuffer, RowMutation> rowMutations = new HashMap<StaticBuffer, RowMutation>(size);
    for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> mutEntry : mutations.entrySet()) {
        String columnFamily = mutEntry.getKey();
        for (Map.Entry<StaticBuffer, KCVMutation> titanMutation : mutEntry.getValue().entrySet()) {
            StaticBuffer key = titanMutation.getKey();
            KCVMutation mut = titanMutation.getValue();
            RowMutation rm = rowMutations.get(key);
            if (rm == null) {
                rm = new RowMutation(keySpaceName, key.asByteBuffer());
                rowMutations.put(key, rm);
            }
            if (mut.hasAdditions()) {
                for (Entry e : mut.getAdditions()) {
                    // TODO are these asByteBuffer() calls too expensive?
                    QueryPath path = new QueryPath(columnFamily, null, e.getColumn().asByteBuffer());
                    rm.add(path, e.getValue().asByteBuffer(), timestamp.additionTime);
                }
            }
            if (mut.hasDeletions()) {
                for (StaticBuffer col : mut.getDeletions()) {
                    QueryPath path = new QueryPath(columnFamily, null, col.asByteBuffer());
                    rm.delete(path, timestamp.deletionTime);
                }
            }
        }
    }
    mutate(new ArrayList<RowMutation>(rowMutations.values()), getTx(txh).getWriteConsistencyLevel().getDBConsistency());
}
Also used : HashMap(java.util.HashMap) KCVMutation(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation) QueryPath(org.apache.cassandra.db.filter.QueryPath) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) RowMutation(org.apache.cassandra.db.RowMutation) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Aggregations

RowMutation (org.apache.cassandra.db.RowMutation)14 QueryPath (org.apache.cassandra.db.filter.QueryPath)12 Table (org.apache.cassandra.db.Table)8 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)7 DecoratedKey (org.apache.cassandra.db.DecoratedKey)7 ColumnFamily (org.apache.cassandra.db.ColumnFamily)6 Test (org.junit.Test)6 ByteBuffer (java.nio.ByteBuffer)5 CFMetaData (org.apache.cassandra.config.CFMetaData)2 CounterMutation (org.apache.cassandra.db.CounterMutation)2 IColumn (org.apache.cassandra.db.IColumn)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)1 Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)1 KCVMutation (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1