Search in sources :

Example 1 with AttributeFamilyProxyDescriptor

use of cz.o2.proxima.repository.AttributeFamilyProxyDescriptor 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();
}
Also used : LocalCachedPartitionedView(cz.o2.proxima.direct.view.LocalCachedPartitionedView) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader)

Example 2 with AttributeFamilyProxyDescriptor

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

the class DirectDataOperator method dependencyOrdered.

/**
 * Create list of families ordered by dependencies between them (non-proxy first).
 */
private List<AttributeFamilyDescriptor> dependencyOrdered(Stream<AttributeFamilyDescriptor> families) {
    Set<AttributeFamilyDescriptor> available = new HashSet<>();
    List<AttributeFamilyDescriptor> resolved = new ArrayList<>();
    Set<AttributeFamilyDescriptor> toResolve = families.collect(Collectors.toSet());
    while (!toResolve.isEmpty()) {
        // prevent infinite cycles
        List<AttributeFamilyDescriptor> remove = new ArrayList<>();
        List<AttributeFamilyDescriptor> add = new ArrayList<>();
        toResolve.stream().filter(af -> !available.contains(af)).forEachOrdered(af -> {
            if (!af.isProxy()) {
                available.add(af);
                resolved.add(af);
                remove.add(af);
            } else {
                AttributeFamilyProxyDescriptor proxy = af.toProxy();
                if (available.contains(proxy.getTargetFamilyRead()) && available.contains(proxy.getTargetFamilyWrite())) {
                    available.add(af);
                    resolved.add(af);
                    remove.add(af);
                } else if (!available.contains(proxy.getTargetFamilyRead())) {
                    add.add(proxy.getTargetFamilyRead());
                } else {
                    add.add(proxy.getTargetFamilyWrite());
                }
            }
        });
        if (add.isEmpty() && remove.isEmpty()) {
            throw new IllegalStateException("Cannot make progress in resolving families " + toResolve.stream().map(AttributeFamilyDescriptor::getName).collect(Collectors.toList()) + ", currently resolved " + available.stream().map(AttributeFamilyDescriptor::getName).collect(Collectors.toList()));
        }
        toResolve.addAll(add);
        remove.forEach(toResolve::remove);
    }
    return resolved;
}
Also used : Arrays(java.util.Arrays) BatchLogReader(cz.o2.proxima.direct.batch.BatchLogReader) ConfigConstants(cz.o2.proxima.repository.ConfigConstants) CommitLogReaders(cz.o2.proxima.direct.commitlog.CommitLogReaders) StorageType(cz.o2.proxima.storage.StorageType) TransactionalCachedView(cz.o2.proxima.direct.transaction.TransactionalCachedView) ExceptionUtils(cz.o2.proxima.util.ExceptionUtils) CachedView(cz.o2.proxima.direct.view.CachedView) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Pair(cz.o2.proxima.util.Pair) UnaryFunction(cz.o2.proxima.functional.UnaryFunction) Map(java.util.Map) TransactionResourceManager(cz.o2.proxima.direct.transaction.TransactionResourceManager) AttributeFamilyProxyDescriptor(cz.o2.proxima.repository.AttributeFamilyProxyDescriptor) URI(java.net.URI) Collection(java.util.Collection) Set(java.util.Set) TransactionMode(cz.o2.proxima.repository.TransactionMode) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ConfigRepository(cz.o2.proxima.repository.ConfigRepository) Stream(java.util.stream.Stream) Internal(cz.o2.proxima.annotations.Internal) DataOperator(cz.o2.proxima.repository.DataOperator) Optional(java.util.Optional) ThroughputLimiter(cz.o2.proxima.storage.ThroughputLimiter) Getter(lombok.Getter) ServerTransactionManager(cz.o2.proxima.direct.transaction.ServerTransactionManager) DataAccessorLoader(cz.o2.proxima.storage.internal.DataAccessorLoader) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ClientTransactionManager(cz.o2.proxima.direct.transaction.ClientTransactionManager) Factory(cz.o2.proxima.functional.Factory) Validate(cz.o2.proxima.repository.Repository.Validate) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) RandomAccessReader(cz.o2.proxima.direct.randomaccess.RandomAccessReader) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) TransactionalOnlineAttributeWriter(cz.o2.proxima.direct.transaction.TransactionalOnlineAttributeWriter) Classpath(cz.o2.proxima.util.Classpath) Repository(cz.o2.proxima.repository.Repository) Config(com.typesafe.config.Config) AttributeDescriptor(cz.o2.proxima.repository.AttributeDescriptor) MoreObjects(com.google.common.base.MoreObjects) AttributeFamilyDescriptor(cz.o2.proxima.repository.AttributeFamilyDescriptor) BatchLogReaders(cz.o2.proxima.direct.batch.BatchLogReaders) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) AttributeFamilyProxyDescriptor(cz.o2.proxima.repository.AttributeFamilyProxyDescriptor) ArrayList(java.util.ArrayList) AttributeFamilyDescriptor(cz.o2.proxima.repository.AttributeFamilyDescriptor) HashSet(java.util.HashSet)

