use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.
the class VerifyTest method testVerifyBrokenSSTableMetadata.
@Test
public void testVerifyBrokenSSTableMetadata() throws IOException, WriteTimeoutException {
CompactionManager.instance.disableAutoCompaction();
Keyspace keyspace = Keyspace.open(KEYSPACE);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CORRUPT_CF2);
cfs.truncateBlocking();
fillCF(cfs, 2);
Util.getAll(Util.cmd(cfs).build());
SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
String filenameToCorrupt = sstable.descriptor.filenameFor(Component.STATS);
FileChannel file = new File(filenameToCorrupt).newReadWriteChannel();
file.position(0);
file.write(ByteBufferUtil.bytes(StringUtils.repeat('z', 2)));
file.close();
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 (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(false).build())) {
verifier.verify();
fail("Expected a RuntimeException to be thrown");
} catch (CorruptSSTableException err) {
fail("wrong exception thrown");
} catch (RuntimeException err) {
}
}
use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.
the class SSTableImporter method verifySSTableForImport.
/**
* Verify an sstable for import, throws exception if there is a failure verifying.
*
* @param verifyTokens to verify that the tokens are owned by the current node
* @param verifySSTables to verify the sstables given. If this is false a "quick" verification will be run, just deserializing metadata
* @param extendedVerify to validate the values in the sstables
*/
private void verifySSTableForImport(Descriptor descriptor, Set<Component> components, boolean verifyTokens, boolean verifySSTables, boolean extendedVerify) {
SSTableReader reader = null;
try {
reader = SSTableReader.open(descriptor, components, cfs.metadata);
Verifier.Options verifierOptions = Verifier.options().extendedVerification(extendedVerify).checkOwnsTokens(verifyTokens).quick(!verifySSTables).invokeDiskFailurePolicy(false).mutateRepairStatus(false).build();
try (Verifier verifier = new Verifier(cfs, reader, false, verifierOptions)) {
verifier.verify();
}
} catch (Throwable t) {
throw new RuntimeException("Can't import sstable " + descriptor, t);
} finally {
if (reader != null)
reader.selfRef().release();
}
}
use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.
the class StandaloneVerifier method main.
public static void main(String[] args) {
Options options = Options.parseArgs(args);
initDatabaseDescriptorForTool();
System.out.println("sstableverify using the following options: " + options);
try {
// load keyspace descriptions.
Schema.instance.loadFromDisk(false);
boolean hasFailed = false;
if (Schema.instance.getTableMetadataRef(options.keyspaceName, options.cfName) == null)
throw new IllegalArgumentException(String.format("Unknown keyspace/table %s.%s", options.keyspaceName, options.cfName));
// Do not load sstables since they might be broken
Keyspace keyspace = Keyspace.openWithoutSSTables(options.keyspaceName);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(options.cfName);
OutputHandler handler = new OutputHandler.SystemOutput(options.verbose, options.debug);
Directories.SSTableLister lister = cfs.getDirectories().sstableLister(Directories.OnTxnErr.THROW).skipTemporary(true);
List<SSTableReader> sstables = new ArrayList<>();
// Verify sstables
for (Map.Entry<Descriptor, Set<Component>> entry : lister.list().entrySet()) {
Set<Component> components = entry.getValue();
if (!components.contains(Component.DATA) || !components.contains(Component.PRIMARY_INDEX))
continue;
try {
SSTableReader sstable = SSTableReader.openNoValidation(entry.getKey(), components, cfs);
sstables.add(sstable);
} catch (Exception e) {
JVMStabilityInspector.inspectThrowable(e);
System.err.println(String.format("Error Loading %s: %s", entry.getKey(), e.getMessage()));
if (options.debug)
e.printStackTrace(System.err);
System.exit(1);
}
}
Verifier.Options verifyOptions = Verifier.options().invokeDiskFailurePolicy(false).extendedVerification(options.extended).checkVersion(options.checkVersion).mutateRepairStatus(options.mutateRepairStatus).checkOwnsTokens(!options.tokens.isEmpty()).tokenLookup(ignore -> options.tokens).build();
handler.output("Running verifier with the following options: " + verifyOptions);
for (SSTableReader sstable : sstables) {
try (Verifier verifier = new Verifier(cfs, sstable, handler, true, verifyOptions)) {
verifier.verify();
} catch (Exception e) {
handler.warn(String.format("Error verifying %s: %s", sstable, e.getMessage()), e);
hasFailed = true;
}
}
CompactionManager.instance.finishCompactionsAndShutdown(5, TimeUnit.MINUTES);
// We need that to stop non daemonized threads
System.exit(hasFailed ? 1 : 0);
} catch (Exception e) {
System.err.println(e.getMessage());
if (options.debug)
e.printStackTrace(System.err);
System.exit(1);
}
}
use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.
the class VerifyTest method testVerifyIncorrectDigest.
@Test
public void testVerifyIncorrectDigest() throws IOException, WriteTimeoutException {
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 (Verifier verifier = new Verifier(cfs, sstable, false, Verifier.options().invokeDiskFailurePolicy(false).build())) {
verifier.verify();
fail("Expected a RuntimeException to be thrown");
} catch (RuntimeException err) {
}
}
use of org.apache.cassandra.db.compaction.Verifier in project cassandra by apache.
the class VerifyTest method testExtendedVerifyCorrect.
@Test
public void testExtendedVerifyCorrect() {
CompactionManager.instance.disableAutoCompaction();
Keyspace keyspace = Keyspace.open(KEYSPACE);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF2);
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