Java Code Examples for org.apache.cassandra.io.sstable.SSTableReader#getFilename()

The following examples show how to use org.apache.cassandra.io.sstable.SSTableReader#getFilename() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleSliceReader.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public SimpleSliceReader(SSTableReader sstable, RowIndexEntry indexEntry, FileDataInput input, Composite finishColumn)
{
    Tracing.trace("Seeking to partition beginning in data file");
    this.finishColumn = finishColumn;
    this.comparator = sstable.metadata.comparator;
    try
    {
        if (input == null)
        {
            this.file = sstable.getFileDataInput(indexEntry.position);
            this.needsClosing = true;
        }
        else
        {
            this.file = input;
            input.seek(indexEntry.position);
            this.needsClosing = false;
        }

        // Skip key and data size
        ByteBufferUtil.skipShortLength(file);

        emptyColumnFamily = ArrayBackedSortedColumns.factory.create(sstable.metadata);
        emptyColumnFamily.delete(DeletionTime.serializer.deserialize(file));
        atomIterator = emptyColumnFamily.metadata().getOnDiskIterator(file, sstable.descriptor.version);
    }
    catch (IOException e)
    {
        sstable.markSuspect();
        throw new CorruptSSTableException(e, sstable.getFilename());
    }
}
 
Example 2
Source File: ScrubTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@Test
public void testScrubCorruptedCounterRow() throws IOException, WriteTimeoutException
{
    // skip the test when compression is enabled until CASSANDRA-9140 is complete
    assumeTrue(!Boolean.parseBoolean(System.getProperty("cassandra.test.compression", "false")));

    CompactionManager.instance.disableAutoCompaction();
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(COUNTER_CF);
    cfs.clearUnsafe();

    fillCounterCF(cfs, 2);

    List<Row> rows = cfs.getRangeSlice(Util.range("", ""), null, new IdentityQueryFilter(), 1000);
    assertEquals(2, rows.size());

    SSTableReader sstable = cfs.getSSTables().iterator().next();

    // overwrite one row with garbage
    long row0Start = sstable.getPosition(RowPosition.ForKey.get(ByteBufferUtil.bytes("0"), sstable.partitioner), SSTableReader.Operator.EQ).position;
    long row1Start = sstable.getPosition(RowPosition.ForKey.get(ByteBufferUtil.bytes("1"), sstable.partitioner), SSTableReader.Operator.EQ).position;
    long startPosition = row0Start < row1Start ? row0Start : row1Start;
    long endPosition = row0Start < row1Start ? row1Start : row0Start;

    RandomAccessFile file = new RandomAccessFile(sstable.getFilename(), "rw");
    file.seek(startPosition);
    file.writeBytes(StringUtils.repeat('z', (int) (endPosition - startPosition)));
    file.close();

    // with skipCorrupted == false, the scrub is expected to fail
    Scrubber scrubber = new Scrubber(cfs, sstable, false, false);
    try
    {
        scrubber.scrub();
        fail("Expected a CorruptSSTableException to be thrown");
    }
    catch (IOError err) {}

    // with skipCorrupted == true, the corrupt row will be skipped
    scrubber = new Scrubber(cfs, sstable, true, false);
    scrubber.scrub();
    scrubber.close();
    assertEquals(1, cfs.getSSTables().size());

    // verify that we can read all of the rows, and there is now one less row
    rows = cfs.getRangeSlice(Util.range("", ""), null, new IdentityQueryFilter(), 1000);
    assertEquals(1, rows.size());
}