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();
}
}
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());
}
}
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));
}
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);
}
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();
}
}
Aggregations