Example 3 with AttributeFamilyProxyDescriptor

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

the class DirectDataOperatorTest method testReplicationProxies.

@Test
public void testReplicationProxies() {
    repo.reloadConfig(true, ConfigFactory.load("test-replication-proxy.conf").resolve());
    EntityDescriptor dummy = repo.getEntity("dummy");
    // attribute _d should be proxy to
    // _dummyReplicationMasterSlave_write$_d
    // and _dummyReplicationMasterSlave_replicated$_d
    AttributeDescriptor<Object> _d = dummy.getAttribute("_d", true);
    assertTrue(_d.isProxy());
    Set<AttributeFamilyDescriptor> families = repo.getFamiliesForAttribute(_d);
    assertEquals(1, families.size());
    AttributeFamilyDescriptor primary = Iterables.getOnlyElement(families);
    assertTrue("Family " + primary + " must be proxy", primary.isProxy());
    AttributeFamilyProxyDescriptor proxy = (AttributeFamilyProxyDescriptor) primary;
    assertEquals("proxy::replication_dummy-replication-proxied-slave_replicated::" + "replication_dummy-replication-proxied-slave_write", primary.getName());
    assertEquals("replication_dummy-replication-proxied-slave_replicated", proxy.getTargetFamilyRead().getName());
    assertEquals("replication_dummy-replication-proxied-slave_write", proxy.getTargetFamilyWrite().getName());
    assertFalse(proxy.getTargetFamilyRead().isProxy());
    assertFalse(proxy.getTargetFamilyWrite().isProxy());
    assertEquals(1, proxy.getAttributes().size());
    AttributeProxyDescriptor<?> attr;
    attr = (AttributeProxyDescriptor<?>) _d;
    assertNotNull(attr.getWriteTransform());
    assertEquals("_d", attr.getWriteTransform().asElementWise().fromProxy("_d"));
    assertEquals("_d", attr.getWriteTransform().asElementWise().toProxy("_d"));
    assertNotNull(attr.getReadTransform());
    assertEquals("_d", attr.getReadTransform().asElementWise().fromProxy("_d"));
    assertEquals("_d", attr.getReadTransform().asElementWise().toProxy("_d"));
    // attribute dummy.data should be proxy to _d
    attr = (AttributeProxyDescriptor<?>) dummy.getAttribute("data");
    assertNotNull(attr.getWriteTransform());
    assertNotNull(attr.getReadTransform());
    assertEquals("data", attr.getWriteTransform().asElementWise().toProxy("_d"));
    assertEquals("data", attr.getReadTransform().asElementWise().toProxy("_d"));
    assertEquals("_d", attr.getWriteTransform().asElementWise().fromProxy("data"));
    assertEquals("_d", attr.getReadTransform().asElementWise().fromProxy("data"));
    families = repo.getFamiliesForAttribute(attr);
    assertEquals(2, families.size());
    primary = families.stream().filter(af -> af.getType() == StorageType.PRIMARY).findAny().orElse(null);
    assertNotNull(primary);
    assertTrue(primary.isProxy());
    proxy = (AttributeFamilyProxyDescriptor) primary;
    assertEquals("proxy::proxy::replication_dummy-replication-proxied-slave_replicated" + "::replication_dummy-replication-proxied-slave_write::proxy" + "::replication_dummy-replication-proxied-slave_replicated" + "::replication_dummy-replication-proxied-slave_write", primary.getName());
    assertEquals("proxy::replication_dummy-replication-proxied-slave_replicated::" + "replication_dummy-replication-proxied-slave_write", proxy.getTargetFamilyRead().getName());
    assertEquals("proxy::replication_dummy-replication-proxied-slave_replicated::" + "replication_dummy-replication-proxied-slave_write", proxy.getTargetFamilyWrite().getName());
    assertTrue(proxy.getTargetFamilyRead().isProxy());
    assertTrue(proxy.getTargetFamilyWrite().isProxy());
    assertEquals(1, proxy.getAttributes().size());
}
Also used : Arrays(java.util.Arrays) TestTracker(cz.o2.proxima.storage.watermark.GlobalWatermarkThroughputLimiterTest.TestTracker) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) StorageType(cz.o2.proxima.storage.StorageType) DummyFilter(cz.o2.proxima.util.DummyFilter) EventDataToDummy(cz.o2.proxima.transform.EventDataToDummy) CachedView(cz.o2.proxima.direct.view.CachedView) StreamElement(cz.o2.proxima.storage.StreamElement) TransformationRunner(cz.o2.proxima.util.TransformationRunner) Map(java.util.Map) AttributeFamilyProxyDescriptor(cz.o2.proxima.repository.AttributeFamilyProxyDescriptor) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) TransformationDescriptor(cz.o2.proxima.repository.TransformationDescriptor) Optionals(cz.o2.proxima.util.Optionals) TestUtils(cz.o2.proxima.util.TestUtils) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) GlobalWatermarkThroughputLimiter(cz.o2.proxima.storage.watermark.GlobalWatermarkThroughputLimiter) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ConfigRepository(cz.o2.proxima.repository.ConfigRepository) KeyValue(cz.o2.proxima.direct.randomaccess.KeyValue) Assert.assertFalse(org.junit.Assert.assertFalse) Accept(cz.o2.proxima.storage.internal.AbstractDataAccessorFactory.Accept) Optional(java.util.Optional) ElementWiseTransformation(cz.o2.proxima.transform.ElementWiseTransformation) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ThroughputLimiter(cz.o2.proxima.storage.ThroughputLimiter) AttributeProxyDescriptor(cz.o2.proxima.repository.AttributeProxyDescriptor) Iterables(com.google.common.collect.Iterables) LimitedCommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReaders.LimitedCommitLogReader) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) ConfigFactory(com.typesafe.config.ConfigFactory) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) RandomAccessReader(cz.o2.proxima.direct.randomaccess.RandomAccessReader) PassthroughFilter(cz.o2.proxima.storage.PassthroughFilter) Config(com.typesafe.config.Config) Assert.assertNotNull(org.junit.Assert.assertNotNull) AttributeDescriptor(cz.o2.proxima.repository.AttributeDescriptor) Assert.assertTrue(org.junit.Assert.assertTrue) CommitLogObserver(cz.o2.proxima.direct.commitlog.CommitLogObserver) IOException(java.io.IOException) Test(org.junit.Test) AttributeFamilyDescriptor(cz.o2.proxima.repository.AttributeFamilyDescriptor) NotSerializableException(java.io.NotSerializableException) ReplicationRunner.runAttributeReplicas(cz.o2.proxima.util.ReplicationRunner.runAttributeReplicas) TimeUnit(java.util.concurrent.TimeUnit) GlobalWatermarkTracker(cz.o2.proxima.storage.watermark.GlobalWatermarkTracker) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) AttributeFamilyProxyDescriptor(cz.o2.proxima.repository.AttributeFamilyProxyDescriptor) AttributeFamilyDescriptor(cz.o2.proxima.repository.AttributeFamilyDescriptor) Test(org.junit.Test)

