Example usage for org.apache.cassandra.io.sstable Component STATS

List of usage examples for org.apache.cassandra.io.sstable Component STATS

Introduction

In this page you can find the example usage for org.apache.cassandra.io.sstable Component STATS.

Prototype

Component STATS

To view the source code for org.apache.cassandra.io.sstable Component STATS.

Click Source Link

Usage

From source file:com.chaordicsystems.sstableconverter.SSTableConverter.java

License:Apache License

public static Collection<SSTableReader> readSSTables(final IPartitioner srcPartitioner, File srcDir,
        final CFMetaData metadata, final OutputHandler outputHandler) {
    final List<SSTableReader> sstables = new ArrayList<SSTableReader>();
    srcDir.list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            if (new File(dir, name).isDirectory())
                return false;
            Pair<Descriptor, Component> p = SSTable.tryComponentFromFilename(dir, name);
            Descriptor desc = p == null ? null : p.left;
            if (p == null || !p.right.equals(Component.DATA) || desc.temporary)
                return false;

            if (!new File(desc.filenameFor(Component.PRIMARY_INDEX)).exists()) {
                outputHandler.output(String.format("Skipping file %s because index is missing", name));
                return false;
            }/*w ww . j a va  2  s . c om*/

            Set<Component> components = new HashSet<Component>();
            components.add(Component.DATA);
            components.add(Component.PRIMARY_INDEX);
            if (new File(desc.filenameFor(Component.COMPRESSION_INFO)).exists())
                components.add(Component.COMPRESSION_INFO);
            if (new File(desc.filenameFor(Component.STATS)).exists())
                components.add(Component.STATS);

            try {
                sstables.add(SSTableReader.openForBatch(desc, components, srcPartitioner, metadata));
            } catch (IOException e) {
                outputHandler
                        .output(String.format("Skipping file %s, error opening it: %s", name, e.getMessage()));
            }
            return false;
        }
    });
    return sstables;
}

From source file:com.scylladb.tools.SSTableToCQL.java

License:Open Source License

private void addFile(final List<SSTableReader> sstables, File dir, String name) {
    Pair<Descriptor, Component> p = SSTable.tryComponentFromFilename(dir, name);
    Descriptor desc = p == null ? null : p.left;
    if (p == null || !p.right.equals(Component.DATA) || desc.type.isTemporary) {
        return;/*  w w w.j a  va2  s. co  m*/
    }

    if (!new File(desc.filenameFor(Component.PRIMARY_INDEX)).exists()) {
        logger.info("Skipping file {} because index is missing", name);
        return;
    }

    CFMetaData metadata = getCFMetaData(keyspace, desc.cfname);
    if (metadata == null) {
        logger.info("Skipping file {}: column family {}.{} doesn't exist", name, keyspace, desc.cfname);
        return;
    }

    Set<Component> components = new HashSet<>();
    components.add(Component.DATA);
    components.add(Component.PRIMARY_INDEX);
    if (new File(desc.filenameFor(Component.SUMMARY)).exists()) {
        components.add(Component.SUMMARY);
    }
    if (new File(desc.filenameFor(Component.COMPRESSION_INFO)).exists()) {
        components.add(Component.COMPRESSION_INFO);
    }
    if (new File(desc.filenameFor(Component.STATS)).exists()) {
        components.add(Component.STATS);
    }

    try {
        // To conserve memory, open SSTableReaders without bloom
        // filters and discard
        // the index summary after calculating the file sections to
        // stream and the estimated
        // number of keys for each endpoint. See CASSANDRA-5555 for
        // details.
        SSTableReader sstable = openForBatch(desc, components, metadata, getPartitioner());
        sstables.add(sstable);
    } catch (IOException e) {
        logger.warn("Skipping file {}, error opening it: {}", name, e.getMessage());
    }
}

From source file:com.wenyu.cassandra.tools.SSTableLevelToZero.java

License:Apache License

/**
 * @param args a list of sstables whose metadata we are changing
 *///from w  ww .  j  a v  a  2 s  . c o m
public static void main(String[] args) throws IOException {
    PrintStream out = System.out;
    if (args.length < 3) {
        out.println("This command should be run with Cassandra stopped!");
        out.println("Usage: sstableleveltozero <keyspace> <columnfamily> <sstablefiles_fullpath>");
        System.exit(1);
    }

    // TODO several daemon threads will run from here.
    // So we have to explicitly call System.exit.
    try {
        // load keyspace descriptions.
        DatabaseDescriptor.loadSchemas();

        String keyspaceName = args[0];
        String columnfamily = args[1];
        String sstables = args[2];

        Set<String> sstableSet = new HashSet<>();
        for (String sstable : sstables.split(",")) {
            sstable = sstable.trim();
            if (sstable.length() == 0) {
                continue;
            }
            sstableSet.add(sstable);
        }

        // validate columnfamily
        if (Schema.instance.getCFMetaData(keyspaceName, columnfamily) == null) {
            System.err.println("ColumnFamily not found: " + keyspaceName + "/" + columnfamily);
            System.exit(1);
        }

        Keyspace keyspace = Keyspace.openWithoutSSTables(keyspaceName);
        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(columnfamily);
        boolean foundSSTable = false;
        for (Map.Entry<Descriptor, Set<Component>> sstable : cfs.directories.sstableLister().list()
                .entrySet()) {
            if (sstable.getValue().contains(Component.STATS)) {
                foundSSTable = true;
                Descriptor descriptor = sstable.getKey();

                StatsMetadata metadata = (StatsMetadata) descriptor.getMetadataSerializer()
                        .deserialize(descriptor, MetadataType.STATS);
                String path = descriptor.filenameFor(Component.DATA);
                if (metadata.sstableLevel > 0 && sstableSet.contains(path)) {
                    out.println("Changing level from " + metadata.sstableLevel + " to 0 on "
                            + descriptor.filenameFor(Component.DATA));
                    descriptor.getMetadataSerializer().mutateLevel(descriptor, 0);
                } else if (metadata.sstableLevel <= 0 && sstableSet.contains(path)) {
                    out.println("Skipped " + descriptor.filenameFor(Component.DATA)
                            + " since it is already on level 0");
                }
            }
        }

        if (!foundSSTable) {
            out.println("Found no sstables, did you give the correct keyspace/columnfamily?");
        }
    } catch (Throwable t) {
        JVMStabilityInspector.inspectThrowable(t);
        t.printStackTrace();
        System.exit(1);
    }
    System.exit(0);
}