Search in sources :

Example 16 with SSTableReader

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

the class LeveledManifest method getCandidatesFor.

private Collection<SSTableReader> getCandidatesFor(int level) {
    assert !generations[level].isEmpty();
    logger.debug("Choosing candidates for L{}", level);
    if (level == 0) {
        // because L0 files may overlap each other, we treat compactions there specially:
        // a L0 compaction also checks other L0 files for overlap.
        Set<SSTableReader> candidates = new HashSet<SSTableReader>();
        // pick the oldest sstable from L0, and any that overlap with it
        List<SSTableReader> ageSortedSSTables = new ArrayList<SSTableReader>(generations[0]);
        Collections.sort(ageSortedSSTables, SSTable.maxTimestampComparator);
        List<SSTableReader> L0 = overlapping(ageSortedSSTables.get(0), generations[0]);
        L0 = L0.size() > MAX_COMPACTING_L0 ? L0.subList(0, MAX_COMPACTING_L0) : L0;
        // add the overlapping ones from L1
        for (SSTableReader sstable : L0) candidates.addAll(overlapping(sstable, generations[1]));
        return candidates;
    }
    // for non-L0 compactions, pick up where we left off last time
    Collections.sort(generations[level], SSTable.sstableComparator);
    for (SSTableReader sstable : generations[level]) {
        // the first sstable that is > than the marked
        if (sstable.first.compareTo(lastCompactedKeys[level]) > 0)
            return overlapping(sstable, generations[(level + 1)]);
    }
    // or if there was no last time, start with the first sstable
    return overlapping(generations[level].get(0), generations[(level + 1)]);
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.SSTableReader)

Example 17 with SSTableReader

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

the class LeveledManifest method create.

static LeveledManifest create(ColumnFamilyStore cfs, int maxSSTableSize) {
    LeveledManifest manifest = new LeveledManifest(cfs, maxSSTableSize);
    load(cfs, manifest);
    // ensure all SSTables are in the manifest
    for (SSTableReader ssTableReader : cfs.getSSTables()) {
        if (manifest.levelOf(ssTableReader) < 0)
            manifest.add(ssTableReader);
    }
    return manifest;
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.SSTableReader)

Example 18 with SSTableReader

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

the class LeveledManifest method promote.

public synchronized void promote(Iterable<SSTableReader> removed, Iterable<SSTableReader> added) {
    // use add() instead of promote when adding new sstables
    assert !Iterables.isEmpty(removed);
    logDistribution();
    if (logger.isDebugEnabled())
        logger.debug("Replacing [" + toString(removed) + "]");
    // the level for the added sstables is the max of the removed ones,
    // plus one if the removed were all on the same level
    int minimumLevel = Integer.MAX_VALUE;
    int maximumLevel = 0;
    for (SSTableReader sstable : removed) {
        int thisLevel = levelOf(sstable);
        maximumLevel = Math.max(maximumLevel, thisLevel);
        minimumLevel = Math.min(minimumLevel, thisLevel);
        remove(sstable);
    }
    // it's valid to do a remove w/o an add (e.g. on truncate)
    if (!added.iterator().hasNext())
        return;
    int newLevel = minimumLevel == maximumLevel ? maximumLevel + 1 : maximumLevel;
    newLevel = skipLevels(newLevel, added);
    assert newLevel > 0;
    if (logger.isDebugEnabled())
        logger.debug("Adding [{}] at L{}", toString(added), newLevel);
    lastCompactedKeys[minimumLevel] = SSTable.sstableOrdering.max(added).last;
    for (SSTableReader ssTableReader : added) add(ssTableReader, newLevel);
    serialize();
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.SSTableReader)

Example 19 with SSTableReader

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

the class SSTableExportTest method testEscapingDoubleQuotes.

@Test
public void testEscapingDoubleQuotes() throws IOException {
    File tempSS = tempSSTableFile("Keyspace1", "ValuesWithQuotes");
    ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "ValuesWithQuotes");
    SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
    // Add rowA
    cfamily.addColumn(null, new Column(ByteBufferUtil.bytes("data"), UTF8Type.instance.fromString("{\"foo\":\"bar\"}")));
    writer.append(Util.dk("rowA"), cfamily);
    cfamily.clear();
    SSTableReader reader = writer.closeAndOpenReader();
    // Export to JSON and verify
    File tempJson = File.createTempFile("ValuesWithQuotes", ".json");
    SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[0]);
    JSONObject json = (JSONObject) JSONValue.parse(new FileReader(tempJson));
    JSONArray rowA = (JSONArray) json.get(asHex("rowA"));
    JSONArray data = (JSONArray) rowA.get(0);
    assert hexToBytes((String) data.get(0)).equals(ByteBufferUtil.bytes("data"));
    assert data.get(1).equals("{\"foo\":\"bar\"}");
}
Also used : PrintStream(java.io.PrintStream) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) JSONObject(org.json.simple.JSONObject) Column(org.apache.cassandra.db.Column) ExpiringColumn(org.apache.cassandra.db.ExpiringColumn) CounterColumn(org.apache.cassandra.db.CounterColumn) SSTableWriter(org.apache.cassandra.io.sstable.SSTableWriter) JSONArray(org.json.simple.JSONArray) FileReader(java.io.FileReader) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 20 with SSTableReader

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

the class SSTableExportTest method testExportCounterCf.

@Test
public void testExportCounterCf() throws IOException {
    File tempSS = tempSSTableFile("Keyspace1", "Counter1");
    ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Counter1");
    SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
    // Add rowA
    cfamily.addColumn(null, new CounterColumn(ByteBufferUtil.bytes("colA"), 42, System.currentTimeMillis()));
    writer.append(Util.dk("rowA"), cfamily);
    cfamily.clear();
    SSTableReader reader = writer.closeAndOpenReader();
    // Export to JSON and verify
    File tempJson = File.createTempFile("Counter1", ".json");
    SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[0]);
    JSONObject json = (JSONObject) JSONValue.parse(new FileReader(tempJson));
    JSONArray rowA = (JSONArray) json.get(asHex("rowA"));
    JSONArray colA = (JSONArray) rowA.get(0);
    assert hexToBytes((String) colA.get(0)).equals(ByteBufferUtil.bytes("colA"));
    assert ((String) colA.get(3)).equals("c");
    assert (Long) colA.get(4) == Long.MIN_VALUE;
}
Also used : PrintStream(java.io.PrintStream) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) JSONObject(org.json.simple.JSONObject) SSTableWriter(org.apache.cassandra.io.sstable.SSTableWriter) JSONArray(org.json.simple.JSONArray) CounterColumn(org.apache.cassandra.db.CounterColumn) FileReader(java.io.FileReader) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

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