use of org.apache.jackrabbit.oak.segment.SegmentNodeBuilder 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);
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeBuilder in project jackrabbit-oak by apache.
the class LockBasedScheduler method removeCheckpoint.
@Override
public boolean removeCheckpoint(String name) {
checkNotNull(name);
// try 5 times
for (int i = 0; i < 5; i++) {
if (commitSemaphore.tryAcquire()) {
try {
refreshHead(true);
SegmentNodeState state = head.get();
SegmentNodeBuilder builder = state.builder();
NodeBuilder cp = builder.child("checkpoints").child(name);
if (cp.exists()) {
cp.remove();
SegmentNodeState newState = builder.getNodeState();
if (revisions.setHead(state.getRecordId(), newState.getRecordId())) {
refreshHead(false);
return true;
}
}
} finally {
commitSemaphore.release();
}
}
}
return false;
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeBuilder in project jackrabbit-oak by apache.
the class FileStoreIT method nonBlockingROStore.
@Test
public void nonBlockingROStore() throws Exception {
FileStore store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
// first 1kB
store.flush();
SegmentNodeState base = store.getHead();
SegmentNodeBuilder builder = base.builder();
builder.setProperty("step", "a");
store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
// second 1kB
store.flush();
ReadOnlyFileStore ro = null;
try {
ro = fileStoreBuilder(getFileStoreFolder()).buildReadOnly();
assertEquals(store.getRevisions().getHead(), ro.getRevisions().getHead());
} finally {
if (ro != null) {
ro.close();
}
store.close();
}
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeBuilder in project jackrabbit-oak by apache.
the class FileStoreIT method setRevisionTest.
@Test
public void setRevisionTest() throws Exception {
try (FileStore store = fileStoreBuilder(getFileStoreFolder()).build()) {
RecordId id1 = store.getRevisions().getHead();
SegmentNodeState base = store.getHead();
SegmentNodeBuilder builder = base.builder();
builder.setProperty("step", "a");
store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
RecordId id2 = store.getRevisions().getHead();
store.flush();
try (ReadOnlyFileStore roStore = fileStoreBuilder(getFileStoreFolder()).buildReadOnly()) {
assertEquals(id2, roStore.getRevisions().getHead());
roStore.setRevision(id1.toString());
assertEquals(id1, roStore.getRevisions().getHead());
roStore.setRevision(id2.toString());
assertEquals(id2, roStore.getRevisions().getHead());
}
}
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeBuilder in project jackrabbit-oak by apache.
the class StandbyClientSyncExecution method execute.
void execute(StandbyClient client) throws Exception {
RecordId remoteHead = getHead(client);
if (remoteHead == null) {
log.error("Unable to fetch remote head");
return;
}
if (remoteHead.equals(store.getHead().getRecordId())) {
return;
}
Stopwatch stopwatch = Stopwatch.createStarted();
SegmentNodeState before = store.getHead();
SegmentNodeBuilder builder = before.builder();
SegmentNodeState current = newSegmentNodeState(remoteHead);
compareAgainstBaseState(client, current, before, builder);
store.getRevisions().setHead(before.getRecordId(), remoteHead);
log.info("Updated head state in {}", stopwatch);
}
Aggregations