Example usage for org.apache.cassandra.io.sstable.metadata MetadataType STATS

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

Introduction

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

Prototype

MetadataType STATS

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

Click Source Link

Document

Metadata always keep in memory

Usage

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  w  w  .j  a  va2  s  .co  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);
}