You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2018/11/03 00:23:19 UTC
[GitHub] jsun98 commented on a change in pull request #6431: Add Kinesis
Indexing Service to core Druid
jsun98 commented on a change in pull request #6431: Add Kinesis Indexing Service to core Druid
URL: https://github.com/apache/incubator-druid/pull/6431#discussion_r230537959
##########
File path: indexing-service/src/main/java/org/apache/druid/indexing/seekablestream/SeekableStreamPartitions.java
##########
@@ -0,0 +1,134 @@
+/*
+ * 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 org.apache.druid.indexing.seekablestream;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * class that encapsulates a map of partitionId -> sequenceNumber.
+ * To be backward compatible with both Kafka and Kinesis datasource metadata when
+ * deserializing json. Redundant constrcturo fields stream, topic and
+ * partitionSequenceNumberMap and partitionOffsetMap are created. Only one of topic, stream
+ * should have a non-null value and only one of partitionOffsetMap and partitionSequenceNumberMap
+ * should have a non-null value.
+ * <p>
+ * Redundant getters
+ * are used for proper Jackson serialization/deserialization when processing terminologies
+ * used by Kafka and kinesis (i.e. topic vs. name)
+ *
+ * @param <partitionType> partition id type
+ * @param <sequenceType> sequence number type
+ */
+public class SeekableStreamPartitions<partitionType, sequenceType>
+{
+ public static final String NO_END_SEQUENCE_NUMBER = "NO_END_SEQUENCE_NUMBER";
+
+ // stream/topic
+ private final String name;
+ // partitionId -> sequence number
+ private final Map<partitionType, sequenceType> map;
+
+ @JsonCreator
+ public SeekableStreamPartitions(
+ @JsonProperty("stream") final String stream,
+ @JsonProperty("topic") final String topic,
+ @JsonProperty("partitionSequenceNumberMap") final Map<partitionType, sequenceType> partitionSequenceNumberMap,
+ @JsonProperty("partitionOffsetMap") final Map<partitionType, sequenceType> partitionOffsetMap
+ )
+ {
+ this.name = stream == null ? topic : stream;
+ this.map = ImmutableMap.copyOf(partitionOffsetMap == null
+ ? partitionSequenceNumberMap
+ : partitionOffsetMap);
+ Preconditions.checkArgument(this.name != null);
+ Preconditions.checkArgument(map != null);
+ }
+
+ // constructor for backward compatibility
+ public SeekableStreamPartitions(@NotNull final String id, final Map<partitionType, sequenceType> partitionOffsetMap)
+ {
+ this(id, null, partitionOffsetMap, null);
+ }
+
+ @JsonProperty
+ public String getName()
Review comment:
the reason for having redundant getters is that Jackson has problems deserializing json strings from kafka and kinesis. For example in `KinesisIOConfig`
```java
@JsonCreator
public KinesisIOConfig(
@JsonProperty("baseSequenceName") String baseSequenceName,
@JsonProperty("startPartitions") SeekableStreamPartitions<String, String> startPartitions,
```
initializing startPartitions requires the getter `getPartitionSequenceNumberMap` while in the kafka version, the getter required is `getPartitionOffsetMap`. I haven't been able to find another workaround, perhaps we could also create a `KafkaStreamPartitions` and `KinesisStreamPartitions` class, but that would introduce 2 redundant classes.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org