Example 4 with AttributeFamilyProxyDescriptor

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

the class BeamDataOperator method createAccessorFor.

private DataAccessor createAccessorFor(AttributeFamilyDescriptor family) {
    if (family.isProxy()) {
        AttributeFamilyProxyDescriptor proxy = family.toProxy();
        DataAccessor readAccessor = accessorFor(proxy.getTargetFamilyRead());
        DataAccessor writeAccessor = accessorFor(proxy.getTargetFamilyWrite());
        return AttributeFamilyProxyDataAccessor.of(proxy, readAccessor, writeAccessor);
    }
    URI uri = family.getStorageUri();
    return loader.findForUri(uri).map(f -> f.createAccessor(this, family)).orElseThrow(() -> new IllegalStateException("No accessor for URI " + family.getStorageUri()));
}
Also used : Arrays(java.util.Arrays) TypeDescriptor(org.apache.beam.sdk.values.TypeDescriptor) CoderRegistry(org.apache.beam.sdk.coders.CoderRegistry) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) DataAccessorLoader(cz.o2.proxima.storage.internal.DataAccessorLoader) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) Union(org.apache.beam.sdk.extensions.euphoria.core.client.operator.Union) Value(lombok.Value) PTransform(org.apache.beam.sdk.transforms.PTransform) HashSet(java.util.HashSet) StreamElement(cz.o2.proxima.storage.StreamElement) Pair(cz.o2.proxima.util.Pair) Map(java.util.Map) StreamElementCoder(cz.o2.proxima.beam.core.io.StreamElementCoder) AttributeFamilyProxyDescriptor(cz.o2.proxima.repository.AttributeFamilyProxyDescriptor) GlobalWindow(org.apache.beam.sdk.transforms.windowing.GlobalWindow) IntervalWindowCoder(org.apache.beam.sdk.transforms.windowing.IntervalWindow.IntervalWindowCoder) URI(java.net.URI) Pipeline(org.apache.beam.sdk.Pipeline) Nullable(javax.annotation.Nullable) AttributeDescriptorCoder(cz.o2.proxima.beam.core.io.AttributeDescriptorCoder) Repository(cz.o2.proxima.repository.Repository) Predicate(java.util.function.Predicate) AttributeDescriptor(cz.o2.proxima.repository.AttributeDescriptor) Set(java.util.Set) AttributeFamilyDescriptor(cz.o2.proxima.repository.AttributeFamilyDescriptor) PCollection(org.apache.beam.sdk.values.PCollection) Collectors(java.util.stream.Collectors) EntityDescriptorCoder(cz.o2.proxima.beam.core.io.EntityDescriptorCoder) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Filter(org.apache.beam.sdk.transforms.Filter) DataOperator(cz.o2.proxima.repository.DataOperator) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DirectDataOperator(cz.o2.proxima.direct.core.DirectDataOperator) Comparator(java.util.Comparator) IntervalWindow(org.apache.beam.sdk.transforms.windowing.IntervalWindow) Collections(java.util.Collections) Position(cz.o2.proxima.storage.commitlog.Position) AttributeFamilyProxyDescriptor(cz.o2.proxima.repository.AttributeFamilyProxyDescriptor) URI(java.net.URI)

