Search in sources :

Example 41 with SSTableReader

use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.

the class StreamingTransferTest method testTransferTableCounter.

@Test
public void testTransferTableCounter() throws Exception {
    final Table table = Table.open("Keyspace1");
    final ColumnFamilyStore cfs = table.getColumnFamilyStore("Counter1");
    final CounterContext cc = new CounterContext();
    final Map<String, ColumnFamily> cleanedEntries = new HashMap<String, ColumnFamily>();
    List<String> keys = createAndTransfer(table, cfs, new Mutator() {

        /**
         * Creates a new SSTable per key: all will be merged before streaming.
         */
        public void mutate(String key, String col, long timestamp) throws Exception {
            Map<String, ColumnFamily> entries = new HashMap<String, ColumnFamily>();
            ColumnFamily cf = ColumnFamily.create(cfs.metadata);
            ColumnFamily cfCleaned = ColumnFamily.create(cfs.metadata);
            CounterContext.ContextState state = CounterContext.ContextState.allocate(4, 1);
            state.writeElement(NodeId.fromInt(2), 9L, 3L, true);
            state.writeElement(NodeId.fromInt(4), 4L, 2L);
            state.writeElement(NodeId.fromInt(6), 3L, 3L);
            state.writeElement(NodeId.fromInt(8), 2L, 4L);
            cf.addColumn(new CounterColumn(ByteBufferUtil.bytes(col), state.context, timestamp));
            cfCleaned.addColumn(new CounterColumn(ByteBufferUtil.bytes(col), cc.clearAllDelta(state.context), timestamp));
            entries.put(key, cf);
            cleanedEntries.put(key, cfCleaned);
            cfs.addSSTable(SSTableUtils.prepare().ks(table.name).cf(cfs.columnFamily).generation(0).write(entries));
        }
    });
    // filter pre-cleaned entries locally, and ensure that the end result is equal
    cleanedEntries.keySet().retainAll(keys);
    SSTableReader cleaned = SSTableUtils.prepare().ks(table.name).cf(cfs.columnFamily).generation(0).write(cleanedEntries);
    SSTableReader streamed = cfs.getSSTables().iterator().next();
    SSTableUtils.assertContentEquals(cleaned, streamed);
    // Retransfer the file, making sure it is now idempotent (see CASSANDRA-3481)
    cfs.clearUnsafe();
    transfer(table, streamed);
    SSTableReader restreamed = cfs.getSSTables().iterator().next();
    SSTableUtils.assertContentEquals(streamed, restreamed);
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) CounterContext(org.apache.cassandra.db.context.CounterContext) Test(org.junit.Test)

Example 42 with SSTableReader

use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.

the class SSTableImportTest method testImportSuperCf.

