use of org.apache.jackrabbit.oak.segment.RecordId 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.RecordId in project jackrabbit-oak by apache.
the class DebugTars method filterNodeStates.
private void filterNodeStates(Set<UUID> uuids, List<String> paths, SegmentNodeState state, String path) {
Set<String> localPaths = newTreeSet();
for (PropertyState ps : state.getProperties()) {
if (ps instanceof SegmentPropertyState) {
SegmentPropertyState sps = (SegmentPropertyState) ps;
RecordId recordId = sps.getRecordId();
UUID id = recordId.getSegmentId().asUUID();
if (uuids.contains(id)) {
if (ps.getType().tag() == PropertyType.STRING) {
String val = "";
if (ps.count() > 0) {
// only shows the first value, do we need more?
val = displayString(ps.getValue(Type.STRING, 0));
}
localPaths.add(getLocalPath(path, ps, val, recordId));
} else {
localPaths.add(getLocalPath(path, ps, recordId));
}
}
if (ps.getType().tag() == PropertyType.BINARY) {
// look for extra segment references
for (int i = 0; i < ps.count(); i++) {
Blob b = ps.getValue(Type.BINARY, i);
for (SegmentId sbid : SegmentBlob.getBulkSegmentIds(b)) {
UUID bid = sbid.asUUID();
if (!bid.equals(id) && uuids.contains(bid)) {
localPaths.add(getLocalPath(path, ps, recordId));
}
}
}
}
}
}
RecordId stateId = state.getRecordId();
if (uuids.contains(stateId.getSegmentId().asUUID())) {
localPaths.add(path + " [SegmentNodeState@" + stateId + "]");
}
RecordId templateId = getTemplateId(state);
if (uuids.contains(templateId.getSegmentId().asUUID())) {
localPaths.add(path + "[Template@" + templateId + "]");
}
paths.addAll(localPaths);
for (ChildNodeEntry ce : state.getChildNodeEntries()) {
NodeState c = ce.getNodeState();
if (c instanceof SegmentNodeState) {
filterNodeStates(uuids, paths, (SegmentNodeState) c, path + ce.getName() + "/");
}
}
}
use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.
the class ReadOnlyRevisions method setHead.
@Override
public boolean setHead(@Nonnull RecordId expected, @Nonnull RecordId head, @Nonnull Option... options) {
checkBound();
RecordId id = this.head.get();
return id.equals(expected) && this.head.compareAndSet(id, head);
}
use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.
the class FileStoreUtil method findPersistedRecordId.
/**
* Traverse the journal until a record ID is found that exists in the
* provided segment store.
*
* @param store An instance of {@link SegmentStore}.
* @param idProvider The {@code SegmentIdProvider} of the {@code store}
* @param journal Path to the journal file.
* @return An instance of {@link RecordId}, or {@code null} if none could be
* found.
* @throws IOException If an I/O error occurs.
*/
static RecordId findPersistedRecordId(SegmentStore store, SegmentIdProvider idProvider, File journal) throws IOException {
try (JournalReader journalReader = new JournalReader(journal)) {
while (journalReader.hasNext()) {
JournalEntry entry = journalReader.next();
try {
RecordId id = RecordId.fromString(idProvider, entry.getRevision());
if (store.containsSegment(id.getSegmentId())) {
return id;
}
log.warn("Unable to access revision {}, rewinding...", id);
} catch (IllegalArgumentException ignore) {
log.warn("Skipping invalid record id {}", entry);
}
}
}
return null;
}
use of org.apache.jackrabbit.oak.segment.RecordId 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());
}
}
}
Aggregations