use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.
the class TarRevisions method setHead.
/**
* This implementation blocks if a concurrent call is already in progress.
* @param newHead function mapping an record id to the record id to which
* the current head id should be set. If it returns
* {@code null} the head remains unchanged and {@code setHead}
* returns {@code false}.
*
* @param options zero or one timeout options specifying how long to block
* @throws InterruptedException
* @throws IllegalArgumentException on any non recognised {@code option}.
* @see #timeout(long, TimeUnit)
* @see #INFINITY
*/
@Override
public RecordId setHead(@Nonnull Function<RecordId, RecordId> newHead, @Nonnull Option... options) throws InterruptedException {
checkBound();
TimeOutOption timeout = getTimeout(options);
if (rwLock.writeLock().tryLock(timeout.time, timeout.unit)) {
try {
RecordId after = newHead.apply(getHead());
if (after != null) {
head.set(after);
return after;
} else {
return null;
}
} finally {
rwLock.writeLock().unlock();
}
} else {
return null;
}
}
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, JournalFile journalFile) throws IOException {
try (JournalReader journalReader = new JournalReader(journalFile)) {
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 ReadOnlyRevisions method bind.
/**
* Bind this instance to a store.
*
* @param store store to bind to
* @param idProvider {@code SegmentIdProvider} of the {@code store}
* @throws IOException
*/
synchronized void bind(@Nonnull SegmentStore store, @Nonnull SegmentIdProvider idProvider) throws IOException {
if (head.get() != null) {
return;
}
RecordId persistedId = findPersistedRecordId(store, idProvider, journalFile);
if (persistedId == null) {
throw new IllegalStateException("Cannot start readonly store from empty journal");
}
head.set(persistedId);
}
Aggregations