Search in sources :

Example 1 with OutputHandler

use of org.apache.cassandra.utils.OutputHandler in project cassandra by apache.

the class BulkLoader method load.

public static void load(LoaderOptions options) throws BulkLoadException {
    DatabaseDescriptor.toolInitialization();
    OutputHandler handler = new OutputHandler.SystemOutput(options.verbose, options.debug);
    SSTableLoader loader = new SSTableLoader(options.directory.getAbsoluteFile(), new ExternalClient(options.hosts, options.nativePort, options.authProvider, options.storagePort, options.sslStoragePort, options.serverEncOptions, buildSSLOptions(options.clientEncOptions)), handler, options.connectionsPerHost);
    DatabaseDescriptor.setStreamThroughputOutboundMegabitsPerSec(options.throttle);
    DatabaseDescriptor.setInterDCStreamThroughputOutboundMegabitsPerSec(options.interDcThrottle);
    StreamResultFuture future = null;
    ProgressIndicator indicator = new ProgressIndicator();
    try {
        if (options.noProgress) {
            future = loader.stream(options.ignores);
        } else {
            future = loader.stream(options.ignores, indicator);
        }
    } catch (Exception e) {
        JVMStabilityInspector.inspectThrowable(e);
        System.err.println(e.getMessage());
        if (e.getCause() != null) {
            System.err.println(e.getCause());
        }
        e.printStackTrace(System.err);
        throw new BulkLoadException(e);
    }
    try {
        future.get();
        if (!options.noProgress) {
            indicator.printSummary(options.connectionsPerHost);
        }
        // Give sockets time to gracefully close
        Thread.sleep(1000);
    // System.exit(0); // We need that to stop non daemonized threads
    } catch (Exception e) {
        System.err.println("Streaming to the following hosts failed:");
        System.err.println(loader.getFailedHosts());
        e.printStackTrace(System.err);
        throw new BulkLoadException(e);
    }
}
Also used : SSTableLoader(org.apache.cassandra.io.sstable.SSTableLoader) OutputHandler(org.apache.cassandra.utils.OutputHandler) IOException(java.io.IOException)

Example 2 with OutputHandler

use of org.apache.cassandra.utils.OutputHandler in project cassandra by apache.

the class StandaloneSSTableUtil method main.

public static void main(String[] args) {
    Options options = Options.parseArgs(args);
    try {
        // load keyspace descriptions.
        Util.initDatabaseDescriptor();
        Schema.instance.loadFromDisk(false);
        TableMetadata metadata = Schema.instance.getTableMetadata(options.keyspaceName, options.cfName);
        if (metadata == null)
            throw new IllegalArgumentException(String.format("Unknown keyspace/table %s.%s", options.keyspaceName, options.cfName));
        OutputHandler handler = new OutputHandler.SystemOutput(options.verbose, options.debug);
        if (options.cleanup) {
            handler.output("Cleanuping up...");
            LifecycleTransaction.removeUnfinishedLeftovers(metadata);
        } else {
            handler.output("Listing files...");
            listFiles(options, metadata, handler);
        }
        System.exit(0);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        if (options.debug)
            e.printStackTrace(System.err);
        System.exit(1);
    }
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) CmdLineOptions(org.apache.cassandra.tools.BulkLoader.CmdLineOptions) OutputHandler(org.apache.cassandra.utils.OutputHandler) IOException(java.io.IOException)

Example 3 with OutputHandler

use of org.apache.cassandra.utils.OutputHandler 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);
    }
}
Also used : CmdLineOptions(org.apache.cassandra.tools.BulkLoader.CmdLineOptions) 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) File(java.io.File)

Example 4 with OutputHandler

use of org.apache.cassandra.utils.OutputHandler 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)

Example 5 with OutputHandler

use of org.apache.cassandra.utils.OutputHandler 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);
    }
}
Also used : CmdLineOptions(org.apache.cassandra.tools.BulkLoader.CmdLineOptions) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException) 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) Descriptor(org.apache.cassandra.io.sstable.Descriptor) OutputHandler(org.apache.cassandra.utils.OutputHandler) Component(org.apache.cassandra.io.sstable.Component)

Aggregations

OutputHandler (org.apache.cassandra.utils.OutputHandler)5 CmdLineOptions (org.apache.cassandra.tools.BulkLoader.CmdLineOptions)4 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)3 Directories (org.apache.cassandra.db.Directories)3 Keyspace (org.apache.cassandra.db.Keyspace)3 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)3 IOException (java.io.IOException)2 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)2 File (java.io.File)1 Upgrader (org.apache.cassandra.db.compaction.Upgrader)1 Component (org.apache.cassandra.io.sstable.Component)1 CorruptSSTableException (org.apache.cassandra.io.sstable.CorruptSSTableException)1 Descriptor (org.apache.cassandra.io.sstable.Descriptor)1 SSTableLoader (org.apache.cassandra.io.sstable.SSTableLoader)1 TableMetadata (org.apache.cassandra.schema.TableMetadata)1