use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.
the class VerifyTest method testBrokenComponentHelper.
private void testBrokenComponentHelper(Component componentToBreak) throws IOException {
CompactionManager.instance.disableAutoCompaction();
Keyspace keyspace = Keyspace.open(KEYSPACE);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CORRUPT_CF2);
fillCF(cfs, 2);
SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().build())) {
// still not corrupt, should pass
verifier.verify();
}
String filenameToCorrupt = sstable.descriptor.filenameFor(componentToBreak);
try (FileChannel fileChannel = new File(filenameToCorrupt).newReadWriteChannel()) {
fileChannel.truncate(3);
}
try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).build())) {
verifier.verify();
fail("should throw exception");
} catch (CorruptSSTableException e) {
// expected
}
}
use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.
the class VerifyTest method testQuick.
@Test
public void testQuick() throws IOException {
CompactionManager.instance.disableAutoCompaction();
Keyspace keyspace = Keyspace.open(KEYSPACE);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CORRUPT_CF);
fillCF(cfs, 2);
Util.getAll(Util.cmd(cfs).build());
SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
try (RandomAccessReader file = RandomAccessReader.open(new File(sstable.descriptor.filenameFor(Component.DIGEST)))) {
Long correctChecksum = file.readLong();
writeChecksum(++correctChecksum, sstable.descriptor.filenameFor(Component.DIGEST));
}
try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).build())) {
verifier.verify();
fail("Expected a CorruptSSTableException to be thrown");
} catch (CorruptSSTableException err) {
}
try (// with quick = true we don't verify the digest
Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).quick(true).build())) {
verifier.verify();
}
try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).build())) {
verifier.verify();
fail("Expected a RuntimeException to be thrown");
} catch (CorruptSSTableException err) {
}
}
use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.
the class VerifyTest method testExtendedVerifyCounterCorrectUncompressed.
@Test
public void testExtendedVerifyCounterCorrectUncompressed() {
CompactionManager.instance.disableAutoCompaction();
Keyspace keyspace = Keyspace.open(KEYSPACE);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(COUNTER_CF4);
fillCounterCF(cfs, 2);
SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().extendedVerification(true).invokeDiskFailurePolicy(true).build())) {
verifier.verify();
} catch (CorruptSSTableException err) {
fail("Unexpected CorruptSSTableException");
}
}
use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.
the class VerifyTest method testVerifyCorruptRowCorrectDigest.
@Test
public void testVerifyCorruptRowCorrectDigest() throws IOException, WriteTimeoutException {
CompactionManager.instance.disableAutoCompaction();
Keyspace keyspace = Keyspace.open(KEYSPACE);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CORRUPT_CF2);
fillCF(cfs, 2);
Util.getAll(Util.cmd(cfs).build());
SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
// overwrite one row with garbage
long row0Start = sstable.getPosition(PartitionPosition.ForKey.get(ByteBufferUtil.bytes("0"), cfs.getPartitioner()), SSTableReader.Operator.EQ).position;
long row1Start = sstable.getPosition(PartitionPosition.ForKey.get(ByteBufferUtil.bytes("1"), cfs.getPartitioner()), SSTableReader.Operator.EQ).position;
long startPosition = row0Start < row1Start ? row0Start : row1Start;
long endPosition = row0Start < row1Start ? row1Start : row0Start;
FileChannel file = new File(sstable.getFilename()).newReadWriteChannel();
file.position(startPosition);
file.write(ByteBufferUtil.bytes(StringUtils.repeat('z', 2)));
file.close();
if (ChunkCache.instance != null)
ChunkCache.instance.invalidateFile(sstable.getFilename());
// Update the Digest to have the right Checksum
writeChecksum(simpleFullChecksum(sstable.getFilename()), sstable.descriptor.filenameFor(Component.DIGEST));
try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).build())) {
// First a simple verify checking digest, which should succeed
try {
verifier.verify();
} catch (CorruptSSTableException err) {
fail("Simple verify should have succeeded as digest matched");
}
}
try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).extendedVerification(true).build())) {
// Now try extended verify
try {
verifier.verify();
} catch (CorruptSSTableException err) {
return;
}
fail("Expected a CorruptSSTableException to be thrown");
}
}
use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.
the class VerifyTest method testVerifyCorrectUncompressed.
@Test
public void testVerifyCorrectUncompressed() {
CompactionManager.instance.disableAutoCompaction();
Keyspace keyspace = Keyspace.open(KEYSPACE);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF3);
fillCF(cfs, 2);
SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
try (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(true).build())) {
verifier.verify();
} catch (CorruptSSTableException err) {
fail("Unexpected CorruptSSTableException");
}
}
Aggregations