Search in sources :

Example 1 with Upgrader

use of org.apache.cassandra.db.compaction.Upgrader 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);
    }
}
Also used : CmdLineOptions(org.apache.cassandra.tools.BulkLoader.CmdLineOptions) Upgrader(org.apache.cassandra.db.compaction.Upgrader) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) Directories(org.apache.cassandra.db.Directories) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) OutputHandler(org.apache.cassandra.utils.OutputHandler)

Aggregations

ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 Directories (org.apache.cassandra.db.Directories)1 Keyspace (org.apache.cassandra.db.Keyspace)1 Upgrader (org.apache.cassandra.db.compaction.Upgrader)1 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)1 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)1 CmdLineOptions (org.apache.cassandra.tools.BulkLoader.CmdLineOptions)1 OutputHandler (org.apache.cassandra.utils.OutputHandler)1