Search in sources :

Example 6 with RecordId

use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.

the class FileStoreIT method segmentOverflow.

// See OAK-2049
@Test
public void segmentOverflow() throws Exception {
    for (int n = 1; n < 255; n++) {
        // 255 = ListRecord.LEVEL_SIZE
        FileStore store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
        SegmentWriter writer = store.getWriter();
        // adding 15 strings with 16516 bytes each
        for (int k = 0; k < 15; k++) {
            // 16516 = (Segment.MEDIUM_LIMIT - 1 + 2 + 3)
            // 1 byte per char, 2 byte to store the length and 3 bytes for the
            // alignment to the integer boundary
            writer.writeString(Strings.repeat("abcdefghijklmno".substring(k, k + 1), SegmentTestConstants.MEDIUM_LIMIT - 1));
        }
        // adding 14280 bytes. 1 byte per char, and 2 bytes to store the length
        RecordId x = writer.writeString(Strings.repeat("x", 14278));
        // writer.length == 262052
        // Adding 765 bytes (255 recordIds)
        // This should cause the current segment to flush
        List<RecordId> list = Collections.nCopies(n, x);
        writer.writeList(list);
        writer.flush();
        // Don't close the store in a finally clause as if a failure happens
        // this will also fail an cover up the earlier exception
        store.close();
    }
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentWriter(org.apache.jackrabbit.oak.segment.SegmentWriter) Test(org.junit.Test)

Example 7 with RecordId

use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.

the class TarRevisionsTest method setHead.

@Test
public void setHead() throws IOException {
    RecordId headId = revisions.getHead();
    SegmentNodeState newRoot = addChild(reader.readNode(headId), "a");
    assertTrue(revisions.setHead(headId, newRoot.getRecordId()));
    store.flush();
    try (JournalReader reader = createJournalReader()) {
        assertTrue(reader.hasNext());
        assertEquals(newRoot.getRecordId().toString10(), reader.next().getRevision());
    }
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) Test(org.junit.Test)

Example 8 with RecordId

use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.

the class TarRevisionsTest method concurrentSetHead.

@Test
public void concurrentSetHead() {
    RecordId headId = revisions.getHead();
    SegmentNodeState rootA = addChild(reader.readNode(headId), "a");
    SegmentNodeState rootB = addChild(reader.readNode(headId), "a");
    assertTrue(revisions.setHead(headId, rootA.getRecordId()));
    assertFalse(revisions.setHead(headId, rootB.getRecordId()));
    assertEquals(rootA, reader.readHeadState(revisions));
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) Test(org.junit.Test)

Example 9 with RecordId

use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.

the class StandbyClientSyncExecution method execute.

void execute(StandbyClient client) throws Exception {
    RecordId remoteHead = getHead(client);
    if (remoteHead == null) {
        log.error("Unable to fetch remote head");
        return;
    }
    if (remoteHead.equals(store.getHead().getRecordId())) {
        return;
    }
    Stopwatch stopwatch = Stopwatch.createStarted();
    SegmentNodeState before = store.getHead();
    SegmentNodeBuilder builder = before.builder();
    SegmentNodeState current = newSegmentNodeState(remoteHead);
    compareAgainstBaseState(client, current, before, builder);
    store.getRevisions().setHead(before.getRecordId(), remoteHead);
    log.info("Updated head state in {}", stopwatch);
}
Also used : Stopwatch(com.google.common.base.Stopwatch) SegmentNodeBuilder(org.apache.jackrabbit.oak.segment.SegmentNodeBuilder) RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

Example 10 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 to
 * {@link #setHead(Function, Option...)} is already in
 * progress.
 *
 * @param options   zero or one expedite option for expediting this call
 * @throws IllegalArgumentException  on any non recognised {@code option}.
 * @see #EXPEDITE_OPTION
 */
@Override
public boolean setHead(@Nonnull RecordId expected, @Nonnull RecordId head, @Nonnull Option... options) {
    checkBound();
    // If the expedite option was specified we acquire the write lock instead of the read lock.
    // This will cause this thread to get the lock before all threads currently waiting to
    // enter the read lock. See also the class comment of ReadWriteLock.
    Lock lock = isExpedited(options) ? rwLock.writeLock() : rwLock.readLock();
    lock.lock();
    try {
        RecordId id = this.head.get();
        return id.equals(expected) && this.head.compareAndSet(id, head);
    } finally {
        lock.unlock();
    }
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId) FileStoreUtil.findPersistedRecordId(org.apache.jackrabbit.oak.segment.file.FileStoreUtil.findPersistedRecordId) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

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