Search in sources :

Example 1 with KeyPartitioner

use of cz.o2.proxima.storage.commitlog.KeyPartitioner in project proxima-platform by O2-Czech-Republic.

the class KafkaLogReaderIT method writePoisonedPills.

/**
 * Write poisoned pills (element with timestamp = {@link Watermarks#MAX_WATERMARK}) to all
 * partitions.
 *
 * @param numPartitions Number of partitions in topic.
 * @return Completion latch.
 */
private CountDownLatch writePoisonedPills(int numPartitions) {
    final OnlineAttributeWriter writer = Optionals.get(operator.getWriter(fooDescriptor));
    // We assume test uses default partitioner.
    final KeyPartitioner keyPartitioner = new KeyPartitioner();
    final Set<Integer> poisonedPartitions = new HashSet<>();
    final CountDownLatch done = new CountDownLatch(numPartitions);
    for (int i = 0; poisonedPartitions.size() < numPartitions; i++) {
        final StreamElement poisonedPill = StreamElement.upsert(entity, fooDescriptor, UUID.randomUUID().toString(), String.format("poisoned-pill-%d", i), fooDescriptor.getName(), Watermarks.MAX_WATERMARK, "value".getBytes(StandardCharsets.UTF_8));
        final int partition = (keyPartitioner.getPartitionId(poisonedPill) & Integer.MAX_VALUE) % numPartitions;
        if (poisonedPartitions.add(partition)) {
            writer.write(poisonedPill, ((success, error) -> {
                if (success) {
                    done.countDown();
                }
            }));
        }
    }
    return done;
}
Also used : Arrays(java.util.Arrays) Partition(cz.o2.proxima.storage.Partition) ConfigValueFactory(com.typesafe.config.ConfigValueFactory) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) Random(java.util.Random) ExceptionUtils(cz.o2.proxima.util.ExceptionUtils) StreamElement(cz.o2.proxima.storage.StreamElement) Map(java.util.Map) Optionals(cz.o2.proxima.util.Optionals) KafkaStreamElementSerializer(cz.o2.proxima.direct.kafka.KafkaStreamElement.KafkaStreamElementSerializer) Set(java.util.Set) ObserveHandle(cz.o2.proxima.direct.commitlog.ObserveHandle) UUID(java.util.UUID) ConfigResolveOptions(com.typesafe.config.ConfigResolveOptions) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) DirectDataOperator(cz.o2.proxima.direct.core.DirectDataOperator) Pattern(java.util.regex.Pattern) KeyPartitioner(cz.o2.proxima.storage.commitlog.KeyPartitioner) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) HashMap(java.util.HashMap) OnlineAttributeWriter(cz.o2.proxima.direct.core.OnlineAttributeWriter) EmbeddedKafkaBroker(org.springframework.kafka.test.EmbeddedKafkaBroker) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) ConfigFactory(com.typesafe.config.ConfigFactory) Watermarks(cz.o2.proxima.time.Watermarks) ObserveHandleUtils(cz.o2.proxima.direct.commitlog.ObserveHandleUtils) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) Before(org.junit.Before) Properties(java.util.Properties) Repository(cz.o2.proxima.repository.Repository) Config(com.typesafe.config.Config) AttributeDescriptor(cz.o2.proxima.repository.AttributeDescriptor) NewTopic(org.apache.kafka.clients.admin.NewTopic) CommitLogObserver(cz.o2.proxima.direct.commitlog.CommitLogObserver) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) EmbeddedKafkaRule(org.springframework.kafka.test.rule.EmbeddedKafkaRule) Rule(org.junit.Rule) Ignore(org.junit.Ignore) Assert(org.junit.Assert) Collections(java.util.Collections) Position(cz.o2.proxima.storage.commitlog.Position) KeyPartitioner(cz.o2.proxima.storage.commitlog.KeyPartitioner) OnlineAttributeWriter(cz.o2.proxima.direct.core.OnlineAttributeWriter) StreamElement(cz.o2.proxima.storage.StreamElement) CountDownLatch(java.util.concurrent.CountDownLatch) HashSet(java.util.HashSet)

Aggregations

Lists (com.google.common.collect.Lists)1 Config (com.typesafe.config.Config)1 ConfigFactory (com.typesafe.config.ConfigFactory)1 ConfigResolveOptions (com.typesafe.config.ConfigResolveOptions)1 ConfigValueFactory (com.typesafe.config.ConfigValueFactory)1 CommitLogObserver (cz.o2.proxima.direct.commitlog.CommitLogObserver)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 DirectDataOperator (cz.o2.proxima.direct.core.DirectDataOperator)1 OnlineAttributeWriter (cz.o2.proxima.direct.core.OnlineAttributeWriter)1 KafkaStreamElementSerializer (cz.o2.proxima.direct.kafka.KafkaStreamElement.KafkaStreamElementSerializer)1 AttributeDescriptor (cz.o2.proxima.repository.AttributeDescriptor)1 EntityDescriptor (cz.o2.proxima.repository.EntityDescriptor)1 Repository (cz.o2.proxima.repository.Repository)1 Partition (cz.o2.proxima.storage.Partition)1 StreamElement (cz.o2.proxima.storage.StreamElement)1 KeyPartitioner (cz.o2.proxima.storage.commitlog.KeyPartitioner)1 Position (cz.o2.proxima.storage.commitlog.Position)1 Watermarks (cz.o2.proxima.time.Watermarks)1