+ ns.getChildNodeCount(Integer.MAX_VALUE)
+ " checkpoints");
}
if ("rm-all".equals(op)) {
long time = System.currentTimeMillis();
SegmentNodeState head = store.getHead();
NodeBuilder builder = head.builder();
NodeBuilder cps = builder.getChildNode("checkpoints");
long cnt = cps.getChildNodeCount(Integer.MAX_VALUE);
builder.setChildNode("checkpoints");
boolean ok = store.setHead(head,
(SegmentNodeState) builder.getNodeState());
time = System.currentTimeMillis() - time;
if (ok) {
System.out.println("Removed " + cnt + " checkpoints in "
+ time + "ms.");
} else {
System.err.println("Failed to remove all checkpoints.");
}
}
if ("rm-unreferenced".equals(op)) {
long time = System.currentTimeMillis();
SegmentNodeState head = store.getHead();
String ref = null;
PropertyState refPS = head.getChildNode("root")
.getChildNode(":async").getProperty("async");
if (refPS != null) {
ref = refPS.getValue(Type.STRING);
}
if (ref != null) {
System.out
.println("Referenced checkpoint from /:async@async is "
+ ref);
}
NodeBuilder builder = head.builder();
NodeBuilder cps = builder.getChildNode("checkpoints");
long cnt = 0;
for (String c : cps.getChildNodeNames()) {
if (c.equals(ref)) {
continue;
}
cps.getChildNode(c).remove();
cnt++;
}
boolean ok = cnt == 0 || store.setHead(head,
(SegmentNodeState) builder.getNodeState());
time = System.currentTimeMillis() - time;
if (ok) {
System.out.println("Removed " + cnt + " checkpoints in "
+ time + "ms.");
} else {
System.err.println("Failed to remove unreferenced checkpoints.");
}
}
if ("rm".equals(op)) {
if (args.length != 3) {
System.err.println("Missing checkpoint id");
System.exit(1);
}
long time = System.currentTimeMillis();
String cp = args[2];
SegmentNodeState head = store.getHead();
NodeBuilder builder = head.builder();
NodeBuilder cpn = builder.getChildNode("checkpoints")
.getChildNode(cp);
if (cpn.exists()) {
cpn.remove();