Search in sources :

Example 26 with RecordId

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;
    }
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId) FileStoreUtil.findPersistedRecordId(org.apache.jackrabbit.oak.segment.file.FileStoreUtil.findPersistedRecordId)

Example 27 with RecordId

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;
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId)

Example 28 with RecordId

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);
}
Also used : FileStoreUtil.findPersistedRecordId(org.apache.jackrabbit.oak.segment.file.FileStoreUtil.findPersistedRecordId) RecordId(org.apache.jackrabbit.oak.segment.RecordId)

Aggregations

RecordId (org.apache.jackrabbit.oak.segment.RecordId)28 SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)14 Test (org.junit.Test)9 FileStoreUtil.findPersistedRecordId (org.apache.jackrabbit.oak.segment.file.FileStoreUtil.findPersistedRecordId)7 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)4 SegmentNodeBuilder (org.apache.jackrabbit.oak.segment.SegmentNodeBuilder)3 SegmentWriter (org.apache.jackrabbit.oak.segment.SegmentWriter)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 IOException (java.io.IOException)2 UUID (java.util.UUID)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 RecordId.fromString (org.apache.jackrabbit.oak.segment.RecordId.fromString)2 SegmentId (org.apache.jackrabbit.oak.segment.SegmentId)2 SegmentNodeStore (org.apache.jackrabbit.oak.segment.SegmentNodeStore)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Function (com.google.common.base.Function)1 Stopwatch (com.google.common.base.Stopwatch)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 PrintWriter (java.io.PrintWriter)1 Random (java.util.Random)1