Set<SegmentId> garbage = newHashSet(idmap.keySet());
Queue<SegmentId> queue = Queues.newArrayDeque();
queue.add(store.getHead().getRecordId().getSegmentId());
while (!queue.isEmpty()) {
SegmentId id = queue.remove();
if (garbage.remove(id)) {
queue.addAll(idmap.get(id));
}
}
dataCount = 0;
dataSize = 0;
bulkCount = 0;
bulkSize = 0;
for (SegmentId id : garbage) {
if (id.isDataSegmentId()) {
dataCount++;
dataSize += id.getSegment().size();
} else if (id.isBulkSegmentId()) {
bulkCount++;
bulkSize += id.getSegment().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 {
Pattern pattern = Pattern.compile(
"([0-9a-f-]+)|([0-9a-f-]+:[0-9a-f]+)?(/.*)?");
for (int i = 1; i < args.length; i++) {
Matcher matcher = pattern.matcher(args[i]);
if (!matcher.matches()) {
System.err.println("Unknown argument: " + args[i]);
} else if (matcher.group(1) != null) {
UUID uuid = UUID.fromString(matcher.group(1));
SegmentId id = store.getTracker().getSegmentId(
uuid.getMostSignificantBits(),
uuid.getLeastSignificantBits());
System.out.println(id.getSegment());
} else {
RecordId id = store.getHead().getRecordId();
if (matcher.group(2) != null) {
id = RecordId.fromString(
store.getTracker(), matcher.group(2));