Example 5 with AttributeFamilyProxyDescriptor

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

the class DirectDataOperator method addResolvedFamily.

private void addResolvedFamily(AttributeFamilyDescriptor family) {
    try {
        if (!familyMap.containsKey(family)) {
            log.debug("Adding new family {} to familyMap", family);
            if (family.isProxy()) {
                AttributeFamilyProxyDescriptor proxy = family.toProxy();
                familyMap.put(family, DirectAttributeFamilyProxyDescriptor.of(repo, context, proxy));
                addResolvedFamily(proxy.getTargetFamilyRead());
                addResolvedFamily(proxy.getTargetFamilyWrite());
            } else {
                DataAccessor accessor = findAccessorFor(family);
                familyMap.put(family, new DirectAttributeFamilyDescriptor(repo, family, context, accessor));
            }
        }
    } catch (Exception ex) {
        log.error("Failed to add family {}", family, ex);
        throw ex;
    }
}
Also used : AttributeFamilyProxyDescriptor(cz.o2.proxima.repository.AttributeFamilyProxyDescriptor)

Aggregations

AttributeFamilyProxyDescriptor (cz.o2.proxima.repository.AttributeFamilyProxyDescriptor)4 CommitLogReader (cz.o2.proxima.direct.commitlog.CommitLogReader)3 AttributeDescriptor (cz.o2.proxima.repository.AttributeDescriptor)3 AttributeFamilyDescriptor (cz.o2.proxima.repository.AttributeFamilyDescriptor)3 URI (java.net.URI)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Config (com.typesafe.config.Config)2 RandomAccessReader (cz.o2.proxima.direct.randomaccess.RandomAccessReader)2 CachedView (cz.o2.proxima.direct.view.CachedView)2 ConfigRepository (cz.o2.proxima.repository.ConfigRepository)2 StorageType (cz.o2.proxima.storage.StorageType)2 ThroughputLimiter (cz.o2.proxima.storage.ThroughputLimiter)2 ArrayList (java.util.ArrayList)2