Github user siyuanh commented on a diff in the pull request:
https://github.com/apache/apex-malhar/pull/294#discussion_r68977507
--- Diff:
contrib/src/main/java/com/datatorrent/contrib/kafka/AbstractTupleUniqueExactlyOnceKafkaOutputOperator.java
---
@@ -0,0 +1,610 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.datatorrent.contrib.kafka;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.classification.InterfaceStability;
+
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+import com.datatorrent.api.Context.OperatorContext;
+import com.datatorrent.api.DefaultInputPort;
+import com.datatorrent.common.util.Pair;
+
+import kafka.api.OffsetRequest;
+import kafka.javaapi.consumer.SimpleConsumer;
+import kafka.javaapi.producer.Producer;
+import kafka.producer.KeyedMessage;
+import kafka.producer.ProducerConfig;
+import kafka.serializer.StringDecoder;
+
+/**
+ * Assumptions: - assume the value of incoming tuples are not duplicate(at
least
+ * in one window) among all operator partitions. - assume one Kafka
partition
+ * can be written by multiple operator partitions at the same time -
assume the
+ * the Kafka partition was decided by tuple value itself( not depended on
+ * operator partition)
+ *
+ * Notes: - the order of data could be changed when replay. - the data
could go
+ * to the other partition when replay. For example if the upstream operator
+ * failed.
+ *
+ * Implementation: for each Kafka partition, load minimum last window and
the
+ * minimum offset of the last window of all operator partitions. And then
load
+ * the tuples from Kafka based on this minimum offset. When processing
tuple, if
+ * the window id is less than the minimum last window, just ignore the
tuple. If
+ * window id equals loaded minimum window id, and tuple equals any of
loaded
+ * tuple, ignore it. Else, send to Kafka
+ *
+ * @displayName Abstract Tuple Unique Exactly Once Kafka Output
+ * @category Messaging
+ * @tags output operator
+ */
[email protected]
+public abstract class AbstractTupleUniqueExactlyOnceKafkaOutputOperator<T,
K, V>
+ extends AbstractKafkaOutputOperator<K, V>
+{
+ public static final String DEFAULT_CONTROL_TOPIC = "ControlTopic";
+ protected transient int partitionNum = 1;
+
+ /**
+ * allow client set the partitioner as partitioner may need some
attributes
+ */
+ protected kafka.producer.Partitioner partitioner;
+
+ protected transient int operatorPartitionId;
+
+ protected String controlTopic = DEFAULT_CONTROL_TOPIC;
+
+ //The control info includes the time, use this time to track the head of
control info we care.
+ protected int controlInfoTrackBackTime = 120000;
+
+ /**
+ * max number of offset need to check
+ */
+ protected int maxNumOffsetsOfControl = 1000;
+
+ protected String controlProducerProperties;
+ protected Set<String> brokerSet;
+
+ protected transient long currentWindowId;
+
+ /**
+ * the map from Kafka partition id to the control offset. this one is
+ * checkpointed and as the start offset to load the recovery control
+ * information Note: this only keep the information of this operator
+ * partition.
+ */
+ protected transient Map<Integer, Long> partitionToLastControlOffset =
Maps.newHashMap();
+
+ /**
+ * keep the minimal last window id for recovery. If only one partition
+ * crashed, it is ok just use the last window id of this operator
partition as
+ * the recovery window id If all operator partitions crashed, should use
the
+ * minimal last window id as the recovery window id, as the data may go
to the
+ * other partitions. But as the operator can't distinguish which is the
case.
+ * use the most general one.
+ */
+ protected transient long minRecoveryWindowId = -2;
+ protected transient long maxRecoveryWindowId = -2;
+
+ /**
+ * A map from Kafka partition id to lastMessages writtten to this kafka
--- End diff --
Typo
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---