use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.
the class TarRevisions method bind.
/**
* Bind this instance to a store.
* @param store store to bind to
* @param idProvider {@code SegmentIdProvider} of the {@code store}
* @param writeInitialNode provider for the initial node in case the journal is empty.
* @throws IOException
*/
synchronized void bind(@Nonnull SegmentStore store, @Nonnull SegmentIdProvider idProvider, @Nonnull Supplier<RecordId> writeInitialNode) throws IOException {
if (head.get() != null) {
return;
}
RecordId persistedId = findPersistedRecordId(store, idProvider, journalFile);
if (persistedId == null) {
head.set(writeInitialNode.get());
} else {
persistedHead.set(persistedId);
head.set(persistedId);
}
}
use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.
the class TarRevisionsTest method concurrentSetHeadFromFunction.
@Test
public void concurrentSetHeadFromFunction() throws InterruptedException, ExecutionException, TimeoutException {
ListeningExecutorService executor = listeningDecorator(newFixedThreadPool(2));
try {
ListenableFuture<Boolean> t1 = executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return null != revisions.setHead(new Function<RecordId, RecordId>() {
@Nullable
@Override
public RecordId apply(RecordId headId) {
return addChild(reader.readNode(headId), "a").getRecordId();
}
});
}
});
ListenableFuture<Boolean> t2 = executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return null != revisions.setHead(new Function<RecordId, RecordId>() {
@Nullable
@Override
public RecordId apply(RecordId headId) {
return addChild(reader.readNode(headId), "b").getRecordId();
}
});
}
});
assertTrue(t1.get(500, MILLISECONDS));
assertTrue(t2.get(500, MILLISECONDS));
SegmentNodeState root = reader.readNode(revisions.getHead());
assertTrue(root.hasChildNode("a"));
assertTrue(root.hasChildNode("b"));
} finally {
executor.shutdown();
}
}
use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.
the class LockBasedSchedulerTest method testSimulatedRaceOnRevisions.
/**
* OAK-7162
*
* This test guards against race conditions which may happen when the head
* state in {@link Revisions} is changed from outside the scheduler. If a
* race condition happens at that point, data from a single commit will be
* lost.
*/
@Test
public void testSimulatedRaceOnRevisions() throws Exception {
final MemoryStore ms = new MemoryStore();
StatisticsProvider statsProvider = StatisticsProvider.NOOP;
SegmentNodeStoreStats stats = new SegmentNodeStoreStats(statsProvider);
final LockBasedScheduler scheduler = LockBasedScheduler.builder(ms.getRevisions(), ms.getReader(), stats).build();
final RecordId initialHead = ms.getRevisions().getHead();
ExecutorService executorService = newFixedThreadPool(10);
final AtomicInteger count = new AtomicInteger();
final Random rand = new Random();
try {
Callable<PropertyState> commitTask = new Callable<PropertyState>() {
@Override
public PropertyState call() throws Exception {
String property = "prop" + count.incrementAndGet();
Commit commit = createCommit(scheduler, property, "value");
SegmentNodeState result = (SegmentNodeState) scheduler.schedule(commit);
return result.getProperty(property);
}
};
Callable<Void> parallelTask = new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.sleep(rand.nextInt(10));
ms.getRevisions().setHead(ms.getRevisions().getHead(), initialHead);
return null;
}
};
List<Future<?>> results = newArrayList();
for (int i = 0; i < 100; i++) {
results.add(executorService.submit(commitTask));
executorService.submit(parallelTask);
}
for (Future<?> result : results) {
assertNotNull("PropertyState must not be null! The corresponding commit got lost because of a race condition.", result.get());
}
} finally {
new ExecutorCloser(executorService).close();
}
}
use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.
the class CheckRepositoryTestBase method corruptPathFromCheckpoint.
protected void corruptPathFromCheckpoint() throws InvalidFileStoreVersionException, IOException {
FileStore fileStore = FileStoreBuilder.fileStoreBuilder(temporaryFolder.getRoot()).withMaxFileSize(256).withSegmentCacheSize(64).build();
SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
SegmentNodeState cp1 = (SegmentNodeState) nodeStore.retrieve(checkpoints.iterator().next());
RecordId bRecordId = ((SegmentNodeState) cp1.getChildNode("b")).getRecordId();
fileStore.close();
corruptRecord(bRecordId, "data00000a.tar");
}
use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.
the class DefaultStandbyReferenceReaderTest method shouldReturnEmptyReferences.
@Test
public void shouldReturnEmptyReferences() throws Exception {
try (FileStore store = newFileStore()) {
SegmentWriter writer = defaultSegmentWriterBuilder("test").build(store);
RecordId id = writer.writeNode(EmptyNodeState.EMPTY_NODE);
writer.flush();
DefaultStandbyReferencesReader reader = new DefaultStandbyReferencesReader(store);
Iterable<String> references = reader.readReferences(id.getSegmentId().asUUID().toString());
assertFalse(references.iterator().hasNext());
}
}
Aggregations