use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class FileStoreIT method testRecovery.
@Test
public void testRecovery() throws Exception {
FileStore store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
store.flush();
RandomAccessFile data0 = new RandomAccessFile(new File(getFileStoreFolder(), "data00000a.tar"), "r");
long pos0 = data0.length();
SegmentNodeState base = store.getHead();
SegmentNodeBuilder builder = base.builder();
builder.setProperty("step", "a");
store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
store.flush();
long pos1 = data0.length();
data0.close();
base = store.getHead();
builder = base.builder();
builder.setProperty("step", "b");
store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
store.close();
store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
assertEquals("b", store.getHead().getString("step"));
store.close();
RandomAccessFile file = new RandomAccessFile(new File(getFileStoreFolder(), "data00000a.tar"), "rw");
file.setLength(pos1);
file.close();
store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
assertEquals("a", store.getHead().getString("step"));
store.close();
file = new RandomAccessFile(new File(getFileStoreFolder(), "data00000a.tar"), "rw");
file.setLength(pos0);
file.close();
store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
assertFalse(store.getHead().hasProperty("step"));
store.close();
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class SegmentTarCheckpoints method removeUnreferenced.
@Override
public long removeUnreferenced() {
SegmentNodeState head = store.getHead();
Set<String> refs = getReferencedCheckpoints(head.getChildNode("root"));
NodeBuilder builder = head.builder();
NodeBuilder cps = builder.getChildNode("checkpoints");
long cnt = 0;
for (String c : cps.getChildNodeNames()) {
if (refs.contains(c)) {
continue;
}
cps.getChildNode(c).remove();
cnt++;
}
if (store.getRevisions().setHead(head.getRecordId(), asSegmentNodeState(builder).getRecordId())) {
return cnt;
} else {
return -1;
}
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class SegmentTarCheckpoints method setInfoProperty.
@Override
public int setInfoProperty(String cp, String name, String value) {
SegmentNodeState head = store.getHead();
NodeBuilder builder = head.builder();
NodeBuilder props = builder.getChildNode("checkpoints").getChildNode(cp).getChildNode("properties");
if (props.exists()) {
if (value == null) {
props.removeProperty(name);
} else {
props.setProperty(name, value, Type.STRING);
}
if (store.getRevisions().setHead(head.getRecordId(), asSegmentNodeState(builder).getRecordId())) {
return 1;
} else {
return -1;
}
} else {
return 0;
}
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class SegmentTarCheckpoints method remove.
@Override
public int remove(String cp) {
SegmentNodeState head = store.getHead();
NodeBuilder builder = head.builder();
NodeBuilder cpn = builder.getChildNode("checkpoints").getChildNode(cp);
if (cpn.exists()) {
cpn.remove();
if (store.getRevisions().setHead(head.getRecordId(), asSegmentNodeState(builder).getRecordId())) {
return 1;
} else {
return -1;
}
} else {
return 0;
}
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class StandbyClientSyncExecution method execute.
void execute() throws Exception {
RecordId remoteHead = getHead();
if (remoteHead == null) {
throw new IllegalStateException("Unable to fetch remote head");
}
if (remoteHead.equals(store.getHead().getRecordId())) {
return;
}
long t = System.currentTimeMillis();
SegmentNodeState before = store.getHead();
SegmentNodeBuilder builder = before.builder();
SegmentNodeState current = newSegmentNodeState(remoteHead);
compareAgainstBaseState(current, before, builder);
boolean ok = store.getRevisions().setHead(before.getRecordId(), remoteHead);
store.flush();
log.debug("updated head state successfully: {} in {}ms.", ok, System.currentTimeMillis() - t);
}
Aggregations