Java Code Examples for org.apache.cassandra.config.DatabaseDescriptor#loadSchemas()

The following examples show how to use org.apache.cassandra.config.DatabaseDescriptor#loadSchemas() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SSTableOfflineRelevel.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
/**
 * @param args a list of sstables whose metadata we are changing
 */
public static void main(String[] args) throws IOException
{
    PrintStream out = System.out;
    if (args.length < 2)
    {
        out.println("This command should be run with Cassandra stopped!");
        out.println("Usage: sstableofflinerelevel [--dry-run] <keyspace> <columnfamily>");
        System.exit(1);
    }
    boolean dryRun = args[0].equals("--dry-run");
    String keyspace = args[args.length - 2];
    String columnfamily = args[args.length - 1];
    DatabaseDescriptor.loadSchemas(false);

    if (Schema.instance.getCFMetaData(keyspace, columnfamily) == null)
        throw new IllegalArgumentException(String.format("Unknown keyspace/columnFamily %s.%s",
                keyspace,
                columnfamily));

    Keyspace ks = Keyspace.openWithoutSSTables(keyspace);
    ColumnFamilyStore cfs = ks.getColumnFamilyStore(columnfamily);
    Directories.SSTableLister lister = cfs.directories.sstableLister().skipTemporary(true);
    Set<SSTableReader> sstables = new HashSet<>();
    for (Map.Entry<Descriptor, Set<Component>> sstable : lister.list().entrySet())
    {
        if (sstable.getKey() != null)
        {
            try
            {
                SSTableReader reader = SSTableReader.open(sstable.getKey());
                sstables.add(reader);
            }
            catch (Throwable t)
            {
                out.println("Couldn't open sstable: "+sstable.getKey().filenameFor(Component.DATA));
                Throwables.propagate(t);
            }
        }
    }
    if (sstables.isEmpty())
    {
        out.println("No sstables to relevel for "+keyspace+"."+columnfamily);
        System.exit(1);
    }
    Relevel rl = new Relevel(sstables);
    rl.relevel(dryRun);
    System.exit(0);

}
 
Example 2
Source File: SSTableLevelResetter.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
/**
 * @param args a list of sstables whose metadata we are changing
 */
public static void main(String[] args) throws IOException
{
    PrintStream out = System.out;
    if (args.length == 0)
    {
        out.println("This command should be run with Cassandra stopped!");
        out.println("Usage: sstablelevelreset <keyspace> <columnfamily>");
        System.exit(1);
    }

    if (!args[0].equals("--really-reset") || args.length != 3)
    {
        out.println("This command should be run with Cassandra stopped, otherwise you will get very strange behavior");
        out.println("Verify that Cassandra is not running and then execute the command like this:");
        out.println("Usage: sstablelevelreset --really-reset <keyspace> <columnfamily>");
        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[1];
        String columnfamily = args[2];
        // 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);
                if (metadata.sstableLevel > 0)
                {
                    out.println("Changing level from " + metadata.sstableLevel + " to 0 on " + descriptor.filenameFor(Component.DATA));
                    descriptor.getMetadataSerializer().mutateLevel(descriptor, 0);
                }
                else
                {
                    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);
}