use of org.apache.cassandra.db.Keyspace in project cassandra by apache.
the class StandaloneScrubber method main.
public static void main(String[] args) {
Options options = Options.parseArgs(args);
Util.initDatabaseDescriptor();
try {
// load keyspace descriptions.
Schema.instance.loadFromDisk(false);
if (Schema.instance.getKeyspaceMetadata(options.keyspaceName) == null)
throw new IllegalArgumentException(String.format("Unknown keyspace %s", options.keyspaceName));
// Do not load sstables since they might be broken
Keyspace keyspace = Keyspace.openWithoutSSTables(options.keyspaceName);
ColumnFamilyStore cfs = null;
for (ColumnFamilyStore c : keyspace.getValidColumnFamilies(true, false, options.cfName)) {
if (c.name.equals(options.cfName)) {
cfs = c;
break;
}
}
if (cfs == null)
throw new IllegalArgumentException(String.format("Unknown table %s.%s", options.keyspaceName, options.cfName));
String snapshotName = "pre-scrub-" + System.currentTimeMillis();
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<>();
// Scrub sstables
for (Map.Entry<Descriptor, Set<Component>> entry : lister.list().entrySet()) {
Set<Component> components = entry.getValue();
if (!components.contains(Component.DATA))
continue;
try {
SSTableReader sstable = SSTableReader.openNoValidation(entry.getKey(), components, cfs);
sstables.add(sstable);
File snapshotDirectory = Directories.getSnapshotDirectory(sstable.descriptor, snapshotName);
sstable.createLinks(snapshotDirectory.getPath());
} 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.out.println(String.format("Pre-scrub sstables snapshotted into snapshot %s", snapshotName));
if (!options.manifestCheckOnly) {
for (SSTableReader sstable : sstables) {
try (LifecycleTransaction txn = LifecycleTransaction.offline(OperationType.SCRUB, sstable)) {
// make sure originals are deleted and avoid NPE if index is missing, CASSANDRA-9591
txn.obsoleteOriginals();
try (Scrubber scrubber = new Scrubber(cfs, txn, options.skipCorrupted, handler, !options.noValidate)) {
scrubber.scrub();
} catch (Throwable t) {
if (!cfs.rebuildOnFailedScrub(t)) {
System.out.println(t.getMessage());
throw t;
}
}
} catch (Exception e) {
System.err.println(String.format("Error scrubbing %s: %s", sstable, e.getMessage()));
e.printStackTrace(System.err);
}
}
}
// Check (and repair) manifests
checkManifest(cfs.getCompactionStrategyManager(), cfs, sstables);
CompactionManager.instance.finishCompactionsAndShutdown(5, TimeUnit.MINUTES);
LifecycleTransaction.waitForDeletions();
// We need that to stop non daemonized threads
System.exit(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.Keyspace in project cassandra by apache.
the class StandaloneUpgrader method main.
public static void main(String[] args) {
Options options = Options.parseArgs(args);
Util.initDatabaseDescriptor();
try {
// load keyspace descriptions.
Schema.instance.loadFromDisk(false);
if (Schema.instance.getTableMetadataRef(options.keyspace, options.cf) == null)
throw new IllegalArgumentException(String.format("Unknown keyspace/table %s.%s", options.keyspace, options.cf));
Keyspace keyspace = Keyspace.openWithoutSSTables(options.keyspace);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(options.cf);
OutputHandler handler = new OutputHandler.SystemOutput(false, options.debug);
Directories.SSTableLister lister = cfs.getDirectories().sstableLister(Directories.OnTxnErr.THROW);
if (options.snapshot != null)
lister.onlyBackups(true).snapshots(options.snapshot);
else
lister.includeBackups(false);
Collection<SSTableReader> readers = new ArrayList<>();
// Upgrade 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);
if (sstable.descriptor.version.equals(SSTableFormat.Type.current().info.getLatestVersion())) {
sstable.selfRef().release();
continue;
}
readers.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);
}
}
int numSSTables = readers.size();
handler.output("Found " + numSSTables + " sstables that need upgrading.");
for (SSTableReader sstable : readers) {
try (LifecycleTransaction txn = LifecycleTransaction.offline(OperationType.UPGRADE_SSTABLES, sstable)) {
Upgrader upgrader = new Upgrader(cfs, txn, handler);
upgrader.upgrade(options.keepSource);
} catch (Exception e) {
System.err.println(String.format("Error upgrading %s: %s", sstable, e.getMessage()));
if (options.debug)
e.printStackTrace(System.err);
} finally {
// we should have released this through commit of the LifecycleTransaction,
// but in case the upgrade failed (or something else went wrong) make sure we don't retain a reference
sstable.selfRef().ensureReleased();
}
}
CompactionManager.instance.finishCompactionsAndShutdown(5, TimeUnit.MINUTES);
LifecycleTransaction.waitForDeletions();
System.exit(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.Keyspace in project cassandra by apache.
the class StandaloneVerifier method main.
public static void main(String[] args) {
Options options = Options.parseArgs(args);
Util.initDatabaseDescriptor();
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);
boolean extended = options.extended;
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);
}
}
for (SSTableReader sstable : sstables) {
try {
try (Verifier verifier = new Verifier(cfs, sstable, handler, true)) {
verifier.verify(extended);
} catch (CorruptSSTableException cs) {
System.err.println(String.format("Error verifying %s: %s", sstable, cs.getMessage()));
hasFailed = true;
}
} catch (Exception e) {
System.err.println(String.format("Error verifying %s: %s", sstable, e.getMessage()));
e.printStackTrace(System.err);
}
}
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.Keyspace in project cassandra by apache.
the class Schema method reload.
private void reload(KeyspaceMetadata previous, KeyspaceMetadata updated) {
Keyspace keyspace = getKeyspaceInstance(updated.name);
if (keyspace != null)
keyspace.setMetadata(updated);
MapDifference<TableId, TableMetadata> tablesDiff = previous.tables.diff(updated.tables);
MapDifference<TableId, ViewMetadata> viewsDiff = previous.views.diff(updated.views);
MapDifference<String, TableMetadata> indexesDiff = previous.tables.indexesDiff(updated.tables);
// clean up after removed entries
tablesDiff.entriesOnlyOnLeft().values().forEach(table -> metadataRefs.remove(table.id));
viewsDiff.entriesOnlyOnLeft().values().forEach(view -> metadataRefs.remove(view.metadata.id));
indexesDiff.entriesOnlyOnLeft().values().forEach(indexTable -> indexMetadataRefs.remove(Pair.create(indexTable.keyspace, indexTable.indexName().get())));
// load up new entries
tablesDiff.entriesOnlyOnRight().values().forEach(table -> metadataRefs.put(table.id, new TableMetadataRef(table)));
viewsDiff.entriesOnlyOnRight().values().forEach(view -> metadataRefs.put(view.metadata.id, new TableMetadataRef(view.metadata)));
indexesDiff.entriesOnlyOnRight().values().forEach(indexTable -> indexMetadataRefs.put(Pair.create(indexTable.keyspace, indexTable.indexName().get()), new TableMetadataRef(indexTable)));
// refresh refs to updated ones
tablesDiff.entriesDiffering().values().forEach(diff -> metadataRefs.get(diff.rightValue().id).set(diff.rightValue()));
viewsDiff.entriesDiffering().values().forEach(diff -> metadataRefs.get(diff.rightValue().metadata.id).set(diff.rightValue().metadata));
indexesDiff.entriesDiffering().values().stream().map(MapDifference.ValueDifference::rightValue).forEach(indexTable -> indexMetadataRefs.get(Pair.create(indexTable.keyspace, indexTable.indexName().get())).set(indexTable));
}
Aggregations