Search in sources :

Example 1 with TransactionMode

use of cz.o2.proxima.repository.TransactionMode in project proxima-platform by O2-Czech-Republic.

the class TransactionResourceManager method findFamilyForTransactionalAttribute.

private Map<AttributeDescriptor<?>, DirectAttributeFamilyDescriptor> findFamilyForTransactionalAttribute(List<AttributeDescriptor<?>> attributes) {
    Preconditions.checkArgument(!attributes.isEmpty(), "Cannot return families for empty attribute list");
    TransactionMode mode = attributes.get(0).getTransactionMode();
    Preconditions.checkArgument(attributes.stream().allMatch(a -> a.getTransactionMode() == mode), "All passed attributes must have the same transaction mode. Got attributes %s.", attributes);
    List<DirectAttributeFamilyDescriptor> candidates = attributes.stream().flatMap(a -> a.getTransactionalManagerFamilies().stream()).distinct().map(direct::findFamilyByName).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    List<AttributeDescriptor<?>> requestResponseState = candidates.stream().flatMap(f -> f.getAttributes().stream().filter(a -> !a.equals(commitDesc))).sorted(Comparator.comparing(AttributeDescriptor::getName)).collect(Collectors.toList());
    Preconditions.checkState(requestResponseState.equals(Lists.newArrayList(requestDesc, responseDesc, stateDesc)), "Should have received only families for unique transactional attributes, " + "got %s for %s with transactional mode %s", candidates, attributes, mode);
    Map<AttributeDescriptor<?>, DirectAttributeFamilyDescriptor> res = candidates.stream().flatMap(f -> f.getAttributes().stream().map(a -> Pair.of(a, f))).collect(Collectors.toMap(Pair::getFirst, Pair::getSecond));
    direct.getRepository().getAllFamilies(true).filter(af -> af.getAttributes().contains(commitDesc)).forEach(af -> res.put(commitDesc, direct.getFamilyByName(af.getName())));
    return res;
}
Also used : Arrays(java.util.Arrays) Partition(cz.o2.proxima.storage.Partition) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) Flags(cz.o2.proxima.transaction.Request.Flags) Wildcard(cz.o2.proxima.repository.EntityAwareAttributeDescriptor.Wildcard) InetAddress(java.net.InetAddress) ExceptionUtils(cz.o2.proxima.util.ExceptionUtils) CachedView(cz.o2.proxima.direct.view.CachedView) StreamElement(cz.o2.proxima.storage.StreamElement) ForwardingObserver(cz.o2.proxima.direct.commitlog.CommitLogObservers.ForwardingObserver) Pair(cz.o2.proxima.util.Pair) Duration(java.time.Duration) Map(java.util.Map) Optionals(cz.o2.proxima.util.Optionals) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TransactionMode(cz.o2.proxima.repository.TransactionMode) ThreadSafe(javax.annotation.concurrent.ThreadSafe) ObserveHandle(cz.o2.proxima.direct.commitlog.ObserveHandle) CommitCallback(cz.o2.proxima.direct.core.CommitCallback) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) BiConsumer(cz.o2.proxima.functional.BiConsumer) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Internal(cz.o2.proxima.annotations.Internal) KeyValue(cz.o2.proxima.direct.randomaccess.KeyValue) Response(cz.o2.proxima.transaction.Response) State(cz.o2.proxima.transaction.State) Optional(java.util.Optional) DirectDataOperator(cz.o2.proxima.direct.core.DirectDataOperator) Getter(lombok.Getter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) OnlineAttributeWriter(cz.o2.proxima.direct.core.OnlineAttributeWriter) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) AccessLevel(lombok.AccessLevel) Regular(cz.o2.proxima.repository.EntityAwareAttributeDescriptor.Regular) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ObserveHandleUtils(cz.o2.proxima.direct.commitlog.ObserveHandleUtils) Commit(cz.o2.proxima.transaction.Commit) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) Nullable(javax.annotation.Nullable) DeclaredThreadSafe(cz.o2.proxima.annotations.DeclaredThreadSafe) Classpath(cz.o2.proxima.util.Classpath) Request(cz.o2.proxima.transaction.Request) AttributeDescriptor(cz.o2.proxima.repository.AttributeDescriptor) CommitLogObserver(cz.o2.proxima.direct.commitlog.CommitLogObserver) KeyAttribute(cz.o2.proxima.transaction.KeyAttribute) AttributeFamilyDescriptor(cz.o2.proxima.repository.AttributeFamilyDescriptor) UnknownHostException(java.net.UnknownHostException) TimeUnit(java.util.concurrent.TimeUnit) DirectAttributeFamilyDescriptor(cz.o2.proxima.direct.core.DirectAttributeFamilyDescriptor) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) DirectAttributeFamilyDescriptor(cz.o2.proxima.direct.core.DirectAttributeFamilyDescriptor) Optional(java.util.Optional) TransactionMode(cz.o2.proxima.repository.TransactionMode) AttributeDescriptor(cz.o2.proxima.repository.AttributeDescriptor)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 DeclaredThreadSafe (cz.o2.proxima.annotations.DeclaredThreadSafe)1 Internal (cz.o2.proxima.annotations.Internal)1 CommitLogObserver (cz.o2.proxima.direct.commitlog.CommitLogObserver)1 ForwardingObserver (cz.o2.proxima.direct.commitlog.CommitLogObservers.ForwardingObserver)1 CommitLogReader (cz.o2.proxima.direct.commitlog.CommitLogReader)1 ObserveHandle (cz.o2.proxima.direct.commitlog.ObserveHandle)1 ObserveHandleUtils (cz.o2.proxima.direct.commitlog.ObserveHandleUtils)1 CommitCallback (cz.o2.proxima.direct.core.CommitCallback)1 DirectAttributeFamilyDescriptor (cz.o2.proxima.direct.core.DirectAttributeFamilyDescriptor)1 DirectDataOperator (cz.o2.proxima.direct.core.DirectDataOperator)1 OnlineAttributeWriter (cz.o2.proxima.direct.core.OnlineAttributeWriter)1 KeyValue (cz.o2.proxima.direct.randomaccess.KeyValue)1 CachedView (cz.o2.proxima.direct.view.CachedView)1 BiConsumer (cz.o2.proxima.functional.BiConsumer)1 AttributeDescriptor (cz.o2.proxima.repository.AttributeDescriptor)1 AttributeFamilyDescriptor (cz.o2.proxima.repository.AttributeFamilyDescriptor)1