System.err.println("usage: upgrade <olddir> <newdir>");
System.exit(1);
}
} else if ("backup".equals(command)) {
if (args.length == 2) {
FileStore store = new FileStore(new File(args[0]), 256, false);
FileStoreBackup.backup(
new SegmentNodeStore(store), new File(args[1]));
store.close();
} else {
System.err.println("usage: backup <repository> <backup>");
System.exit(1);
}
} else if ("tarmk".equals(command)) {
if (args.length == 0) {
System.err.println("usage: tarmk <path> [id...]");
System.exit(1);
} else {
System.out.println("TarMK " + args[0]);
File file = new File(args[0]);
FileStore store = new FileStore(file, 256, false);
try {
if (args.length == 1) {
Map<UUID, List<UUID>> idmap = Maps.newHashMap();
int dataCount = 0;
long dataSize = 0;
int bulkCount = 0;
long bulkSize = 0;
for (UUID uuid : store.getSegmentIds()) {
if (SegmentIdFactory.isDataSegmentId(uuid)) {
Segment segment = store.readSegment(uuid);
dataCount++;
dataSize += segment.size();
idmap.put(uuid, segment.getReferencedIds());
} else if (SegmentIdFactory.isBulkSegmentId(uuid)) {
bulkCount++;
bulkSize += store.readSegment(uuid).size();
idmap.put(uuid, Collections.<UUID>emptyList());
}
}
System.out.println("Total size:");
System.out.format(
"%6dMB in %6d data segments%n",
dataSize / (1024 * 1024), dataCount);
System.out.format(
"%6dMB in %6d bulk segments%n",
bulkSize / (1024 * 1024), bulkCount);
Set<UUID> garbage = newHashSet(idmap.keySet());
Queue<UUID> queue = Queues.newArrayDeque();
queue.add(store.getJournal("root").getHead().getSegmentId());
while (!queue.isEmpty()) {
UUID id = queue.remove();
if (garbage.remove(id)) {
queue.addAll(idmap.get(id));
}
}
dataCount = 0;
dataSize = 0;
bulkCount = 0;
bulkSize = 0;
for (UUID uuid : garbage) {
if (SegmentIdFactory.isDataSegmentId(uuid)) {
dataCount++;
dataSize += store.readSegment(uuid).size();
} else if (SegmentIdFactory.isBulkSegmentId(uuid)) {
bulkCount++;
bulkSize += store.readSegment(uuid).size();
}
}
System.out.println("Available for garbage collection:");
System.out.format(
"%6dMB in %6d data segments%n",
dataSize / (1024 * 1024), dataCount);
System.out.format(
"%6dMB in %6d bulk segments%n",
bulkSize / (1024 * 1024), bulkCount);
} else {
for (int i = 1; i < args.length; i++) {
UUID uuid = UUID.fromString(args[i]);
System.out.println(store.readSegment(uuid));
}
}
} finally {
store.close();
}
}
} else {
System.err.println("Unknown command: " + command);
System.exit(1);