@Test
public void testImportSuperCf() throws IOException, ParseException, URISyntaxException {
    String jsonUrl = resourcePath("SuperCF.json");
    File tempSS = tempSSTableFile("Keyspace1", "Super4");
    SSTableImport.importJson(jsonUrl, "Keyspace1", "Super4", tempSS.getPath());
    // Verify results
    SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
    QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Super4", null, null), ByteBufferUtil.bytes("superA"));
    ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily();
    IColumn superCol = cf.getColumn(ByteBufferUtil.bytes("superA"));
    assert superCol != null;
    assert superCol.getSubColumns().size() > 0;
    IColumn subColumn = superCol.getSubColumn(ByteBufferUtil.bytes("636f6c4141"));
    assert subColumn.value().equals(hexToBytes("76616c75654141"));
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IColumn(org.apache.cassandra.db.IColumn) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 43 with SSTableReader

use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.

the class SSTableImportTest method testImportCounterCf.

@Test
public void testImportCounterCf() throws IOException, URISyntaxException {
    // Import JSON to temp SSTable file
    String jsonUrl = resourcePath("CounterCF.json");
    File tempSS = tempSSTableFile("Keyspace1", "Counter1");
    SSTableImport.importJson(jsonUrl, "Keyspace1", "Counter1", tempSS.getPath());
    // Verify results
    SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
    QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Counter1"));
    IColumnIterator iter = qf.getSSTableColumnIterator(reader);
    ColumnFamily cf = iter.getColumnFamily();
    while (iter.hasNext()) cf.addColumn(iter.next());
    IColumn c = cf.getColumn(ByteBufferUtil.bytes("colAA"));
    assert c instanceof CounterColumn : c;
    assert ((CounterColumn) c).total() == 42;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IColumn(org.apache.cassandra.db.IColumn) IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator) CounterColumn(org.apache.cassandra.db.CounterColumn) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 44 with SSTableReader

use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.

the class SSTableImportTest method testImportSimpleCfOldFormat.

@Test
public void testImportSimpleCfOldFormat() throws IOException, URISyntaxException {
    // Import JSON to temp SSTable file
    String jsonUrl = resourcePath("SimpleCF.oldformat.json");
    File tempSS = tempSSTableFile("Keyspace1", "Standard1");
    SSTableImport.importJson(jsonUrl, "Keyspace1", "Standard1", tempSS.getPath());
    // Verify results
    SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
    QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Standard1"));
    IColumnIterator iter = qf.getSSTableColumnIterator(reader);
    ColumnFamily cf = iter.getColumnFamily();
    while (iter.hasNext()) cf.addColumn(iter.next());
    assert cf.getColumn(ByteBufferUtil.bytes("colAA")).value().equals(hexToBytes("76616c4141"));
    assert !(cf.getColumn(ByteBufferUtil.bytes("colAA")) instanceof DeletedColumn);
    IColumn expCol = cf.getColumn(ByteBufferUtil.bytes("colAC"));
    assert expCol.value().equals(hexToBytes("76616c4143"));
    assert expCol instanceof ExpiringColumn;
    assert ((ExpiringColumn) expCol).getTimeToLive() == 42 && expCol.getLocalDeletionTime() == 2000000000;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IColumn(org.apache.cassandra.db.IColumn) ExpiringColumn(org.apache.cassandra.db.ExpiringColumn) IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator) DeletedColumn(org.apache.cassandra.db.DeletedColumn) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 45 with SSTableReader

use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.

the class LazilyCompactedRowTest method assertDigest.

private void assertDigest(ColumnFamilyStore cfs, int gcBefore) throws IOException, NoSuchAlgorithmException {
    Collection<SSTableReader> sstables = cfs.getSSTables();
    AbstractCompactionIterable ci1 = new CompactionIterable(OperationType.UNKNOWN, sstables, new PreCompactingController(cfs, sstables, gcBefore, false));
    AbstractCompactionIterable ci2 = new CompactionIterable(OperationType.UNKNOWN, sstables, new LazilyCompactingController(cfs, sstables, gcBefore, false));
    CloseableIterator<AbstractCompactedRow> iter1 = ci1.iterator();
    CloseableIterator<AbstractCompactedRow> iter2 = ci2.iterator();
    while (true) {
        if (!iter1.hasNext()) {
            assert !iter2.hasNext();
            break;
        }
        AbstractCompactedRow row1 = iter1.next();
        AbstractCompactedRow row2 = iter2.next();
        MessageDigest digest1 = MessageDigest.getInstance("MD5");
        MessageDigest digest2 = MessageDigest.getInstance("MD5");
        row1.update(digest1);
        row2.update(digest2);
        assert MessageDigest.isEqual(digest1.digest(), digest2.digest());
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) MessageDigest(java.security.MessageDigest)

Aggregations

SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)45 Test (org.junit.Test)16 File (java.io.File)14 ColumnFamily (org.apache.cassandra.db.ColumnFamily)10 QueryPath (org.apache.cassandra.db.filter.QueryPath)10 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)9 IOException (java.io.IOException)8 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)7 SSTableWriter (org.apache.cassandra.io.sstable.SSTableWriter)7 IColumnIterator (org.apache.cassandra.db.columniterator.IColumnIterator)6 PrintStream (java.io.PrintStream)5 FileReader (java.io.FileReader)4 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)4 ExpiringColumn (org.apache.cassandra.db.ExpiringColumn)4 IColumn (org.apache.cassandra.db.IColumn)4 Token (org.apache.cassandra.dht.Token)4 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 ByteBuffer (java.nio.ByteBuffer)3 CounterColumn (org.apache.cassandra.db.CounterColumn)3