use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class CheckRepositoryTestBase method addInvalidRevision.
protected void addInvalidRevision() throws InvalidFileStoreVersionException, IOException, CommitFailedException {
FileStore fileStore = FileStoreBuilder.fileStoreBuilder(temporaryFolder.getRoot()).withMaxFileSize(256).withSegmentCacheSize(64).build();
SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
NodeBuilder builder = nodeStore.getRoot().builder();
// add a new child "z"
addChildWithBlobProperties(nodeStore, builder, "z", 5);
// add a new property value to existing child "a"
addChildWithBlobProperties(nodeStore, builder, "a", 1);
NodeState after = nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
// get record number to corrupt (NODE record for "z")
SegmentNodeState child = (SegmentNodeState) after.getChildNode("z");
int zRecordNumber = child.getRecordId().getRecordNumber();
// get record number to corrupt (NODE record for "a")
child = (SegmentNodeState) after.getChildNode("a");
int aRecordNumber = child.getRecordId().getRecordNumber();
fileStore.close();
corruptRecord(zRecordNumber);
corruptRecord(aRecordNumber);
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class SegmentTarCheckpoints method removeAll.
@Override
public long removeAll() {
SegmentNodeState head = store.getHead();
NodeBuilder builder = head.builder();
NodeBuilder cps = builder.getChildNode("checkpoints");
long cnt = cps.getChildNodeCount(Integer.MAX_VALUE);
builder.setChildNode("checkpoints");
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 getInfo.
@Override
public Map<String, String> getInfo(String cp) {
SegmentNodeState head = store.getHead();
NodeState props = head.getChildNode("checkpoints").getChildNode(cp).getChildNode("properties");
if (props.exists()) {
Map<String, String> info = new HashMap<>();
for (PropertyState p : props.getProperties()) {
info.put(p.getName(), p.getValue(Type.STRING));
}
return info;
} else {
return null;
}
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class LockBasedScheduler method execute.
private NodeState execute(Commit commit) throws CommitFailedException, InterruptedException {
// only do the merge if there are some changes to commit
if (commit.hasChanges()) {
refreshHead(true);
SegmentNodeState before = head.get();
SegmentNodeState after = commit.apply(before);
if (revisions.setHead(before.getRecordId(), after.getRecordId())) {
head.set(after);
contentChanged(after.getChildNode(ROOT), commit.info());
refreshHead(true);
}
}
return head.get().getChildNode(ROOT);
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class LockBasedScheduler method schedule.
@Override
public NodeState schedule(@Nonnull Commit commit, SchedulerOption... schedulingOptions) throws CommitFailedException {
boolean queued = false;
try {
long queuedTime = -1;
if (commitSemaphore.availablePermits() < 1) {
queuedTime = System.nanoTime();
stats.onCommitQueued();
queued = true;
}
commitSemaphore.acquire();
try {
if (queued) {
long dequeuedTime = System.nanoTime();
stats.dequeuedAfter(dequeuedTime - queuedTime);
stats.onCommitDequeued();
}
long beforeCommitTime = System.nanoTime();
SegmentNodeState merged = (SegmentNodeState) execute(commit);
commit.applied(merged);
long afterCommitTime = System.nanoTime();
stats.committedAfter(afterCommitTime - beforeCommitTime);
stats.onCommit();
return merged;
} finally {
commitSemaphore.release();
}
} catch (InterruptedException e) {
currentThread().interrupt();
throw new CommitFailedException("Segment", 2, "Merge interrupted", e);
} catch (SegmentOverflowException e) {
throw new CommitFailedException("Segment", 3, "Merge failed", e);
}
}
Aggregations