Search in sources :

Example 6 with RowIndexEntry

use of org.apache.cassandra.db.RowIndexEntry in project cassandra by apache.

the class MajorLeveledCompactionWriter method realAppend.

@Override
@SuppressWarnings("resource")
public boolean realAppend(UnfilteredRowIterator partition) {
    RowIndexEntry rie = sstableWriter.append(partition);
    partitionsWritten++;
    long totalWrittenInCurrentWriter = sstableWriter.currentWriter().getEstimatedOnDiskBytesWritten();
    if (totalWrittenInCurrentWriter > maxSSTableSize) {
        totalWrittenInLevel += totalWrittenInCurrentWriter;
        if (totalWrittenInLevel > LeveledManifest.maxBytesForLevel(currentLevel, levelFanoutSize, maxSSTableSize)) {
            totalWrittenInLevel = 0;
            currentLevel++;
        }
        switchCompactionLocation(sstableDirectory);
    }
    return rie != null;
}
Also used : RowIndexEntry(org.apache.cassandra.db.RowIndexEntry)

Example 7 with RowIndexEntry

use of org.apache.cassandra.db.RowIndexEntry in project cassandra by apache.

the class SSTableRewriter method append.

public RowIndexEntry append(UnfilteredRowIterator partition) {
    // we do this before appending to ensure we can resetAndTruncate() safely if the append fails
    DecoratedKey key = partition.partitionKey();
    maybeReopenEarly(key);
    RowIndexEntry index = writer.append(partition);
    if (!transaction.isOffline() && index != null) {
        for (SSTableReader reader : transaction.originals()) {
            if (reader.getCachedPosition(key, false) != null) {
                cachedKeys.put(key, index);
                break;
            }
        }
    }
    return index;
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) DecoratedKey(org.apache.cassandra.db.DecoratedKey) RowIndexEntry(org.apache.cassandra.db.RowIndexEntry)

Example 8 with RowIndexEntry

use of org.apache.cassandra.db.RowIndexEntry in project cassandra by apache.

the class QueryWithIndexedSSTableTest method queryIndexedSSTableTest.

@Test
public void queryIndexedSSTableTest() throws Throwable {
    // That test reproduces the bug from CASSANDRA-10903 and the fact we have a static column is
    // relevant to that reproduction in particular as it forces a slightly different code path that
    // if there wasn't a static.
    int ROWS = 1000;
    int VALUE_LENGTH = 100;
    createTable("CREATE TABLE %s (k int, t int, s text static, v text, PRIMARY KEY (k, t))");
    // We create a partition that is big enough that the underlying sstable will be indexed
    // For that, we use a large-ish number of row, and a value that isn't too small.
    String text = TombstonesWithIndexedSSTableTest.makeRandomString(VALUE_LENGTH);
    for (int i = 0; i < ROWS; i++) execute("INSERT INTO %s(k, t, v) VALUES (?, ?, ?)", 0, i, text + i);
    flush();
    compact();
    // Sanity check that we're testing what we want to test, that is that we're reading from an indexed
    // sstable. Note that we'll almost surely have a single indexed sstable in practice, but it's theorically
    // possible for a compact strategy to yield more than that and as long as one is indexed we're pretty
    // much testing what we want. If this check ever fails on some specific setting, we'll have to either
    // tweak ROWS and VALUE_LENGTH, or skip the test on those settings.
    DecoratedKey dk = Util.dk(ByteBufferUtil.bytes(0));
    boolean hasIndexed = false;
    for (SSTableReader sstable : getCurrentColumnFamilyStore().getLiveSSTables()) {
        RowIndexEntry indexEntry = sstable.getPosition(dk, SSTableReader.Operator.EQ);
        hasIndexed |= indexEntry != null && indexEntry.isIndexed();
    }
    assert hasIndexed;
    assertRowCount(execute("SELECT s FROM %s WHERE k = ?", 0), ROWS);
    assertRowCount(execute("SELECT s FROM %s WHERE k = ? ORDER BY t DESC", 0), ROWS);
    assertRowCount(execute("SELECT DISTINCT s FROM %s WHERE k = ?", 0), 1);
    assertRowCount(execute("SELECT DISTINCT s FROM %s WHERE k = ? ORDER BY t DESC", 0), 1);
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) DecoratedKey(org.apache.cassandra.db.DecoratedKey) RowIndexEntry(org.apache.cassandra.db.RowIndexEntry) Test(org.junit.Test)

Aggregations

RowIndexEntry (org.apache.cassandra.db.RowIndexEntry)8 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)5 DecoratedKey (org.apache.cassandra.db.DecoratedKey)4 IOException (java.io.IOException)1 Map (java.util.Map)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 CompactionInterruptedException (org.apache.cassandra.db.compaction.CompactionInterruptedException)1 ColumnIndex (org.apache.cassandra.index.sasi.conf.ColumnIndex)1 PerSSTableIndexWriter (org.apache.cassandra.index.sasi.disk.PerSSTableIndexWriter)1 FSReadError (org.apache.cassandra.io.FSReadError)1 KeyIterator (org.apache.cassandra.io.sstable.KeyIterator)1 SSTableIdentityIterator (org.apache.cassandra.io.sstable.SSTableIdentityIterator)1 RandomAccessReader (org.apache.cassandra.io.util.RandomAccessReader)1 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)1 Test (org.junit.Test)1