use of cz.o2.proxima.direct.commitlog.CommitLogReader in project proxima-platform by O2-Czech-Republic.
the class TransactionResourceManager method runObservations.
/**
* Observe all transactional families with given observer.
*
* @param name name of the observer (will be appended with name of the family)
* @param requestObserver the observer (need not be synchronized)
*/
@Override
public void runObservations(String name, BiConsumer<StreamElement, Pair<Long, Object>> updateConsumer, CommitLogObserver requestObserver) {
final CommitLogObserver effectiveObserver;
if (isNotThreadSafe(requestObserver)) {
effectiveObserver = requestObserver;
} else {
effectiveObserver = new ThreadPooledObserver(direct.getContext().getExecutorService(), requestObserver, getDeclaredParallelism(requestObserver).orElse(Runtime.getRuntime().availableProcessors()));
}
List<Set<String>> families = direct.getRepository().getAllEntities().filter(EntityDescriptor::isTransactional).flatMap(e -> e.getAllAttributes().stream()).filter(a -> a.getTransactionMode() != TransactionMode.NONE).map(AttributeDescriptor::getTransactionalManagerFamilies).map(Sets::newHashSet).distinct().collect(Collectors.toList());
CountDownLatch initializedLatch = new CountDownLatch(families.size());
families.stream().map(this::toRequestStatePair).forEach(p -> {
DirectAttributeFamilyDescriptor requestFamily = p.getFirst();
DirectAttributeFamilyDescriptor stateFamily = p.getSecond();
String consumerName = name + "-" + requestFamily.getDesc().getName();
log.info("Starting to observe family {} with URI {} and associated state family {} as {}", requestFamily, requestFamily.getDesc().getStorageUri(), stateFamily, consumerName);
CommitLogReader reader = Optionals.get(requestFamily.getCommitLogReader());
CachedView view = stateViews.get(stateFamily);
if (view == null) {
view = Optionals.get(stateFamily.getCachedView());
Duration ttl = Duration.ofMillis(cleanupIntervalMs);
stateViews.put(stateFamily, view);
view.assign(view.getPartitions(), updateConsumer, ttl);
}
initializedLatch.countDown();
serverObservedFamilies.put(requestFamily, reader.observe(consumerName, repartitionHookForBeingActive(stateFamily, reader.getPartitions().size(), effectiveObserver)));
});
ExceptionUtils.unchecked(initializedLatch::await);
}
use of cz.o2.proxima.direct.commitlog.CommitLogReader in project proxima-platform by O2-Czech-Republic.
the class CommitLogReaderTest method testCommitLogReaderFetchOffsetDefaults.
@Test
public void testCommitLogReaderFetchOffsetDefaults() {
CommitLogReader commitLogReader = spy(CommitLogReader.class);
when(commitLogReader.hasExternalizableOffsets()).thenReturn(false);
assertThrows(UnsupportedOperationException.class, () -> commitLogReader.fetchOffsets(Position.NEWEST, Collections.emptyList()));
when(commitLogReader.hasExternalizableOffsets()).thenReturn(true);
assertThrows(IllegalStateException.class, () -> commitLogReader.fetchOffsets(Position.NEWEST, Collections.emptyList()));
}
use of cz.o2.proxima.direct.commitlog.CommitLogReader in project proxima-platform by O2-Czech-Republic.
the class DirectAttributeFamilyProxyDescriptor method getPartitionedCachedView.
private static Optional<CachedView> getPartitionedCachedView(AttrLookup lookup, Context context, AttributeFamilyProxyDescriptor desc) {
if (desc.getTargetFamilyRead().getAccess().canReadCommitLog() && !desc.getTargetFamilyWrite().getAccess().isReadonly() && desc.getTargetFamilyRead().getAccess().canCreateCachedView()) {
Optional<CommitLogReader> maybeReader = getCommitLogReader(lookup, context, desc);
Optional<OnlineAttributeWriter> maybeWriter = getWriter(lookup, context, desc).map(AttributeWriterBase::online);
if (maybeReader.isPresent() && maybeWriter.isPresent()) {
return Optional.of(new LocalCachedPartitionedView(desc.getTargetFamilyRead().getEntity(), maybeReader.get(), maybeWriter.get()));
}
}
return Optional.empty();
}
use of cz.o2.proxima.direct.commitlog.CommitLogReader in project proxima-platform by O2-Czech-Republic.
the class CommitLogReaderTest method testThroughputLimitedCommitLogReaderAsFactory.
@Test
public void testThroughputLimitedCommitLogReaderAsFactory() {
ThroughputLimiter limiter = ThroughputLimiter.NoOpThroughputLimiter.INSTANCE;
CommitLogReader limitedReader = CommitLogReaders.withThroughputLimit(reader, limiter);
CommitLogReader cloned = limitedReader.asFactory().apply(repo);
assertTrue(limitedReader.getClass().isAssignableFrom(cloned.getClass()));
}
use of cz.o2.proxima.direct.commitlog.CommitLogReader in project proxima-platform by O2-Czech-Republic.
the class CommitLogReaderTest method testOffsetExternalizer.
@Test
public void testOffsetExternalizer() {
CommitLogReader commitLogReader = spy(CommitLogReader.class);
when(commitLogReader.hasExternalizableOffsets()).thenReturn(false);
assertThrows(UnsupportedOperationException.class, commitLogReader::getOffsetExternalizer);
when(commitLogReader.hasExternalizableOffsets()).thenReturn(true);
assertThrows(IllegalStateException.class, commitLogReader::getOffsetExternalizer);
}
Aggregations