public static void main(String args[]) throws IOException
{
Options options = Options.parseArgs(args);
try
{
OutputHandler handler = new OutputHandler.SystemOutput(false, options.debug);
// Migrate sstables from pre-#2749 to the correct location
if (Directories.sstablesNeedsMigration())
{
if (!options.migrate)
{
System.err.println("Detected a pre-1.1 data directory layout. For this tool to work, a migration " +
"must be performed to the 1.1+ format for directories and filenames. Re-run " +
TOOL_NAME + " with the --" + MIGRATE_OPTION + " option to automatically " +
"migrate *all* keyspaces and column families to the new layout.");
System.exit(1);
}
handler.output("Detected a pre-1.1 data directory layout. All keyspace and column family directories " +
"will be migrated to the 1.1+ format.");
Directories.migrateSSTables();
}
// load keyspace descriptions.
DatabaseDescriptor.loadSchemas();
if (Schema.instance.getCFMetaData(options.keyspace, options.cf) == null)
throw new IllegalArgumentException(String.format("Unknown keyspace/columnFamily %s.%s",
options.keyspace,
options.cf));
Table table = Table.openWithoutSSTables(options.keyspace);
ColumnFamilyStore cfs = table.getColumnFamilyStore(options.cf);
Directories.SSTableLister lister = cfs.directories.sstableLister();
if (options.snapshot != null)
lister.onlyBackups(true).snapshots(options.snapshot);
else
lister.includeBackups(false);
Collection<SSTableReader> readers = new ArrayList<SSTableReader>();
// 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.metadata);
if (sstable.descriptor.version.equals(Descriptor.Version.CURRENT))
continue;
readers.add(sstable);
}
catch (Exception e)
{
System.err.println(String.format("Error Loading %s: %s", entry.getKey(), e.getMessage()));
if (options.debug)
e.printStackTrace(System.err);
continue;
}
}
int numSSTables = readers.size();
handler.output("Found " + numSSTables + " sstables that need upgrading.");
for (SSTableReader sstable : readers)
{
try
{