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 FileStoreBackupImpl method backup.
@Override
public void backup(@Nonnull SegmentReader reader, @Nonnull Revisions revisions, @Nonnull File destination) throws IOException, InvalidFileStoreVersionException {
Stopwatch watch = Stopwatch.createStarted();
SegmentGCOptions gcOptions = SegmentGCOptions.defaultGCOptions().setOffline();
FileStoreBuilder builder = fileStoreBuilder(destination).withDefaultMemoryMapping();
if (USE_FAKE_BLOBSTORE) {
builder.withBlobStore(new BasicReadOnlyBlobStore());
}
builder.withGCOptions(gcOptions);
FileStore backup = builder.build();
SegmentNodeState current = reader.readHeadState(revisions);
try {
int gen = current.getRecordId().getSegmentId().getGcGeneration();
SegmentBufferWriter bufferWriter = new SegmentBufferWriter(backup.getSegmentIdProvider(), backup.getReader(), "b", gen);
SegmentWriter writer = new SegmentWriter(backup, backup.getReader(), backup.getSegmentIdProvider(), backup.getBlobStore(), new WriterCacheManager.Default(), bufferWriter);
Compactor compactor = new Compactor(backup.getReader(), writer, backup.getBlobStore(), Suppliers.ofInstance(false), gcOptions);
compactor.setContentEqualityCheck(true);
SegmentNodeState head = backup.getHead();
SegmentNodeState after = compactor.compact(head, current, head);
if (after != null) {
backup.getRevisions().setHead(head.getRecordId(), after.getRecordId());
}
} finally {
backup.close();
}
backup = fileStoreBuilder(destination).withDefaultMemoryMapping().withGCOptions(gcOptions).build();
try {
cleanup(backup);
} finally {
backup.close();
}
watch.stop();
log.info("Backup finished in {}.", watch);
}
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);
}
Aggregations