You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/03/09 13:31:42 UTC

[GitHub] [incubator-pinot] KKcorps opened a new pull request #6661: Add Kinesis Stream Ingestion Plugin

KKcorps opened a new pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661


   The PR contains the code related to the new Kinesis Stream Ingestion Plugin for Pinot.
   
   The plugin allows users to ingest data into Pinot directly from Kinesis.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r616221241



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConnectionHandler.java
##########
@@ -0,0 +1,76 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.List;
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ListShardsRequest;
+import software.amazon.awssdk.services.kinesis.model.ListShardsResponse;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * Manages the Kinesis stream connection, given the stream name and aws region
+ */
+public class KinesisConnectionHandler {
+  protected KinesisClient _kinesisClient;
+  private final String _stream;
+  private final String _awsRegion;
+
+  public KinesisConnectionHandler(String stream, String awsRegion) {
+    _stream = stream;
+    _awsRegion = awsRegion;
+    createConnection();
+  }
+
+  public KinesisConnectionHandler(String stream, String awsRegion, KinesisClient kinesisClient) {

Review comment:
       Looks like it is for testing. Marking it as VisibleForTesting.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r624603253



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumer.java
##########
@@ -0,0 +1,194 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsResponse;
+import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
+import software.amazon.awssdk.services.kinesis.model.InvalidArgumentException;
+import software.amazon.awssdk.services.kinesis.model.KinesisException;
+import software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException;
+import software.amazon.awssdk.services.kinesis.model.Record;
+import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * A {@link PartitionGroupConsumer} implementation for the Kinesis stream
+ */
+public class KinesisConsumer extends KinesisConnectionHandler implements PartitionGroupConsumer {
+  private final Logger LOG = LoggerFactory.getLogger(KinesisConsumer.class);
+  private final String _stream;
+  private final int _maxRecords;
+  private final ExecutorService _executorService;

Review comment:
       I think he's put it there as a mechanism to timeout the request after the timeoutMillis configured by the user. In Kafka it gets taken care of by the `_consumer.poll(timeout)` method.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r624603387



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumer.java
##########
@@ -0,0 +1,194 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsResponse;
+import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
+import software.amazon.awssdk.services.kinesis.model.InvalidArgumentException;
+import software.amazon.awssdk.services.kinesis.model.KinesisException;
+import software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException;
+import software.amazon.awssdk.services.kinesis.model.Record;
+import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * A {@link PartitionGroupConsumer} implementation for the Kinesis stream
+ */
+public class KinesisConsumer extends KinesisConnectionHandler implements PartitionGroupConsumer {
+  private final Logger LOG = LoggerFactory.getLogger(KinesisConsumer.class);
+  private final String _stream;
+  private final int _maxRecords;
+  private final ExecutorService _executorService;
+  private final ShardIteratorType _shardIteratorType;
+
+  public KinesisConsumer(KinesisConfig kinesisConfig) {
+    super(kinesisConfig.getStream(), kinesisConfig.getAwsRegion());
+    _stream = kinesisConfig.getStream();
+    _maxRecords = kinesisConfig.maxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  public KinesisConsumer(KinesisConfig kinesisConfig, KinesisClient kinesisClient) {
+    super(kinesisConfig.getStream(), kinesisConfig.getAwsRegion(), kinesisClient);
+    _kinesisClient = kinesisClient;
+    _stream = kinesisConfig.getStream();
+    _maxRecords = kinesisConfig.maxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  /**
+   * Fetch records from the Kinesis stream between the start and end KinesisCheckpoint
+   */
+  @Override
+  public KinesisRecordsBatch fetchMessages(StreamPartitionMsgOffset startCheckpoint,
+      StreamPartitionMsgOffset endCheckpoint, int timeoutMs) {
+    List<Record> recordList = new ArrayList<>();
+    Future<KinesisRecordsBatch> kinesisFetchResultFuture =
+        _executorService.submit(() -> getResult(startCheckpoint, endCheckpoint, recordList));
+
+    try {
+      return kinesisFetchResultFuture.get(timeoutMs, TimeUnit.MILLISECONDS);
+    } catch (Exception e) {
+      return handleException((KinesisPartitionGroupOffset) startCheckpoint, recordList);
+    }
+  }
+
+  private KinesisRecordsBatch getResult(StreamPartitionMsgOffset start, StreamPartitionMsgOffset end,
+      List<Record> recordList) {
+    KinesisPartitionGroupOffset kinesisStartCheckpoint = (KinesisPartitionGroupOffset) start;
+
+    try {
+
+      if (_kinesisClient == null) {
+        createConnection();
+      }
+
+      //TODO: iterate upon all the shardIds in the map
+      // Okay for now, since we have assumed that every partition group contains a single shard
+      Map.Entry<String, String> shardToSequenceNum =
+          kinesisStartCheckpoint.getShardToStartSequenceMap().entrySet().iterator().next();
+      String shardIterator = getShardIterator(shardToSequenceNum.getKey(), shardToSequenceNum.getValue());
+
+      String kinesisEndSequenceNumber = null;
+
+      if (end != null) {
+        KinesisPartitionGroupOffset kinesisEndCheckpoint = (KinesisPartitionGroupOffset) end;
+        kinesisEndSequenceNumber = kinesisEndCheckpoint.getShardToStartSequenceMap().values().iterator().next();
+      }
+
+      String nextStartSequenceNumber = null;
+      boolean isEndOfShard = false;
+
+      while (shardIterator != null) {
+        GetRecordsRequest getRecordsRequest = GetRecordsRequest.builder().shardIterator(shardIterator).build();
+        GetRecordsResponse getRecordsResponse = _kinesisClient.getRecords(getRecordsRequest);
+
+        if (getRecordsResponse.records().size() > 0) {
+          recordList.addAll(getRecordsResponse.records());
+          nextStartSequenceNumber = recordList.get(recordList.size() - 1).sequenceNumber();

Review comment:
       Added the precondition. Right now we have made the assumption that we will only have 1 shard per segment




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r630559861



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisStreamMetadataProvider.java
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.spi.stream.MessageBatch;
+import org.apache.pinot.spi.stream.OffsetCriteria;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.PartitionGroupConsumptionStatus;
+import org.apache.pinot.spi.stream.PartitionGroupMetadata;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConsumerFactory;
+import org.apache.pinot.spi.stream.StreamConsumerFactoryProvider;
+import org.apache.pinot.spi.stream.StreamMetadataProvider;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * A {@link StreamMetadataProvider} implementation for the Kinesis stream
+ */
+public class KinesisStreamMetadataProvider implements StreamMetadataProvider {
+  private final KinesisConnectionHandler _kinesisConnectionHandler;
+  private final StreamConsumerFactory _kinesisStreamConsumerFactory;
+  private final String _clientId;
+  private final int _fetchTimeoutMs;
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = new KinesisConnectionHandler(kinesisConfig.getStream(), kinesisConfig.getAwsRegion());
+    _kinesisStreamConsumerFactory = StreamConsumerFactoryProvider.create(streamConfig);
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig,
+      KinesisConnectionHandler kinesisConnectionHandler, StreamConsumerFactory streamConsumerFactory) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = kinesisConnectionHandler;
+    _kinesisStreamConsumerFactory = streamConsumerFactory;
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  @Override
+  public int fetchPartitionCount(long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public long fetchPartitionOffset(@Nonnull OffsetCriteria offsetCriteria, long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  /**
+   * This call returns all active shards, taking into account the consumption status for those shards.
+   * {@link PartitionGroupMetadata} is returned for a shard if:
+   * 1. It is a branch new shard AND its parent has been consumed completely
+   * 2. It is still being actively consumed from i.e. the consuming partition has not reached the end of the shard
+   */
+  @Override
+  public List<PartitionGroupMetadata> computePartitionGroupMetadata(String clientId, StreamConfig streamConfig,
+      List<PartitionGroupConsumptionStatus> partitionGroupConsumptionStatuses, int timeoutMillis)
+      throws IOException, TimeoutException {
+
+    List<PartitionGroupMetadata> newPartitionGroupMetadatas = new ArrayList<>();
+
+    Map<String, Shard> shardIdToShardMap = _kinesisConnectionHandler.getShards().stream()
+        .collect(Collectors.toMap(Shard::shardId, s -> s, (s1, s2) -> s1));
+    Set<String> shardsInCurrent = new HashSet<>();
+    Set<String> shardsEnded = new HashSet<>();
+
+    // TODO: Once we start supporting multiple shards in a PartitionGroup,
+    //  we need to iterate over all shards to check if any of them have reached end
+
+    // Process existing shards. Add them to new list if still consuming from them
+    for (PartitionGroupConsumptionStatus currentPartitionGroupConsumptionStatus : partitionGroupConsumptionStatuses) {
+      KinesisPartitionGroupOffset kinesisStartCheckpoint =
+          (KinesisPartitionGroupOffset) currentPartitionGroupConsumptionStatus.getStartOffset();
+      String shardId = kinesisStartCheckpoint.getShardToStartSequenceMap().keySet().iterator().next();
+      Shard shard = shardIdToShardMap.get(shardId);
+      shardsInCurrent.add(shardId);
+
+      StreamPartitionMsgOffset newStartOffset;
+      StreamPartitionMsgOffset currentEndOffset = currentPartitionGroupConsumptionStatus.getEndOffset();
+      if (currentEndOffset != null) { // Segment DONE (committing/committed)
+        String endingSequenceNumber = shard.sequenceNumberRange().endingSequenceNumber();
+        if (endingSequenceNumber != null) { // Shard has ended, check if we're also done consuming it
+          if (consumedEndOfShard(currentEndOffset, currentPartitionGroupConsumptionStatus)) {
+            shardsEnded.add(shardId);
+            continue; // Shard ended and we're done consuming it. Skip
+          }
+        }
+        newStartOffset = currentEndOffset;
+      } else { // Segment IN_PROGRESS
+        newStartOffset = currentPartitionGroupConsumptionStatus.getStartOffset();
+      }
+      newPartitionGroupMetadatas.add(
+          new PartitionGroupMetadata(currentPartitionGroupConsumptionStatus.getPartitionGroupId(), newStartOffset));
+    }
+
+    // Add new shards. Parent should be null (new table case, very first shards)
+    // OR it should be flagged as reached EOL and completely consumed.
+    for (Map.Entry<String, Shard> entry : shardIdToShardMap.entrySet()) {
+      String newShardId = entry.getKey();
+      if (shardsInCurrent.contains(newShardId)) {
+        continue;
+      }
+      StreamPartitionMsgOffset newStartOffset;
+      Shard newShard = entry.getValue();
+      String parentShardId = newShard.parentShardId();
+
+      if (parentShardId == null || shardsEnded.contains(parentShardId)) {

Review comment:
       great catch! yes this is possible. Let me see if there's an easy fix




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r624603337



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumer.java
##########
@@ -0,0 +1,194 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsResponse;
+import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
+import software.amazon.awssdk.services.kinesis.model.InvalidArgumentException;
+import software.amazon.awssdk.services.kinesis.model.KinesisException;
+import software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException;
+import software.amazon.awssdk.services.kinesis.model.Record;
+import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * A {@link PartitionGroupConsumer} implementation for the Kinesis stream
+ */
+public class KinesisConsumer extends KinesisConnectionHandler implements PartitionGroupConsumer {
+  private final Logger LOG = LoggerFactory.getLogger(KinesisConsumer.class);
+  private final String _stream;
+  private final int _maxRecords;
+  private final ExecutorService _executorService;
+  private final ShardIteratorType _shardIteratorType;
+
+  public KinesisConsumer(KinesisConfig kinesisConfig) {
+    super(kinesisConfig.getStream(), kinesisConfig.getAwsRegion());
+    _stream = kinesisConfig.getStream();
+    _maxRecords = kinesisConfig.maxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  public KinesisConsumer(KinesisConfig kinesisConfig, KinesisClient kinesisClient) {
+    super(kinesisConfig.getStream(), kinesisConfig.getAwsRegion(), kinesisClient);
+    _kinesisClient = kinesisClient;
+    _stream = kinesisConfig.getStream();
+    _maxRecords = kinesisConfig.maxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  /**
+   * Fetch records from the Kinesis stream between the start and end KinesisCheckpoint
+   */
+  @Override
+  public KinesisRecordsBatch fetchMessages(StreamPartitionMsgOffset startCheckpoint,
+      StreamPartitionMsgOffset endCheckpoint, int timeoutMs) {
+    List<Record> recordList = new ArrayList<>();
+    Future<KinesisRecordsBatch> kinesisFetchResultFuture =
+        _executorService.submit(() -> getResult(startCheckpoint, endCheckpoint, recordList));
+
+    try {
+      return kinesisFetchResultFuture.get(timeoutMs, TimeUnit.MILLISECONDS);
+    } catch (Exception e) {
+      return handleException((KinesisPartitionGroupOffset) startCheckpoint, recordList);
+    }
+  }
+
+  private KinesisRecordsBatch getResult(StreamPartitionMsgOffset start, StreamPartitionMsgOffset end,
+      List<Record> recordList) {
+    KinesisPartitionGroupOffset kinesisStartCheckpoint = (KinesisPartitionGroupOffset) start;
+
+    try {
+
+      if (_kinesisClient == null) {
+        createConnection();
+      }
+
+      //TODO: iterate upon all the shardIds in the map
+      // Okay for now, since we have assumed that every partition group contains a single shard
+      Map.Entry<String, String> shardToSequenceNum =
+          kinesisStartCheckpoint.getShardToStartSequenceMap().entrySet().iterator().next();
+      String shardIterator = getShardIterator(shardToSequenceNum.getKey(), shardToSequenceNum.getValue());
+
+      String kinesisEndSequenceNumber = null;
+
+      if (end != null) {
+        KinesisPartitionGroupOffset kinesisEndCheckpoint = (KinesisPartitionGroupOffset) end;
+        kinesisEndSequenceNumber = kinesisEndCheckpoint.getShardToStartSequenceMap().values().iterator().next();
+      }
+
+      String nextStartSequenceNumber = null;
+      boolean isEndOfShard = false;
+
+      while (shardIterator != null) {
+        GetRecordsRequest getRecordsRequest = GetRecordsRequest.builder().shardIterator(shardIterator).build();
+        GetRecordsResponse getRecordsResponse = _kinesisClient.getRecords(getRecordsRequest);
+
+        if (getRecordsResponse.records().size() > 0) {
+          recordList.addAll(getRecordsResponse.records());
+          nextStartSequenceNumber = recordList.get(recordList.size() - 1).sequenceNumber();
+
+          if (kinesisEndSequenceNumber != null && kinesisEndSequenceNumber.compareTo(nextStartSequenceNumber) <= 0) {
+            nextStartSequenceNumber = kinesisEndSequenceNumber;

Review comment:
       True. Removing it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r624603923



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisStreamMetadataProvider.java
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.spi.stream.MessageBatch;
+import org.apache.pinot.spi.stream.OffsetCriteria;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.PartitionGroupConsumptionStatus;
+import org.apache.pinot.spi.stream.PartitionGroupMetadata;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConsumerFactory;
+import org.apache.pinot.spi.stream.StreamConsumerFactoryProvider;
+import org.apache.pinot.spi.stream.StreamMetadataProvider;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * A {@link StreamMetadataProvider} implementation for the Kinesis stream
+ */
+public class KinesisStreamMetadataProvider implements StreamMetadataProvider {
+  private final KinesisConnectionHandler _kinesisConnectionHandler;
+  private final StreamConsumerFactory _kinesisStreamConsumerFactory;
+  private final String _clientId;
+  private final int _fetchTimeoutMs;
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = new KinesisConnectionHandler(kinesisConfig.getStream(), kinesisConfig.getAwsRegion());
+    _kinesisStreamConsumerFactory = StreamConsumerFactoryProvider.create(streamConfig);
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig,
+      KinesisConnectionHandler kinesisConnectionHandler, StreamConsumerFactory streamConsumerFactory) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = kinesisConnectionHandler;
+    _kinesisStreamConsumerFactory = streamConsumerFactory;
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  @Override
+  public int fetchPartitionCount(long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public long fetchPartitionOffset(@Nonnull OffsetCriteria offsetCriteria, long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  /**
+   * This call returns all active shards, taking into account the consumption status for those shards.
+   * {@link PartitionGroupMetadata} is returned for a shard if:
+   * 1. It is a branch new shard AND its parent has been consumed completely
+   * 2. It is still being actively consumed from i.e. the consuming partition has not reached the end of the shard
+   */
+  @Override
+  public List<PartitionGroupMetadata> computePartitionGroupMetadata(String clientId, StreamConfig streamConfig,
+      List<PartitionGroupConsumptionStatus> partitionGroupConsumptionStatuses, int timeoutMillis)
+      throws IOException, TimeoutException {
+
+    List<PartitionGroupMetadata> newPartitionGroupMetadatas = new ArrayList<>();
+
+    Map<String, Shard> shardIdToShardMap = _kinesisConnectionHandler.getShards().stream()
+        .collect(Collectors.toMap(Shard::shardId, s -> s, (s1, s2) -> s1));
+    Set<String> shardsInCurrent = new HashSet<>();
+    Set<String> shardsEnded = new HashSet<>();
+
+    // TODO: Once we start supporting multiple shards in a PartitionGroup,
+    //  we need to iterate over all shards to check if any of them have reached end
+
+    // Process existing shards. Add them to new list if still consuming from them
+    for (PartitionGroupConsumptionStatus currentPartitionGroupConsumptionStatus : partitionGroupConsumptionStatuses) {
+      KinesisPartitionGroupOffset kinesisStartCheckpoint =
+          (KinesisPartitionGroupOffset) currentPartitionGroupConsumptionStatus.getStartOffset();
+      String shardId = kinesisStartCheckpoint.getShardToStartSequenceMap().keySet().iterator().next();
+      Shard shard = shardIdToShardMap.get(shardId);
+      shardsInCurrent.add(shardId);
+
+      StreamPartitionMsgOffset newStartOffset;
+      StreamPartitionMsgOffset currentEndOffset = currentPartitionGroupConsumptionStatus.getEndOffset();
+      if (currentEndOffset != null) { // Segment DONE (committing/committed)
+        String endingSequenceNumber = shard.sequenceNumberRange().endingSequenceNumber();
+        if (endingSequenceNumber != null) { // Shard has ended, check if we're also done consuming it
+          if (consumedEndOfShard(currentEndOffset, currentPartitionGroupConsumptionStatus)) {
+            shardsEnded.add(shardId);
+            continue; // Shard ended and we're done consuming it. Skip
+          }
+        }
+        newStartOffset = currentEndOffset;
+      } else { // Segment IN_PROGRESS
+        newStartOffset = currentPartitionGroupConsumptionStatus.getStartOffset();
+      }
+      newPartitionGroupMetadatas.add(
+          new PartitionGroupMetadata(currentPartitionGroupConsumptionStatus.getPartitionGroupId(), newStartOffset));
+    }
+
+    // Add new shards. Parent should be null (new table case, very first shards)
+    // OR it should be flagged as reached EOL and completely consumed.
+    for (Map.Entry<String, Shard> entry : shardIdToShardMap.entrySet()) {
+      String newShardId = entry.getKey();
+      if (shardsInCurrent.contains(newShardId)) {
+        continue;
+      }
+      StreamPartitionMsgOffset newStartOffset;
+      Shard newShard = entry.getValue();
+      String parentShardId = newShard.parentShardId();
+
+      if (parentShardId == null || shardsEnded.contains(parentShardId)) {
+        Map<String, String> shardToSequenceNumberMap = new HashMap<>();
+        shardToSequenceNumberMap.put(newShardId, newShard.sequenceNumberRange().startingSequenceNumber());
+        newStartOffset = new KinesisPartitionGroupOffset(shardToSequenceNumberMap);
+        int partitionGroupId = getPartitionGroupIdFromShardId(newShardId);
+        newPartitionGroupMetadatas.add(new PartitionGroupMetadata(partitionGroupId, newStartOffset));
+      }
+    }
+    return newPartitionGroupMetadatas;
+  }
+
+  /**
+   * Converts a shardId string to a partitionGroupId integer by parsing the digits of the shardId
+   * e.g. "shardId-000000000001" becomes 1

Review comment:
       I agree with you. There's no guarantee, but I think it's safe to assume it, because practically, it's always like this. I spoke to few Kinesis users too.
   Added a FIXME, to  call this out and re-evaluate this in the future if needed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] codecov-commenter commented on pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#issuecomment-849265905


   # [Codecov](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#6661](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (9450858) into [master](https://codecov.io/gh/apache/incubator-pinot/commit/b8a92c41e3d063c436e37965ade577ff8e2b5f86?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b8a92c4) will **decrease** coverage by `7.89%`.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-pinot/pull/6661/graphs/tree.svg?width=650&height=150&src=pr&token=4ibza2ugkz&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #6661      +/-   ##
   ============================================
   - Coverage     73.42%   65.53%   -7.90%     
     Complexity       12       12              
   ============================================
     Files          1441     1441              
     Lines         71431    71450      +19     
     Branches      10351    10354       +3     
   ============================================
   - Hits          52446    46822    -5624     
   - Misses        15464    21237    +5773     
   + Partials       3521     3391     -130     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | integration | `?` | |
   | unittests | `65.53% <ø> (-0.02%)` | :arrow_down: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...a/org/apache/pinot/minion/metrics/MinionMeter.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtbWluaW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9taW5pb24vbWV0cmljcy9NaW5pb25NZXRlci5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [.../apache/pinot/common/metrics/BrokerQueryPhase.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vbWV0cmljcy9Ccm9rZXJRdWVyeVBoYXNlLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [.../apache/pinot/minion/metrics/MinionQueryPhase.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtbWluaW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9taW5pb24vbWV0cmljcy9NaW5pb25RdWVyeVBoYXNlLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...pache/pinot/common/utils/grpc/GrpcQueryClient.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vdXRpbHMvZ3JwYy9HcnBjUXVlcnlDbGllbnQuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...pinot/minion/exception/TaskCancelledException.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtbWluaW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9taW5pb24vZXhjZXB0aW9uL1Rhc2tDYW5jZWxsZWRFeGNlcHRpb24uamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...t/core/startree/plan/StarTreeDocIdSetPlanNode.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9zdGFydHJlZS9wbGFuL1N0YXJUcmVlRG9jSWRTZXRQbGFuTm9kZS5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [.../core/startree/plan/StarTreeTransformPlanNode.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9zdGFydHJlZS9wbGFuL1N0YXJUcmVlVHJhbnNmb3JtUGxhbk5vZGUuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...core/startree/plan/StarTreeProjectionPlanNode.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9zdGFydHJlZS9wbGFuL1N0YXJUcmVlUHJvamVjdGlvblBsYW5Ob2RlLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...t/minion/executor/MinionTaskZkMetadataManager.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtbWluaW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9taW5pb24vZXhlY3V0b3IvTWluaW9uVGFza1prTWV0YWRhdGFNYW5hZ2VyLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...startree/executor/StarTreeAggregationExecutor.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9zdGFydHJlZS9leGVjdXRvci9TdGFyVHJlZUFnZ3JlZ2F0aW9uRXhlY3V0b3IuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | ... and [338 more](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [b8a92c4...9450858](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] mcvsubbu commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
mcvsubbu commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r612095454



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/test/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumerIntegrationTest.java
##########
@@ -0,0 +1,69 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamConfigProperties;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+public class KinesisConsumerIntegrationTest {

Review comment:
       Is this some example code? why do we have a main() here?

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumer.java
##########
@@ -0,0 +1,194 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsResponse;
+import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
+import software.amazon.awssdk.services.kinesis.model.InvalidArgumentException;
+import software.amazon.awssdk.services.kinesis.model.KinesisException;
+import software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException;
+import software.amazon.awssdk.services.kinesis.model.Record;
+import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * A {@link PartitionGroupConsumer} implementation for the Kinesis stream
+ */
+public class KinesisConsumer extends KinesisConnectionHandler implements PartitionGroupConsumer {
+  private final Logger LOG = LoggerFactory.getLogger(KinesisConsumer.class);
+  private final String _stream;
+  private final int _maxRecords;
+  private final ExecutorService _executorService;
+  private final ShardIteratorType _shardIteratorType;
+
+  public KinesisConsumer(KinesisConfig kinesisConfig) {
+    super(kinesisConfig.getStream(), kinesisConfig.getAwsRegion());
+    _stream = kinesisConfig.getStream();
+    _maxRecords = kinesisConfig.maxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  public KinesisConsumer(KinesisConfig kinesisConfig, KinesisClient kinesisClient) {
+    super(kinesisConfig.getStream(), kinesisConfig.getAwsRegion(), kinesisClient);
+    _kinesisClient = kinesisClient;
+    _stream = kinesisConfig.getStream();
+    _maxRecords = kinesisConfig.maxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  /**
+   * Fetch records from the Kinesis stream between the start and end KinesisCheckpoint
+   */
+  @Override
+  public KinesisRecordsBatch fetchMessages(StreamPartitionMsgOffset startCheckpoint,
+      StreamPartitionMsgOffset endCheckpoint, int timeoutMs) {
+    List<Record> recordList = new ArrayList<>();
+    Future<KinesisRecordsBatch> kinesisFetchResultFuture =
+        _executorService.submit(() -> getResult(startCheckpoint, endCheckpoint, recordList));
+
+    try {
+      return kinesisFetchResultFuture.get(timeoutMs, TimeUnit.MILLISECONDS);
+    } catch (Exception e) {
+      return handleException((KinesisPartitionGroupOffset) startCheckpoint, recordList);
+    }
+  }
+
+  private KinesisRecordsBatch getResult(StreamPartitionMsgOffset start, StreamPartitionMsgOffset end,
+      List<Record> recordList) {
+    KinesisPartitionGroupOffset kinesisStartCheckpoint = (KinesisPartitionGroupOffset) start;
+
+    try {
+
+      if (_kinesisClient == null) {
+        createConnection();
+      }
+
+      //TODO: iterate upon all the shardIds in the map
+      // Okay for now, since we have assumed that every partition group contains a single shard
+      Map.Entry<String, String> shardToSequenceNum =
+          kinesisStartCheckpoint.getShardToStartSequenceMap().entrySet().iterator().next();
+      String shardIterator = getShardIterator(shardToSequenceNum.getKey(), shardToSequenceNum.getValue());
+
+      String kinesisEndSequenceNumber = null;
+
+      if (end != null) {
+        KinesisPartitionGroupOffset kinesisEndCheckpoint = (KinesisPartitionGroupOffset) end;
+        kinesisEndSequenceNumber = kinesisEndCheckpoint.getShardToStartSequenceMap().values().iterator().next();
+      }
+
+      String nextStartSequenceNumber = null;
+      boolean isEndOfShard = false;
+
+      while (shardIterator != null) {
+        GetRecordsRequest getRecordsRequest = GetRecordsRequest.builder().shardIterator(shardIterator).build();
+        GetRecordsResponse getRecordsResponse = _kinesisClient.getRecords(getRecordsRequest);
+
+        if (getRecordsResponse.records().size() > 0) {
+          recordList.addAll(getRecordsResponse.records());
+          nextStartSequenceNumber = recordList.get(recordList.size() - 1).sequenceNumber();

Review comment:
       If we are iterating through shards then we should be getting a vector of sequence numbers, right? We seem to be keeping track of the sequence number of the last shard we examined?
   Othewise add a PreCondition that the shardlist has exactly one shard.

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/test/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumerIntegrationTest.java
##########
@@ -0,0 +1,69 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamConfigProperties;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+public class KinesisConsumerIntegrationTest {
+
+  private static final String STREAM_NAME = "kinesis-test";
+  private static final String AWS_REGION = "us-west-2";
+
+  public static void main(String[] args)
+      throws IOException {
+    Map<String, String> props = new HashMap<>();
+    props.put(StreamConfigProperties
+        .constructStreamProperty(KinesisConfig.STREAM_TYPE, StreamConfigProperties.STREAM_TOPIC_NAME), STREAM_NAME);
+    props.put(KinesisConfig.AWS_REGION, AWS_REGION);
+    props.put(KinesisConfig.MAX_RECORDS_TO_FETCH, "10");
+    props.put(KinesisConfig.SHARD_ITERATOR_TYPE, ShardIteratorType.AT_SEQUENCE_NUMBER.toString());
+    KinesisConfig kinesisConfig = new KinesisConfig(props);
+    KinesisConnectionHandler kinesisConnectionHandler = new KinesisConnectionHandler(STREAM_NAME, AWS_REGION);
+    List<Shard> shardList = kinesisConnectionHandler.getShards();
+    for (Shard shard : shardList) {
+      System.out.println("SHARD: " + shard.shardId());

Review comment:
       Use logger (if this is a real test)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar merged pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar merged pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r624605113



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConnectionHandler.java
##########
@@ -0,0 +1,76 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.List;
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ListShardsRequest;
+import software.amazon.awssdk.services.kinesis.model.ListShardsResponse;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * Manages the Kinesis stream connection, given the stream name and aws region
+ */
+public class KinesisConnectionHandler {
+  protected KinesisClient _kinesisClient;
+  private final String _stream;
+  private final String _awsRegion;
+
+  public KinesisConnectionHandler(String stream, String awsRegion) {
+    _stream = stream;
+    _awsRegion = awsRegion;
+    createConnection();
+  }
+
+  public KinesisConnectionHandler(String stream, String awsRegion, KinesisClient kinesisClient) {
+    _stream = stream;
+    _awsRegion = awsRegion;
+    _kinesisClient = kinesisClient;
+  }
+
+  /**
+   * Lists all shards of the stream
+   */
+  public List<Shard> getShards() {
+    ListShardsResponse listShardsResponse =
+        _kinesisClient.listShards(ListShardsRequest.builder().streamName(_stream).build());
+    return listShardsResponse.shards();
+  }
+
+  /**
+   * Creates a Kinesis client for the stream
+   */
+  public void createConnection() {
+    if (_kinesisClient == null) {
+      _kinesisClient =
+          KinesisClient.builder().region(Region.of(_awsRegion)).credentialsProvider(DefaultCredentialsProvider.create())

Review comment:
       good catch, yes we prolly need to do something similar here, will add




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r630583092



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisStreamMetadataProvider.java
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.spi.stream.MessageBatch;
+import org.apache.pinot.spi.stream.OffsetCriteria;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.PartitionGroupConsumptionStatus;
+import org.apache.pinot.spi.stream.PartitionGroupMetadata;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConsumerFactory;
+import org.apache.pinot.spi.stream.StreamConsumerFactoryProvider;
+import org.apache.pinot.spi.stream.StreamMetadataProvider;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * A {@link StreamMetadataProvider} implementation for the Kinesis stream
+ */
+public class KinesisStreamMetadataProvider implements StreamMetadataProvider {
+  private final KinesisConnectionHandler _kinesisConnectionHandler;
+  private final StreamConsumerFactory _kinesisStreamConsumerFactory;
+  private final String _clientId;
+  private final int _fetchTimeoutMs;
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = new KinesisConnectionHandler(kinesisConfig.getStream(), kinesisConfig.getAwsRegion());
+    _kinesisStreamConsumerFactory = StreamConsumerFactoryProvider.create(streamConfig);
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig,
+      KinesisConnectionHandler kinesisConnectionHandler, StreamConsumerFactory streamConsumerFactory) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = kinesisConnectionHandler;
+    _kinesisStreamConsumerFactory = streamConsumerFactory;
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  @Override
+  public int fetchPartitionCount(long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public long fetchPartitionOffset(@Nonnull OffsetCriteria offsetCriteria, long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  /**
+   * This call returns all active shards, taking into account the consumption status for those shards.
+   * {@link PartitionGroupMetadata} is returned for a shard if:
+   * 1. It is a branch new shard AND its parent has been consumed completely
+   * 2. It is still being actively consumed from i.e. the consuming partition has not reached the end of the shard
+   */
+  @Override
+  public List<PartitionGroupMetadata> computePartitionGroupMetadata(String clientId, StreamConfig streamConfig,
+      List<PartitionGroupConsumptionStatus> partitionGroupConsumptionStatuses, int timeoutMillis)
+      throws IOException, TimeoutException {
+
+    List<PartitionGroupMetadata> newPartitionGroupMetadatas = new ArrayList<>();
+
+    Map<String, Shard> shardIdToShardMap = _kinesisConnectionHandler.getShards().stream()
+        .collect(Collectors.toMap(Shard::shardId, s -> s, (s1, s2) -> s1));
+    Set<String> shardsInCurrent = new HashSet<>();
+    Set<String> shardsEnded = new HashSet<>();
+
+    // TODO: Once we start supporting multiple shards in a PartitionGroup,
+    //  we need to iterate over all shards to check if any of them have reached end
+
+    // Process existing shards. Add them to new list if still consuming from them
+    for (PartitionGroupConsumptionStatus currentPartitionGroupConsumptionStatus : partitionGroupConsumptionStatuses) {
+      KinesisPartitionGroupOffset kinesisStartCheckpoint =
+          (KinesisPartitionGroupOffset) currentPartitionGroupConsumptionStatus.getStartOffset();
+      String shardId = kinesisStartCheckpoint.getShardToStartSequenceMap().keySet().iterator().next();
+      Shard shard = shardIdToShardMap.get(shardId);
+      shardsInCurrent.add(shardId);
+
+      StreamPartitionMsgOffset newStartOffset;
+      StreamPartitionMsgOffset currentEndOffset = currentPartitionGroupConsumptionStatus.getEndOffset();
+      if (currentEndOffset != null) { // Segment DONE (committing/committed)
+        String endingSequenceNumber = shard.sequenceNumberRange().endingSequenceNumber();
+        if (endingSequenceNumber != null) { // Shard has ended, check if we're also done consuming it
+          if (consumedEndOfShard(currentEndOffset, currentPartitionGroupConsumptionStatus)) {
+            shardsEnded.add(shardId);
+            continue; // Shard ended and we're done consuming it. Skip
+          }
+        }
+        newStartOffset = currentEndOffset;
+      } else { // Segment IN_PROGRESS
+        newStartOffset = currentPartitionGroupConsumptionStatus.getStartOffset();
+      }
+      newPartitionGroupMetadatas.add(
+          new PartitionGroupMetadata(currentPartitionGroupConsumptionStatus.getPartitionGroupId(), newStartOffset));
+    }
+
+    // Add new shards. Parent should be null (new table case, very first shards)
+    // OR it should be flagged as reached EOL and completely consumed.
+    for (Map.Entry<String, Shard> entry : shardIdToShardMap.entrySet()) {
+      String newShardId = entry.getKey();
+      if (shardsInCurrent.contains(newShardId)) {
+        continue;
+      }
+      StreamPartitionMsgOffset newStartOffset;
+      Shard newShard = entry.getValue();
+      String parentShardId = newShard.parentShardId();
+
+      if (parentShardId == null || shardsEnded.contains(parentShardId)) {

Review comment:
       fixed in the new shards case.
   Thought of another edge case (shard expired due to retention but the consumer was not done consuming it). That's a more tricky case, and i've added a todo for now, because i dont know if practically we'll reach it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r630521582



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisPartitionGroupOffset.java
##########
@@ -0,0 +1,75 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+/**
+ * A {@link StreamPartitionMsgOffset} implementation for the Kinesis partition group consumption
+ * A partition group consists of 1 or more shards. The KinesisCheckpoint maintains a Map of shards to the sequenceNumber

Review comment:
       Added more lines about sequence number.
   Regarding it being inclusive or exclusive, this is exactly like the "offset" in kafka. Whether it is inclusive or exclusive will depend on the context e.g. startOffset, endOffset, catchupOffset




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] snleee commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
snleee commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r612080251



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConnectionHandler.java
##########
@@ -0,0 +1,76 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.List;
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ListShardsRequest;
+import software.amazon.awssdk.services.kinesis.model.ListShardsResponse;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * Manages the Kinesis stream connection, given the stream name and aws region
+ */
+public class KinesisConnectionHandler {
+  protected KinesisClient _kinesisClient;
+  private final String _stream;
+  private final String _awsRegion;
+
+  public KinesisConnectionHandler(String stream, String awsRegion) {
+    _stream = stream;
+    _awsRegion = awsRegion;
+    createConnection();
+  }
+
+  public KinesisConnectionHandler(String stream, String awsRegion, KinesisClient kinesisClient) {
+    _stream = stream;
+    _awsRegion = awsRegion;
+    _kinesisClient = kinesisClient;
+  }
+
+  /**
+   * Lists all shards of the stream
+   */
+  public List<Shard> getShards() {
+    ListShardsResponse listShardsResponse =
+        _kinesisClient.listShards(ListShardsRequest.builder().streamName(_stream).build());
+    return listShardsResponse.shards();
+  }
+
+  /**
+   * Creates a Kinesis client for the stream
+   */
+  public void createConnection() {
+    if (_kinesisClient == null) {
+      _kinesisClient =
+          KinesisClient.builder().region(Region.of(_awsRegion)).credentialsProvider(DefaultCredentialsProvider.create())

Review comment:
       `S3PinotFS` has a way of reading `accessKey` and `secretKey` from the config. Do we need a similar thing or `DefaultCredentialsProvider.create()` will be enough?

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisPartitionGroupOffset.java
##########
@@ -0,0 +1,75 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+/**
+ * A {@link StreamPartitionMsgOffset} implementation for the Kinesis partition group consumption
+ * A partition group consists of 1 or more shards. The KinesisCheckpoint maintains a Map of shards to the sequenceNumber
+ */
+public class KinesisPartitionGroupOffset implements StreamPartitionMsgOffset {
+  private final Map<String, String> _shardToStartSequenceMap;
+
+  public KinesisPartitionGroupOffset(Map<String, String> shardToStartSequenceMap) {
+    _shardToStartSequenceMap = shardToStartSequenceMap;
+  }
+
+  public KinesisPartitionGroupOffset(String offsetStr)
+      throws IOException {
+    _shardToStartSequenceMap = JsonUtils.stringToObject(offsetStr, new TypeReference<Map<String, String>>() {
+    });
+  }
+
+  public Map<String, String> getShardToStartSequenceMap() {
+    return _shardToStartSequenceMap;
+  }
+
+  @Override
+  public String toString() {
+    try {
+      return JsonUtils.objectToString(_shardToStartSequenceMap);
+    } catch (JsonProcessingException e) {
+      throw new IllegalStateException(
+          "Caught exception when converting KinesisCheckpoint to string: " + _shardToStartSequenceMap);
+    }
+  }
+
+  @Override
+  public KinesisPartitionGroupOffset fromString(String kinesisCheckpointStr) {
+    try {
+      return new KinesisPartitionGroupOffset(kinesisCheckpointStr);
+    } catch (IOException e) {
+      throw new IllegalStateException(
+          "Caught exception when converting string to KinesisCheckpoint: " + kinesisCheckpointStr);
+    }
+  }
+
+  @Override
+  public int compareTo(Object o) {

Review comment:
       @npawar Where do we use `compareTo` for the `StreamPartitionOffset`?

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisPartitionGroupOffset.java
##########
@@ -0,0 +1,75 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+/**
+ * A {@link StreamPartitionMsgOffset} implementation for the Kinesis partition group consumption
+ * A partition group consists of 1 or more shards. The KinesisCheckpoint maintains a Map of shards to the sequenceNumber
+ */
+public class KinesisPartitionGroupOffset implements StreamPartitionMsgOffset {
+  private final Map<String, String> _shardToStartSequenceMap;
+
+  public KinesisPartitionGroupOffset(Map<String, String> shardToStartSequenceMap) {
+    _shardToStartSequenceMap = shardToStartSequenceMap;
+  }
+
+  public KinesisPartitionGroupOffset(String offsetStr)
+      throws IOException {
+    _shardToStartSequenceMap = JsonUtils.stringToObject(offsetStr, new TypeReference<Map<String, String>>() {
+    });
+  }
+
+  public Map<String, String> getShardToStartSequenceMap() {
+    return _shardToStartSequenceMap;
+  }
+
+  @Override
+  public String toString() {
+    try {
+      return JsonUtils.objectToString(_shardToStartSequenceMap);
+    } catch (JsonProcessingException e) {
+      throw new IllegalStateException(
+          "Caught exception when converting KinesisCheckpoint to string: " + _shardToStartSequenceMap);
+    }
+  }
+
+  @Override
+  public KinesisPartitionGroupOffset fromString(String kinesisCheckpointStr) {
+    try {
+      return new KinesisPartitionGroupOffset(kinesisCheckpointStr);
+    } catch (IOException e) {
+      throw new IllegalStateException(
+          "Caught exception when converting string to KinesisCheckpoint: " + kinesisCheckpointStr);
+    }
+  }
+
+  @Override
+  public int compareTo(Object o) {
+    return this._shardToStartSequenceMap.values().iterator().next()

Review comment:
       Do we handle null or empty maps correctly?

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisStreamMetadataProvider.java
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.spi.stream.MessageBatch;
+import org.apache.pinot.spi.stream.OffsetCriteria;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.PartitionGroupConsumptionStatus;
+import org.apache.pinot.spi.stream.PartitionGroupMetadata;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConsumerFactory;
+import org.apache.pinot.spi.stream.StreamConsumerFactoryProvider;
+import org.apache.pinot.spi.stream.StreamMetadataProvider;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * A {@link StreamMetadataProvider} implementation for the Kinesis stream
+ */
+public class KinesisStreamMetadataProvider implements StreamMetadataProvider {
+  private final KinesisConnectionHandler _kinesisConnectionHandler;
+  private final StreamConsumerFactory _kinesisStreamConsumerFactory;
+  private final String _clientId;
+  private final int _fetchTimeoutMs;
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = new KinesisConnectionHandler(kinesisConfig.getStream(), kinesisConfig.getAwsRegion());
+    _kinesisStreamConsumerFactory = StreamConsumerFactoryProvider.create(streamConfig);
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig,
+      KinesisConnectionHandler kinesisConnectionHandler, StreamConsumerFactory streamConsumerFactory) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = kinesisConnectionHandler;
+    _kinesisStreamConsumerFactory = streamConsumerFactory;
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  @Override
+  public int fetchPartitionCount(long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public long fetchPartitionOffset(@Nonnull OffsetCriteria offsetCriteria, long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  /**
+   * This call returns all active shards, taking into account the consumption status for those shards.
+   * {@link PartitionGroupMetadata} is returned for a shard if:
+   * 1. It is a branch new shard AND its parent has been consumed completely
+   * 2. It is still being actively consumed from i.e. the consuming partition has not reached the end of the shard
+   */
+  @Override
+  public List<PartitionGroupMetadata> computePartitionGroupMetadata(String clientId, StreamConfig streamConfig,
+      List<PartitionGroupConsumptionStatus> partitionGroupConsumptionStatuses, int timeoutMillis)
+      throws IOException, TimeoutException {
+
+    List<PartitionGroupMetadata> newPartitionGroupMetadatas = new ArrayList<>();

Review comment:
       `newPartitionGroupMetadatas` -> `newPartitionGroupMetadataList`

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumer.java
##########
@@ -0,0 +1,194 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsResponse;
+import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
+import software.amazon.awssdk.services.kinesis.model.InvalidArgumentException;
+import software.amazon.awssdk.services.kinesis.model.KinesisException;
+import software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException;
+import software.amazon.awssdk.services.kinesis.model.Record;
+import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * A {@link PartitionGroupConsumer} implementation for the Kinesis stream
+ */
+public class KinesisConsumer extends KinesisConnectionHandler implements PartitionGroupConsumer {
+  private final Logger LOG = LoggerFactory.getLogger(KinesisConsumer.class);

Review comment:
       Let's rename `LOG` -> `LOGGER` to keep the convention

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConfig.java
##########
@@ -0,0 +1,68 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConfigProperties;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * Kinesis stream specific config
+ */
+public class KinesisConfig {
+  public static final String STREAM_TYPE = "kinesis";
+  public static final String SHARD_ITERATOR_TYPE = "shard-iterator-type";
+  public static final String AWS_REGION = "aws-region";
+  public static final String MAX_RECORDS_TO_FETCH = "max-records-to-fetch";
+  public static final String DEFAULT_AWS_REGION = "us-central-1";
+  public static final String DEFAULT_MAX_RECORDS = "20";

Review comment:
       Is this some random number or it's based on some observation or experiment?
   
   If we simply put a rough number to begin with, let's add `TODO` comment on finding the good default number for this.

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConfig.java
##########
@@ -0,0 +1,68 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConfigProperties;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * Kinesis stream specific config
+ */
+public class KinesisConfig {
+  public static final String STREAM_TYPE = "kinesis";
+  public static final String SHARD_ITERATOR_TYPE = "shard-iterator-type";
+  public static final String AWS_REGION = "aws-region";
+  public static final String MAX_RECORDS_TO_FETCH = "max-records-to-fetch";
+  public static final String DEFAULT_AWS_REGION = "us-central-1";
+  public static final String DEFAULT_MAX_RECORDS = "20";
+  public static final String DEFAULT_SHARD_ITERATOR_TYPE = ShardIteratorType.LATEST.toString();
+  private final Map<String, String> _props;
+
+  public KinesisConfig(StreamConfig streamConfig) {
+    _props = streamConfig.getStreamConfigsMap();
+  }
+
+  public KinesisConfig(Map<String, String> props) {
+    _props = props;
+  }
+
+  public String getStream() {
+    return _props
+        .get(StreamConfigProperties.constructStreamProperty(STREAM_TYPE, StreamConfigProperties.STREAM_TOPIC_NAME));
+  }
+
+  public String getAwsRegion() {
+    return _props.getOrDefault(AWS_REGION, DEFAULT_AWS_REGION);
+  }
+
+  public Integer maxRecordsToFetch() {

Review comment:
       Rename to `getNumMaxRecordsToFecth()` to keep the convention

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConfig.java
##########
@@ -0,0 +1,68 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConfigProperties;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * Kinesis stream specific config
+ */
+public class KinesisConfig {
+  public static final String STREAM_TYPE = "kinesis";
+  public static final String SHARD_ITERATOR_TYPE = "shard-iterator-type";
+  public static final String AWS_REGION = "aws-region";
+  public static final String MAX_RECORDS_TO_FETCH = "max-records-to-fetch";
+  public static final String DEFAULT_AWS_REGION = "us-central-1";

Review comment:
       I think that we should not put the default value for the region because we cannot make the assumption that the kinesis topic is available in the `us-central-1`. It's better to throw the exception and make this config as `the required field` when using a kinesis based consumer.

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/pom.xml
##########
@@ -0,0 +1,177 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>pinot-stream-ingestion</artifactId>
+    <groupId>org.apache.pinot</groupId>
+    <version>0.7.0-SNAPSHOT</version>
+    <relativePath>..</relativePath>
+  </parent>
+
+  <artifactId>pinot-kinesis</artifactId>
+  <name>Pinot Kinesis</name>
+  <url>https://pinot.apache.org/</url>
+  <properties>
+    <pinot.root>${basedir}/../../..</pinot.root>
+    <phase.prop>package</phase.prop>
+    <aws.version>2.14.28</aws.version>

Review comment:
       Is there a particular reason on why we are pinning the specific versions here instead of the main pom file? In my understanding, we pin the versions in the top level pom file.

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConfig.java
##########
@@ -0,0 +1,68 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConfigProperties;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * Kinesis stream specific config
+ */
+public class KinesisConfig {
+  public static final String STREAM_TYPE = "kinesis";
+  public static final String SHARD_ITERATOR_TYPE = "shard-iterator-type";
+  public static final String AWS_REGION = "aws-region";
+  public static final String MAX_RECORDS_TO_FETCH = "max-records-to-fetch";
+  public static final String DEFAULT_AWS_REGION = "us-central-1";
+  public static final String DEFAULT_MAX_RECORDS = "20";
+  public static final String DEFAULT_SHARD_ITERATOR_TYPE = ShardIteratorType.LATEST.toString();
+  private final Map<String, String> _props;
+
+  public KinesisConfig(StreamConfig streamConfig) {
+    _props = streamConfig.getStreamConfigsMap();
+  }
+
+  public KinesisConfig(Map<String, String> props) {
+    _props = props;
+  }
+
+  public String getStream() {

Review comment:
       `getStream()-> getStreamTopicName()` 

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConnectionHandler.java
##########
@@ -0,0 +1,76 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.List;
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ListShardsRequest;
+import software.amazon.awssdk.services.kinesis.model.ListShardsResponse;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * Manages the Kinesis stream connection, given the stream name and aws region
+ */
+public class KinesisConnectionHandler {
+  protected KinesisClient _kinesisClient;
+  private final String _stream;
+  private final String _awsRegion;
+
+  public KinesisConnectionHandler(String stream, String awsRegion) {

Review comment:
       We need the validation for `stream topic name` and `aws region` somewhere (probably kinesis config is the good place)

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConnectionHandler.java
##########
@@ -0,0 +1,76 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.List;
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ListShardsRequest;
+import software.amazon.awssdk.services.kinesis.model.ListShardsResponse;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * Manages the Kinesis stream connection, given the stream name and aws region
+ */
+public class KinesisConnectionHandler {
+  protected KinesisClient _kinesisClient;
+  private final String _stream;
+  private final String _awsRegion;
+
+  public KinesisConnectionHandler(String stream, String awsRegion) {
+    _stream = stream;
+    _awsRegion = awsRegion;
+    createConnection();
+  }
+
+  public KinesisConnectionHandler(String stream, String awsRegion, KinesisClient kinesisClient) {

Review comment:
       Why do we need the constructor that would pass the `kinesisClient`? I thought the main purpose of this connection handler is to create the client object by creating a connection?

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumer.java
##########
@@ -0,0 +1,194 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsResponse;
+import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
+import software.amazon.awssdk.services.kinesis.model.InvalidArgumentException;
+import software.amazon.awssdk.services.kinesis.model.KinesisException;
+import software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException;
+import software.amazon.awssdk.services.kinesis.model.Record;
+import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * A {@link PartitionGroupConsumer} implementation for the Kinesis stream
+ */
+public class KinesisConsumer extends KinesisConnectionHandler implements PartitionGroupConsumer {
+  private final Logger LOG = LoggerFactory.getLogger(KinesisConsumer.class);
+  private final String _stream;

Review comment:
       `_stream -> _streamTopicName or _streamName`

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumer.java
##########
@@ -0,0 +1,194 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsResponse;
+import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
+import software.amazon.awssdk.services.kinesis.model.InvalidArgumentException;
+import software.amazon.awssdk.services.kinesis.model.KinesisException;
+import software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException;
+import software.amazon.awssdk.services.kinesis.model.Record;
+import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * A {@link PartitionGroupConsumer} implementation for the Kinesis stream
+ */
+public class KinesisConsumer extends KinesisConnectionHandler implements PartitionGroupConsumer {
+  private final Logger LOG = LoggerFactory.getLogger(KinesisConsumer.class);
+  private final String _stream;
+  private final int _maxRecords;

Review comment:
       `_numMaxRecordsToFetch`

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumer.java
##########
@@ -0,0 +1,194 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsResponse;
+import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
+import software.amazon.awssdk.services.kinesis.model.InvalidArgumentException;
+import software.amazon.awssdk.services.kinesis.model.KinesisException;
+import software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException;
+import software.amazon.awssdk.services.kinesis.model.Record;
+import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * A {@link PartitionGroupConsumer} implementation for the Kinesis stream
+ */
+public class KinesisConsumer extends KinesisConnectionHandler implements PartitionGroupConsumer {
+  private final Logger LOG = LoggerFactory.getLogger(KinesisConsumer.class);
+  private final String _stream;
+  private final int _maxRecords;
+  private final ExecutorService _executorService;

Review comment:
       Why do we need to create the executor service?

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisPartitionGroupOffset.java
##########
@@ -0,0 +1,75 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+/**
+ * A {@link StreamPartitionMsgOffset} implementation for the Kinesis partition group consumption
+ * A partition group consists of 1 or more shards. The KinesisCheckpoint maintains a Map of shards to the sequenceNumber

Review comment:
       Can you add more description of `sequenceNumber`? I guess that the sequence number is the Kinesis specific term. Can you add a bit more explanation? Also, is this sequence number inclusive or exclusive?
   
   e.g. Let's say that we have a check point,`streamA : 123`. Does this mean that `we have consumed all records from streamA up to the sequence number 123 (inclusive)`?
   
   Als

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConfig.java
##########
@@ -0,0 +1,68 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConfigProperties;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * Kinesis stream specific config
+ */
+public class KinesisConfig {
+  public static final String STREAM_TYPE = "kinesis";
+  public static final String SHARD_ITERATOR_TYPE = "shard-iterator-type";
+  public static final String AWS_REGION = "aws-region";
+  public static final String MAX_RECORDS_TO_FETCH = "max-records-to-fetch";
+  public static final String DEFAULT_AWS_REGION = "us-central-1";
+  public static final String DEFAULT_MAX_RECORDS = "20";
+  public static final String DEFAULT_SHARD_ITERATOR_TYPE = ShardIteratorType.LATEST.toString();
+  private final Map<String, String> _props;
+
+  public KinesisConfig(StreamConfig streamConfig) {
+    _props = streamConfig.getStreamConfigsMap();
+  }
+
+  public KinesisConfig(Map<String, String> props) {
+    _props = props;
+  }
+
+  public String getStream() {
+    return _props
+        .get(StreamConfigProperties.constructStreamProperty(STREAM_TYPE, StreamConfigProperties.STREAM_TOPIC_NAME));
+  }
+
+  public String getAwsRegion() {
+    return _props.getOrDefault(AWS_REGION, DEFAULT_AWS_REGION);
+  }
+
+  public Integer maxRecordsToFetch() {
+    return Integer.parseInt(_props.getOrDefault(MAX_RECORDS_TO_FETCH, DEFAULT_MAX_RECORDS));
+  }
+
+  public ShardIteratorType getShardIteratorType() {
+    return ShardIteratorType.fromValue(_props.getOrDefault(SHARD_ITERATOR_TYPE, DEFAULT_SHARD_ITERATOR_TYPE));
+  }
+
+  public void setMaxRecordsToFetch(int maxRecordsToFetch){

Review comment:
       Why do we need the setter here? For the config, I think that we should keep this to be read-only. If you need to change this value for testing, you can create the new KinesisConfig object.

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumer.java
##########
@@ -0,0 +1,194 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsResponse;
+import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
+import software.amazon.awssdk.services.kinesis.model.InvalidArgumentException;
+import software.amazon.awssdk.services.kinesis.model.KinesisException;
+import software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException;
+import software.amazon.awssdk.services.kinesis.model.Record;
+import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * A {@link PartitionGroupConsumer} implementation for the Kinesis stream
+ */
+public class KinesisConsumer extends KinesisConnectionHandler implements PartitionGroupConsumer {
+  private final Logger LOG = LoggerFactory.getLogger(KinesisConsumer.class);
+  private final String _stream;
+  private final int _maxRecords;
+  private final ExecutorService _executorService;
+  private final ShardIteratorType _shardIteratorType;
+
+  public KinesisConsumer(KinesisConfig kinesisConfig) {
+    super(kinesisConfig.getStream(), kinesisConfig.getAwsRegion());
+    _stream = kinesisConfig.getStream();
+    _maxRecords = kinesisConfig.maxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  public KinesisConsumer(KinesisConfig kinesisConfig, KinesisClient kinesisClient) {
+    super(kinesisConfig.getStream(), kinesisConfig.getAwsRegion(), kinesisClient);
+    _kinesisClient = kinesisClient;
+    _stream = kinesisConfig.getStream();
+    _maxRecords = kinesisConfig.maxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  /**
+   * Fetch records from the Kinesis stream between the start and end KinesisCheckpoint
+   */
+  @Override
+  public KinesisRecordsBatch fetchMessages(StreamPartitionMsgOffset startCheckpoint,
+      StreamPartitionMsgOffset endCheckpoint, int timeoutMs) {
+    List<Record> recordList = new ArrayList<>();
+    Future<KinesisRecordsBatch> kinesisFetchResultFuture =
+        _executorService.submit(() -> getResult(startCheckpoint, endCheckpoint, recordList));
+
+    try {
+      return kinesisFetchResultFuture.get(timeoutMs, TimeUnit.MILLISECONDS);
+    } catch (Exception e) {
+      return handleException((KinesisPartitionGroupOffset) startCheckpoint, recordList);
+    }
+  }
+
+  private KinesisRecordsBatch getResult(StreamPartitionMsgOffset start, StreamPartitionMsgOffset end,
+      List<Record> recordList) {
+    KinesisPartitionGroupOffset kinesisStartCheckpoint = (KinesisPartitionGroupOffset) start;
+
+    try {
+
+      if (_kinesisClient == null) {
+        createConnection();
+      }
+
+      //TODO: iterate upon all the shardIds in the map
+      // Okay for now, since we have assumed that every partition group contains a single shard
+      Map.Entry<String, String> shardToSequenceNum =
+          kinesisStartCheckpoint.getShardToStartSequenceMap().entrySet().iterator().next();
+      String shardIterator = getShardIterator(shardToSequenceNum.getKey(), shardToSequenceNum.getValue());
+
+      String kinesisEndSequenceNumber = null;
+
+      if (end != null) {
+        KinesisPartitionGroupOffset kinesisEndCheckpoint = (KinesisPartitionGroupOffset) end;
+        kinesisEndSequenceNumber = kinesisEndCheckpoint.getShardToStartSequenceMap().values().iterator().next();
+      }
+
+      String nextStartSequenceNumber = null;
+      boolean isEndOfShard = false;
+
+      while (shardIterator != null) {
+        GetRecordsRequest getRecordsRequest = GetRecordsRequest.builder().shardIterator(shardIterator).build();
+        GetRecordsResponse getRecordsResponse = _kinesisClient.getRecords(getRecordsRequest);
+
+        if (getRecordsResponse.records().size() > 0) {
+          recordList.addAll(getRecordsResponse.records());
+          nextStartSequenceNumber = recordList.get(recordList.size() - 1).sequenceNumber();
+
+          if (kinesisEndSequenceNumber != null && kinesisEndSequenceNumber.compareTo(nextStartSequenceNumber) <= 0) {
+            nextStartSequenceNumber = kinesisEndSequenceNumber;
+            break;
+          }
+
+          if (recordList.size() >= _maxRecords) {
+            break;
+          }
+        }
+
+        if (getRecordsResponse.hasChildShards()) {
+          //This statement returns true only when end of current shard has reached.
+          isEndOfShard = true;
+          break;
+        }
+
+        shardIterator = getRecordsResponse.nextShardIterator();
+      }
+
+      return new KinesisRecordsBatch(recordList, shardToSequenceNum.getKey(), isEndOfShard);
+    } catch (IllegalStateException e) {
+      LOG.warn("Illegal state exception, connection is broken", e);
+      return handleException(kinesisStartCheckpoint, recordList);
+    } catch (ProvisionedThroughputExceededException e) {
+      LOG.warn("The request rate for the stream is too high", e);
+      return handleException(kinesisStartCheckpoint, recordList);
+    } catch (ExpiredIteratorException e) {
+      LOG.warn("ShardIterator expired while trying to fetch records", e);
+      return handleException(kinesisStartCheckpoint, recordList);
+    } catch (ResourceNotFoundException | InvalidArgumentException e) {
+      // aws errors
+      LOG.error("Encountered AWS error while attempting to fetch records", e);
+      return handleException(kinesisStartCheckpoint, recordList);
+    } catch (KinesisException e) {
+      LOG.warn("Encountered unknown unrecoverable AWS exception", e);
+      throw new RuntimeException(e);
+    } catch (Throwable e) {
+      // non transient errors
+      LOG.error("Unknown fetchRecords exception", e);
+      throw new RuntimeException(e);
+    }
+  }
+
+  private KinesisRecordsBatch handleException(KinesisPartitionGroupOffset start, List<Record> recordList) {
+    String shardId = start.getShardToStartSequenceMap().entrySet().iterator().next().getKey();
+
+    if (recordList.size() > 0) {
+      String nextStartSequenceNumber = recordList.get(recordList.size() - 1).sequenceNumber();
+      Map<String, String> newCheckpoint = new HashMap<>(start.getShardToStartSequenceMap());
+      newCheckpoint.put(newCheckpoint.keySet().iterator().next(), nextStartSequenceNumber);
+    }
+    return new KinesisRecordsBatch(recordList, shardId, false);
+  }
+
+  private String getShardIterator(String shardId, String sequenceNumber) {
+

Review comment:
       remove line

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumer.java
##########
@@ -0,0 +1,194 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsResponse;
+import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
+import software.amazon.awssdk.services.kinesis.model.InvalidArgumentException;
+import software.amazon.awssdk.services.kinesis.model.KinesisException;
+import software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException;
+import software.amazon.awssdk.services.kinesis.model.Record;
+import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * A {@link PartitionGroupConsumer} implementation for the Kinesis stream
+ */
+public class KinesisConsumer extends KinesisConnectionHandler implements PartitionGroupConsumer {
+  private final Logger LOG = LoggerFactory.getLogger(KinesisConsumer.class);
+  private final String _stream;
+  private final int _maxRecords;
+  private final ExecutorService _executorService;
+  private final ShardIteratorType _shardIteratorType;
+
+  public KinesisConsumer(KinesisConfig kinesisConfig) {
+    super(kinesisConfig.getStream(), kinesisConfig.getAwsRegion());
+    _stream = kinesisConfig.getStream();
+    _maxRecords = kinesisConfig.maxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  public KinesisConsumer(KinesisConfig kinesisConfig, KinesisClient kinesisClient) {
+    super(kinesisConfig.getStream(), kinesisConfig.getAwsRegion(), kinesisClient);
+    _kinesisClient = kinesisClient;
+    _stream = kinesisConfig.getStream();
+    _maxRecords = kinesisConfig.maxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  /**
+   * Fetch records from the Kinesis stream between the start and end KinesisCheckpoint
+   */
+  @Override
+  public KinesisRecordsBatch fetchMessages(StreamPartitionMsgOffset startCheckpoint,
+      StreamPartitionMsgOffset endCheckpoint, int timeoutMs) {
+    List<Record> recordList = new ArrayList<>();
+    Future<KinesisRecordsBatch> kinesisFetchResultFuture =
+        _executorService.submit(() -> getResult(startCheckpoint, endCheckpoint, recordList));
+
+    try {
+      return kinesisFetchResultFuture.get(timeoutMs, TimeUnit.MILLISECONDS);
+    } catch (Exception e) {
+      return handleException((KinesisPartitionGroupOffset) startCheckpoint, recordList);
+    }
+  }
+
+  private KinesisRecordsBatch getResult(StreamPartitionMsgOffset start, StreamPartitionMsgOffset end,
+      List<Record> recordList) {
+    KinesisPartitionGroupOffset kinesisStartCheckpoint = (KinesisPartitionGroupOffset) start;
+
+    try {
+
+      if (_kinesisClient == null) {
+        createConnection();
+      }
+
+      //TODO: iterate upon all the shardIds in the map
+      // Okay for now, since we have assumed that every partition group contains a single shard
+      Map.Entry<String, String> shardToSequenceNum =
+          kinesisStartCheckpoint.getShardToStartSequenceMap().entrySet().iterator().next();
+      String shardIterator = getShardIterator(shardToSequenceNum.getKey(), shardToSequenceNum.getValue());
+
+      String kinesisEndSequenceNumber = null;
+
+      if (end != null) {
+        KinesisPartitionGroupOffset kinesisEndCheckpoint = (KinesisPartitionGroupOffset) end;
+        kinesisEndSequenceNumber = kinesisEndCheckpoint.getShardToStartSequenceMap().values().iterator().next();
+      }
+
+      String nextStartSequenceNumber = null;
+      boolean isEndOfShard = false;
+
+      while (shardIterator != null) {
+        GetRecordsRequest getRecordsRequest = GetRecordsRequest.builder().shardIterator(shardIterator).build();
+        GetRecordsResponse getRecordsResponse = _kinesisClient.getRecords(getRecordsRequest);
+
+        if (getRecordsResponse.records().size() > 0) {
+          recordList.addAll(getRecordsResponse.records());
+          nextStartSequenceNumber = recordList.get(recordList.size() - 1).sequenceNumber();
+
+          if (kinesisEndSequenceNumber != null && kinesisEndSequenceNumber.compareTo(nextStartSequenceNumber) <= 0) {
+            nextStartSequenceNumber = kinesisEndSequenceNumber;

Review comment:
       After you assign the new value to `nextStartSequenceNumber`, it will never be accessed. So, I think that this line is redundant.

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumer.java
##########
@@ -0,0 +1,194 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsResponse;
+import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
+import software.amazon.awssdk.services.kinesis.model.InvalidArgumentException;
+import software.amazon.awssdk.services.kinesis.model.KinesisException;
+import software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException;
+import software.amazon.awssdk.services.kinesis.model.Record;
+import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * A {@link PartitionGroupConsumer} implementation for the Kinesis stream
+ */
+public class KinesisConsumer extends KinesisConnectionHandler implements PartitionGroupConsumer {
+  private final Logger LOG = LoggerFactory.getLogger(KinesisConsumer.class);
+  private final String _stream;
+  private final int _maxRecords;
+  private final ExecutorService _executorService;
+  private final ShardIteratorType _shardIteratorType;
+
+  public KinesisConsumer(KinesisConfig kinesisConfig) {
+    super(kinesisConfig.getStream(), kinesisConfig.getAwsRegion());
+    _stream = kinesisConfig.getStream();
+    _maxRecords = kinesisConfig.maxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  public KinesisConsumer(KinesisConfig kinesisConfig, KinesisClient kinesisClient) {
+    super(kinesisConfig.getStream(), kinesisConfig.getAwsRegion(), kinesisClient);
+    _kinesisClient = kinesisClient;
+    _stream = kinesisConfig.getStream();
+    _maxRecords = kinesisConfig.maxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  /**
+   * Fetch records from the Kinesis stream between the start and end KinesisCheckpoint
+   */
+  @Override
+  public KinesisRecordsBatch fetchMessages(StreamPartitionMsgOffset startCheckpoint,
+      StreamPartitionMsgOffset endCheckpoint, int timeoutMs) {
+    List<Record> recordList = new ArrayList<>();
+    Future<KinesisRecordsBatch> kinesisFetchResultFuture =
+        _executorService.submit(() -> getResult(startCheckpoint, endCheckpoint, recordList));
+
+    try {
+      return kinesisFetchResultFuture.get(timeoutMs, TimeUnit.MILLISECONDS);
+    } catch (Exception e) {
+      return handleException((KinesisPartitionGroupOffset) startCheckpoint, recordList);
+    }
+  }
+
+  private KinesisRecordsBatch getResult(StreamPartitionMsgOffset start, StreamPartitionMsgOffset end,
+      List<Record> recordList) {
+    KinesisPartitionGroupOffset kinesisStartCheckpoint = (KinesisPartitionGroupOffset) start;
+
+    try {
+
+      if (_kinesisClient == null) {
+        createConnection();
+      }
+
+      //TODO: iterate upon all the shardIds in the map
+      // Okay for now, since we have assumed that every partition group contains a single shard
+      Map.Entry<String, String> shardToSequenceNum =
+          kinesisStartCheckpoint.getShardToStartSequenceMap().entrySet().iterator().next();
+      String shardIterator = getShardIterator(shardToSequenceNum.getKey(), shardToSequenceNum.getValue());
+
+      String kinesisEndSequenceNumber = null;
+
+      if (end != null) {
+        KinesisPartitionGroupOffset kinesisEndCheckpoint = (KinesisPartitionGroupOffset) end;
+        kinesisEndSequenceNumber = kinesisEndCheckpoint.getShardToStartSequenceMap().values().iterator().next();
+      }
+
+      String nextStartSequenceNumber = null;
+      boolean isEndOfShard = false;
+
+      while (shardIterator != null) {
+        GetRecordsRequest getRecordsRequest = GetRecordsRequest.builder().shardIterator(shardIterator).build();
+        GetRecordsResponse getRecordsResponse = _kinesisClient.getRecords(getRecordsRequest);
+
+        if (getRecordsResponse.records().size() > 0) {
+          recordList.addAll(getRecordsResponse.records());
+          nextStartSequenceNumber = recordList.get(recordList.size() - 1).sequenceNumber();
+
+          if (kinesisEndSequenceNumber != null && kinesisEndSequenceNumber.compareTo(nextStartSequenceNumber) <= 0) {
+            nextStartSequenceNumber = kinesisEndSequenceNumber;
+            break;
+          }
+
+          if (recordList.size() >= _maxRecords) {
+            break;
+          }
+        }
+
+        if (getRecordsResponse.hasChildShards()) {
+          //This statement returns true only when end of current shard has reached.
+          isEndOfShard = true;
+          break;
+        }
+
+        shardIterator = getRecordsResponse.nextShardIterator();
+      }
+
+      return new KinesisRecordsBatch(recordList, shardToSequenceNum.getKey(), isEndOfShard);
+    } catch (IllegalStateException e) {
+      LOG.warn("Illegal state exception, connection is broken", e);
+      return handleException(kinesisStartCheckpoint, recordList);
+    } catch (ProvisionedThroughputExceededException e) {
+      LOG.warn("The request rate for the stream is too high", e);
+      return handleException(kinesisStartCheckpoint, recordList);
+    } catch (ExpiredIteratorException e) {
+      LOG.warn("ShardIterator expired while trying to fetch records", e);
+      return handleException(kinesisStartCheckpoint, recordList);
+    } catch (ResourceNotFoundException | InvalidArgumentException e) {
+      // aws errors
+      LOG.error("Encountered AWS error while attempting to fetch records", e);
+      return handleException(kinesisStartCheckpoint, recordList);
+    } catch (KinesisException e) {
+      LOG.warn("Encountered unknown unrecoverable AWS exception", e);
+      throw new RuntimeException(e);
+    } catch (Throwable e) {
+      // non transient errors
+      LOG.error("Unknown fetchRecords exception", e);
+      throw new RuntimeException(e);
+    }
+  }
+
+  private KinesisRecordsBatch handleException(KinesisPartitionGroupOffset start, List<Record> recordList) {
+    String shardId = start.getShardToStartSequenceMap().entrySet().iterator().next().getKey();
+
+    if (recordList.size() > 0) {
+      String nextStartSequenceNumber = recordList.get(recordList.size() - 1).sequenceNumber();
+      Map<String, String> newCheckpoint = new HashMap<>(start.getShardToStartSequenceMap());
+      newCheckpoint.put(newCheckpoint.keySet().iterator().next(), nextStartSequenceNumber);
+    }
+    return new KinesisRecordsBatch(recordList, shardId, false);
+  }
+
+  private String getShardIterator(String shardId, String sequenceNumber) {
+
+    GetShardIteratorRequest.Builder requestBuilder =
+        GetShardIteratorRequest.builder().streamName(_stream).shardId(shardId).shardIteratorType(_shardIteratorType);
+
+    if (sequenceNumber != null && _shardIteratorType.toString().contains("SEQUENCE")) {

Review comment:
       Let's check the exact string against `ShardIteratorType.AT_SEQUENCE_NUMBER` and `ShardIteratorType.AFTER_SEQUENCE_NUMBER`

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisStreamMetadataProvider.java
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.spi.stream.MessageBatch;
+import org.apache.pinot.spi.stream.OffsetCriteria;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.PartitionGroupConsumptionStatus;
+import org.apache.pinot.spi.stream.PartitionGroupMetadata;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConsumerFactory;
+import org.apache.pinot.spi.stream.StreamConsumerFactoryProvider;
+import org.apache.pinot.spi.stream.StreamMetadataProvider;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * A {@link StreamMetadataProvider} implementation for the Kinesis stream
+ */
+public class KinesisStreamMetadataProvider implements StreamMetadataProvider {
+  private final KinesisConnectionHandler _kinesisConnectionHandler;
+  private final StreamConsumerFactory _kinesisStreamConsumerFactory;
+  private final String _clientId;
+  private final int _fetchTimeoutMs;
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = new KinesisConnectionHandler(kinesisConfig.getStream(), kinesisConfig.getAwsRegion());
+    _kinesisStreamConsumerFactory = StreamConsumerFactoryProvider.create(streamConfig);
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig,
+      KinesisConnectionHandler kinesisConnectionHandler, StreamConsumerFactory streamConsumerFactory) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = kinesisConnectionHandler;
+    _kinesisStreamConsumerFactory = streamConsumerFactory;
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  @Override
+  public int fetchPartitionCount(long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public long fetchPartitionOffset(@Nonnull OffsetCriteria offsetCriteria, long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  /**
+   * This call returns all active shards, taking into account the consumption status for those shards.
+   * {@link PartitionGroupMetadata} is returned for a shard if:
+   * 1. It is a branch new shard AND its parent has been consumed completely
+   * 2. It is still being actively consumed from i.e. the consuming partition has not reached the end of the shard
+   */
+  @Override
+  public List<PartitionGroupMetadata> computePartitionGroupMetadata(String clientId, StreamConfig streamConfig,
+      List<PartitionGroupConsumptionStatus> partitionGroupConsumptionStatuses, int timeoutMillis)
+      throws IOException, TimeoutException {
+
+    List<PartitionGroupMetadata> newPartitionGroupMetadatas = new ArrayList<>();
+
+    Map<String, Shard> shardIdToShardMap = _kinesisConnectionHandler.getShards().stream()
+        .collect(Collectors.toMap(Shard::shardId, s -> s, (s1, s2) -> s1));
+    Set<String> shardsInCurrent = new HashSet<>();
+    Set<String> shardsEnded = new HashSet<>();
+
+    // TODO: Once we start supporting multiple shards in a PartitionGroup,
+    //  we need to iterate over all shards to check if any of them have reached end
+
+    // Process existing shards. Add them to new list if still consuming from them
+    for (PartitionGroupConsumptionStatus currentPartitionGroupConsumptionStatus : partitionGroupConsumptionStatuses) {
+      KinesisPartitionGroupOffset kinesisStartCheckpoint =
+          (KinesisPartitionGroupOffset) currentPartitionGroupConsumptionStatus.getStartOffset();
+      String shardId = kinesisStartCheckpoint.getShardToStartSequenceMap().keySet().iterator().next();
+      Shard shard = shardIdToShardMap.get(shardId);
+      shardsInCurrent.add(shardId);
+
+      StreamPartitionMsgOffset newStartOffset;
+      StreamPartitionMsgOffset currentEndOffset = currentPartitionGroupConsumptionStatus.getEndOffset();
+      if (currentEndOffset != null) { // Segment DONE (committing/committed)
+        String endingSequenceNumber = shard.sequenceNumberRange().endingSequenceNumber();
+        if (endingSequenceNumber != null) { // Shard has ended, check if we're also done consuming it
+          if (consumedEndOfShard(currentEndOffset, currentPartitionGroupConsumptionStatus)) {
+            shardsEnded.add(shardId);
+            continue; // Shard ended and we're done consuming it. Skip
+          }
+        }
+        newStartOffset = currentEndOffset;
+      } else { // Segment IN_PROGRESS
+        newStartOffset = currentPartitionGroupConsumptionStatus.getStartOffset();
+      }
+      newPartitionGroupMetadatas.add(
+          new PartitionGroupMetadata(currentPartitionGroupConsumptionStatus.getPartitionGroupId(), newStartOffset));
+    }
+
+    // Add new shards. Parent should be null (new table case, very first shards)
+    // OR it should be flagged as reached EOL and completely consumed.
+    for (Map.Entry<String, Shard> entry : shardIdToShardMap.entrySet()) {
+      String newShardId = entry.getKey();
+      if (shardsInCurrent.contains(newShardId)) {
+        continue;
+      }
+      StreamPartitionMsgOffset newStartOffset;
+      Shard newShard = entry.getValue();
+      String parentShardId = newShard.parentShardId();
+
+      if (parentShardId == null || shardsEnded.contains(parentShardId)) {
+        Map<String, String> shardToSequenceNumberMap = new HashMap<>();
+        shardToSequenceNumberMap.put(newShardId, newShard.sequenceNumberRange().startingSequenceNumber());
+        newStartOffset = new KinesisPartitionGroupOffset(shardToSequenceNumberMap);
+        int partitionGroupId = getPartitionGroupIdFromShardId(newShardId);
+        newPartitionGroupMetadatas.add(new PartitionGroupMetadata(partitionGroupId, newStartOffset));
+      }
+    }
+    return newPartitionGroupMetadatas;
+  }
+
+  /**
+   * Converts a shardId string to a partitionGroupId integer by parsing the digits of the shardId
+   * e.g. "shardId-000000000001" becomes 1

Review comment:
       Is shardId guaranteed to be like the above format?  It looks that we probably can assume the convention but the official documentation does not guarantee this specific format. 
   
   https://docs.aws.amazon.com/kinesis/latest/APIReference/API_Shard.html
   
   The safer approach can be keeping the mapping from shardId to the partition group Id not to depend on the conversion of shardId returned by Kinesis.
   

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisStreamMetadataProvider.java
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.spi.stream.MessageBatch;
+import org.apache.pinot.spi.stream.OffsetCriteria;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.PartitionGroupConsumptionStatus;
+import org.apache.pinot.spi.stream.PartitionGroupMetadata;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConsumerFactory;
+import org.apache.pinot.spi.stream.StreamConsumerFactoryProvider;
+import org.apache.pinot.spi.stream.StreamMetadataProvider;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * A {@link StreamMetadataProvider} implementation for the Kinesis stream
+ */
+public class KinesisStreamMetadataProvider implements StreamMetadataProvider {
+  private final KinesisConnectionHandler _kinesisConnectionHandler;
+  private final StreamConsumerFactory _kinesisStreamConsumerFactory;
+  private final String _clientId;
+  private final int _fetchTimeoutMs;
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = new KinesisConnectionHandler(kinesisConfig.getStream(), kinesisConfig.getAwsRegion());
+    _kinesisStreamConsumerFactory = StreamConsumerFactoryProvider.create(streamConfig);
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig,
+      KinesisConnectionHandler kinesisConnectionHandler, StreamConsumerFactory streamConsumerFactory) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = kinesisConnectionHandler;
+    _kinesisStreamConsumerFactory = streamConsumerFactory;
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  @Override
+  public int fetchPartitionCount(long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public long fetchPartitionOffset(@Nonnull OffsetCriteria offsetCriteria, long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  /**
+   * This call returns all active shards, taking into account the consumption status for those shards.
+   * {@link PartitionGroupMetadata} is returned for a shard if:
+   * 1. It is a branch new shard AND its parent has been consumed completely
+   * 2. It is still being actively consumed from i.e. the consuming partition has not reached the end of the shard
+   */
+  @Override
+  public List<PartitionGroupMetadata> computePartitionGroupMetadata(String clientId, StreamConfig streamConfig,
+      List<PartitionGroupConsumptionStatus> partitionGroupConsumptionStatuses, int timeoutMillis)
+      throws IOException, TimeoutException {
+
+    List<PartitionGroupMetadata> newPartitionGroupMetadatas = new ArrayList<>();
+
+    Map<String, Shard> shardIdToShardMap = _kinesisConnectionHandler.getShards().stream()
+        .collect(Collectors.toMap(Shard::shardId, s -> s, (s1, s2) -> s1));
+    Set<String> shardsInCurrent = new HashSet<>();
+    Set<String> shardsEnded = new HashSet<>();
+
+    // TODO: Once we start supporting multiple shards in a PartitionGroup,
+    //  we need to iterate over all shards to check if any of them have reached end
+
+    // Process existing shards. Add them to new list if still consuming from them
+    for (PartitionGroupConsumptionStatus currentPartitionGroupConsumptionStatus : partitionGroupConsumptionStatuses) {
+      KinesisPartitionGroupOffset kinesisStartCheckpoint =
+          (KinesisPartitionGroupOffset) currentPartitionGroupConsumptionStatus.getStartOffset();
+      String shardId = kinesisStartCheckpoint.getShardToStartSequenceMap().keySet().iterator().next();
+      Shard shard = shardIdToShardMap.get(shardId);
+      shardsInCurrent.add(shardId);
+
+      StreamPartitionMsgOffset newStartOffset;
+      StreamPartitionMsgOffset currentEndOffset = currentPartitionGroupConsumptionStatus.getEndOffset();
+      if (currentEndOffset != null) { // Segment DONE (committing/committed)
+        String endingSequenceNumber = shard.sequenceNumberRange().endingSequenceNumber();
+        if (endingSequenceNumber != null) { // Shard has ended, check if we're also done consuming it
+          if (consumedEndOfShard(currentEndOffset, currentPartitionGroupConsumptionStatus)) {
+            shardsEnded.add(shardId);
+            continue; // Shard ended and we're done consuming it. Skip
+          }
+        }
+        newStartOffset = currentEndOffset;
+      } else { // Segment IN_PROGRESS
+        newStartOffset = currentPartitionGroupConsumptionStatus.getStartOffset();
+      }
+      newPartitionGroupMetadatas.add(
+          new PartitionGroupMetadata(currentPartitionGroupConsumptionStatus.getPartitionGroupId(), newStartOffset));
+    }
+
+    // Add new shards. Parent should be null (new table case, very first shards)
+    // OR it should be flagged as reached EOL and completely consumed.
+    for (Map.Entry<String, Shard> entry : shardIdToShardMap.entrySet()) {
+      String newShardId = entry.getKey();
+      if (shardsInCurrent.contains(newShardId)) {
+        continue;
+      }
+      StreamPartitionMsgOffset newStartOffset;
+      Shard newShard = entry.getValue();
+      String parentShardId = newShard.parentShardId();
+
+      if (parentShardId == null || shardsEnded.contains(parentShardId)) {

Review comment:
       Can there be an edge case for this check? 
   
   (e.g. Segments with the parent shard id got deleted due to retention before we reach this code path)
   

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisStreamMetadataProvider.java
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.spi.stream.MessageBatch;
+import org.apache.pinot.spi.stream.OffsetCriteria;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.PartitionGroupConsumptionStatus;
+import org.apache.pinot.spi.stream.PartitionGroupMetadata;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConsumerFactory;
+import org.apache.pinot.spi.stream.StreamConsumerFactoryProvider;
+import org.apache.pinot.spi.stream.StreamMetadataProvider;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * A {@link StreamMetadataProvider} implementation for the Kinesis stream
+ */
+public class KinesisStreamMetadataProvider implements StreamMetadataProvider {
+  private final KinesisConnectionHandler _kinesisConnectionHandler;
+  private final StreamConsumerFactory _kinesisStreamConsumerFactory;
+  private final String _clientId;
+  private final int _fetchTimeoutMs;
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = new KinesisConnectionHandler(kinesisConfig.getStream(), kinesisConfig.getAwsRegion());
+    _kinesisStreamConsumerFactory = StreamConsumerFactoryProvider.create(streamConfig);
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig,
+      KinesisConnectionHandler kinesisConnectionHandler, StreamConsumerFactory streamConsumerFactory) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = kinesisConnectionHandler;
+    _kinesisStreamConsumerFactory = streamConsumerFactory;
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  @Override
+  public int fetchPartitionCount(long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public long fetchPartitionOffset(@Nonnull OffsetCriteria offsetCriteria, long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  /**
+   * This call returns all active shards, taking into account the consumption status for those shards.
+   * {@link PartitionGroupMetadata} is returned for a shard if:
+   * 1. It is a branch new shard AND its parent has been consumed completely
+   * 2. It is still being actively consumed from i.e. the consuming partition has not reached the end of the shard
+   */
+  @Override
+  public List<PartitionGroupMetadata> computePartitionGroupMetadata(String clientId, StreamConfig streamConfig,
+      List<PartitionGroupConsumptionStatus> partitionGroupConsumptionStatuses, int timeoutMillis)
+      throws IOException, TimeoutException {
+
+    List<PartitionGroupMetadata> newPartitionGroupMetadatas = new ArrayList<>();
+
+    Map<String, Shard> shardIdToShardMap = _kinesisConnectionHandler.getShards().stream()
+        .collect(Collectors.toMap(Shard::shardId, s -> s, (s1, s2) -> s1));
+    Set<String> shardsInCurrent = new HashSet<>();
+    Set<String> shardsEnded = new HashSet<>();
+
+    // TODO: Once we start supporting multiple shards in a PartitionGroup,
+    //  we need to iterate over all shards to check if any of them have reached end
+
+    // Process existing shards. Add them to new list if still consuming from them
+    for (PartitionGroupConsumptionStatus currentPartitionGroupConsumptionStatus : partitionGroupConsumptionStatuses) {
+      KinesisPartitionGroupOffset kinesisStartCheckpoint =
+          (KinesisPartitionGroupOffset) currentPartitionGroupConsumptionStatus.getStartOffset();
+      String shardId = kinesisStartCheckpoint.getShardToStartSequenceMap().keySet().iterator().next();
+      Shard shard = shardIdToShardMap.get(shardId);
+      shardsInCurrent.add(shardId);
+
+      StreamPartitionMsgOffset newStartOffset;
+      StreamPartitionMsgOffset currentEndOffset = currentPartitionGroupConsumptionStatus.getEndOffset();
+      if (currentEndOffset != null) { // Segment DONE (committing/committed)
+        String endingSequenceNumber = shard.sequenceNumberRange().endingSequenceNumber();
+        if (endingSequenceNumber != null) { // Shard has ended, check if we're also done consuming it
+          if (consumedEndOfShard(currentEndOffset, currentPartitionGroupConsumptionStatus)) {
+            shardsEnded.add(shardId);
+            continue; // Shard ended and we're done consuming it. Skip
+          }
+        }
+        newStartOffset = currentEndOffset;
+      } else { // Segment IN_PROGRESS
+        newStartOffset = currentPartitionGroupConsumptionStatus.getStartOffset();
+      }
+      newPartitionGroupMetadatas.add(
+          new PartitionGroupMetadata(currentPartitionGroupConsumptionStatus.getPartitionGroupId(), newStartOffset));
+    }
+
+    // Add new shards. Parent should be null (new table case, very first shards)
+    // OR it should be flagged as reached EOL and completely consumed.
+    for (Map.Entry<String, Shard> entry : shardIdToShardMap.entrySet()) {
+      String newShardId = entry.getKey();
+      if (shardsInCurrent.contains(newShardId)) {
+        continue;
+      }
+      StreamPartitionMsgOffset newStartOffset;
+      Shard newShard = entry.getValue();
+      String parentShardId = newShard.parentShardId();
+
+      if (parentShardId == null || shardsEnded.contains(parentShardId)) {
+        Map<String, String> shardToSequenceNumberMap = new HashMap<>();
+        shardToSequenceNumberMap.put(newShardId, newShard.sequenceNumberRange().startingSequenceNumber());
+        newStartOffset = new KinesisPartitionGroupOffset(shardToSequenceNumberMap);
+        int partitionGroupId = getPartitionGroupIdFromShardId(newShardId);
+        newPartitionGroupMetadatas.add(new PartitionGroupMetadata(partitionGroupId, newStartOffset));
+      }
+    }
+    return newPartitionGroupMetadatas;
+  }
+
+  /**
+   * Converts a shardId string to a partitionGroupId integer by parsing the digits of the shardId
+   * e.g. "shardId-000000000001" becomes 1
+   */
+  private int getPartitionGroupIdFromShardId(String shardId) {
+    String shardIdNum = StringUtils.stripStart(StringUtils.removeStart(shardId, "shardId-"), "0");

Review comment:
       let's use static variable for `shardId-`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r624602777



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/pom.xml
##########
@@ -0,0 +1,177 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>pinot-stream-ingestion</artifactId>
+    <groupId>org.apache.pinot</groupId>
+    <version>0.7.0-SNAPSHOT</version>
+    <relativePath>..</relativePath>
+  </parent>
+
+  <artifactId>pinot-kinesis</artifactId>
+  <name>Pinot Kinesis</name>
+  <url>https://pinot.apache.org/</url>
+  <properties>
+    <pinot.root>${basedir}/../../..</pinot.root>
+    <phase.prop>package</phase.prop>
+    <aws.version>2.14.28</aws.version>

Review comment:
       i think it's because they result in conflicts in the rest of Pinot. I see pinot-s3, and all those file system plugins also follow same appraoch. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r616208342



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/test/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumerIntegrationTest.java
##########
@@ -0,0 +1,69 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamConfigProperties;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+public class KinesisConsumerIntegrationTest {

Review comment:
       removed it




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#issuecomment-849243455


   > If there is a way to start kinesis locally and run some integration tests that will be awesome. Can be a separate PR.
   
   Last when @KKcorps was trying this out, he had reported that there's no way to do so. But created this issue https://github.com/apache/incubator-pinot/issues/6992 to look into this more and add the integration test


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] codecov-commenter edited a comment on pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#issuecomment-849265905


   # [Codecov](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#6661](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (30f4b9f) into [master](https://codecov.io/gh/apache/incubator-pinot/commit/b8a92c41e3d063c436e37965ade577ff8e2b5f86?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b8a92c4) will **decrease** coverage by `0.04%`.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-pinot/pull/6661/graphs/tree.svg?width=650&height=150&src=pr&token=4ibza2ugkz&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #6661      +/-   ##
   ============================================
   - Coverage     73.42%   73.37%   -0.05%     
     Complexity       12       12              
   ============================================
     Files          1441     1441              
     Lines         71431    71450      +19     
     Branches      10351    10354       +3     
   ============================================
   - Hits          52446    52429      -17     
   - Misses        15464    15499      +35     
   - Partials       3521     3522       +1     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | integration | `42.01% <ø> (-0.11%)` | :arrow_down: |
   | unittests | `65.51% <ø> (-0.03%)` | :arrow_down: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...a/manager/realtime/RealtimeSegmentDataManager.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9kYXRhL21hbmFnZXIvcmVhbHRpbWUvUmVhbHRpbWVTZWdtZW50RGF0YU1hbmFnZXIuamF2YQ==) | `50.00% <0.00%> (-50.00%)` | :arrow_down: |
   | [...t/server/api/resources/SegmentMetadataFetcher.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zZXJ2ZXIvYXBpL3Jlc291cmNlcy9TZWdtZW50TWV0YWRhdGFGZXRjaGVyLmphdmE=) | `45.00% <0.00%> (-24.05%)` | :arrow_down: |
   | [...erator/transform/PassThroughTransformOperator.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9vcGVyYXRvci90cmFuc2Zvcm0vUGFzc1Rocm91Z2hUcmFuc2Zvcm1PcGVyYXRvci5qYXZh) | `85.71% <0.00%> (-14.29%)` | :arrow_down: |
   | [...impl/dictionary/DoubleOnHeapMutableDictionary.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9yZWFsdGltZS9pbXBsL2RpY3Rpb25hcnkvRG91YmxlT25IZWFwTXV0YWJsZURpY3Rpb25hcnkuamF2YQ==) | `46.98% <0.00%> (-7.23%)` | :arrow_down: |
   | [...mpl/dictionary/DoubleOffHeapMutableDictionary.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc2VnbWVudC1sb2NhbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3Qvc2VnbWVudC9sb2NhbC9yZWFsdGltZS9pbXBsL2RpY3Rpb25hcnkvRG91YmxlT2ZmSGVhcE11dGFibGVEaWN0aW9uYXJ5LmphdmE=) | `59.57% <0.00%> (-4.26%)` | :arrow_down: |
   | [...operator/filter/RangeIndexBasedFilterOperator.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9vcGVyYXRvci9maWx0ZXIvUmFuZ2VJbmRleEJhc2VkRmlsdGVyT3BlcmF0b3IuamF2YQ==) | `40.42% <0.00%> (-4.26%)` | :arrow_down: |
   | [...in/java/org/apache/pinot/minion/MinionStarter.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtbWluaW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9taW5pb24vTWluaW9uU3RhcnRlci5qYXZh) | `72.80% <0.00%> (-3.51%)` | :arrow_down: |
   | [...not/broker/broker/helix/ClusterChangeMediator.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtYnJva2VyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9icm9rZXIvYnJva2VyL2hlbGl4L0NsdXN0ZXJDaGFuZ2VNZWRpYXRvci5qYXZh) | `74.72% <0.00%> (-2.20%)` | :arrow_down: |
   | [...oker/routing/timeboundary/TimeBoundaryManager.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtYnJva2VyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9icm9rZXIvcm91dGluZy90aW1lYm91bmRhcnkvVGltZUJvdW5kYXJ5TWFuYWdlci5qYXZh) | `90.24% <0.00%> (-1.22%)` | :arrow_down: |
   | [...lix/core/realtime/PinotRealtimeSegmentManager.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29udHJvbGxlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29udHJvbGxlci9oZWxpeC9jb3JlL3JlYWx0aW1lL1Bpbm90UmVhbHRpbWVTZWdtZW50TWFuYWdlci5qYXZh) | `83.07% <0.00%> (-1.03%)` | :arrow_down: |
   | ... and [9 more](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [b8a92c4...30f4b9f](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r624605113



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConnectionHandler.java
##########
@@ -0,0 +1,76 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.util.List;
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ListShardsRequest;
+import software.amazon.awssdk.services.kinesis.model.ListShardsResponse;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * Manages the Kinesis stream connection, given the stream name and aws region
+ */
+public class KinesisConnectionHandler {
+  protected KinesisClient _kinesisClient;
+  private final String _stream;
+  private final String _awsRegion;
+
+  public KinesisConnectionHandler(String stream, String awsRegion) {
+    _stream = stream;
+    _awsRegion = awsRegion;
+    createConnection();
+  }
+
+  public KinesisConnectionHandler(String stream, String awsRegion, KinesisClient kinesisClient) {
+    _stream = stream;
+    _awsRegion = awsRegion;
+    _kinesisClient = kinesisClient;
+  }
+
+  /**
+   * Lists all shards of the stream
+   */
+  public List<Shard> getShards() {
+    ListShardsResponse listShardsResponse =
+        _kinesisClient.listShards(ListShardsRequest.builder().streamName(_stream).build());
+    return listShardsResponse.shards();
+  }
+
+  /**
+   * Creates a Kinesis client for the stream
+   */
+  public void createConnection() {
+    if (_kinesisClient == null) {
+      _kinesisClient =
+          KinesisClient.builder().region(Region.of(_awsRegion)).credentialsProvider(DefaultCredentialsProvider.create())

Review comment:
       good catch, yes we prolly need to do something similar here




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] snleee commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
snleee commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r639475680



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumer.java
##########
@@ -0,0 +1,199 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsResponse;
+import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
+import software.amazon.awssdk.services.kinesis.model.InvalidArgumentException;
+import software.amazon.awssdk.services.kinesis.model.KinesisException;
+import software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException;
+import software.amazon.awssdk.services.kinesis.model.Record;
+import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * A {@link PartitionGroupConsumer} implementation for the Kinesis stream
+ */
+public class KinesisConsumer extends KinesisConnectionHandler implements PartitionGroupConsumer {
+  private static final Logger LOGGER = LoggerFactory.getLogger(KinesisConsumer.class);
+  private final String _streamTopicName;
+  private final int _numMaxRecordsToFetch;
+  private final ExecutorService _executorService;
+  private final ShardIteratorType _shardIteratorType;
+
+  public KinesisConsumer(KinesisConfig kinesisConfig) {
+    super(kinesisConfig);
+    _streamTopicName = kinesisConfig.getStreamTopicName();
+    _numMaxRecordsToFetch = kinesisConfig.getNumMaxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  @VisibleForTesting
+  public KinesisConsumer(KinesisConfig kinesisConfig, KinesisClient kinesisClient) {
+    super(kinesisConfig, kinesisClient);
+    _kinesisClient = kinesisClient;
+    _streamTopicName = kinesisConfig.getStreamTopicName();
+    _numMaxRecordsToFetch = kinesisConfig.getNumMaxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  /**
+   * Fetch records from the Kinesis stream between the start and end KinesisCheckpoint
+   */
+  @Override
+  public KinesisRecordsBatch fetchMessages(StreamPartitionMsgOffset startCheckpoint,
+      StreamPartitionMsgOffset endCheckpoint, int timeoutMs) {
+    List<Record> recordList = new ArrayList<>();
+    Future<KinesisRecordsBatch> kinesisFetchResultFuture =
+        _executorService.submit(() -> getResult(startCheckpoint, endCheckpoint, recordList));
+
+    try {
+      return kinesisFetchResultFuture.get(timeoutMs, TimeUnit.MILLISECONDS);
+    } catch (Exception e) {
+      return handleException((KinesisPartitionGroupOffset) startCheckpoint, recordList);
+    }
+  }
+
+  private KinesisRecordsBatch getResult(StreamPartitionMsgOffset start, StreamPartitionMsgOffset end,
+      List<Record> recordList) {
+    KinesisPartitionGroupOffset kinesisStartCheckpoint = (KinesisPartitionGroupOffset) start;
+
+    try {
+
+      if (_kinesisClient == null) {
+        createConnection();
+      }
+
+      // TODO: iterate upon all the shardIds in the map
+      //  Okay for now, since we have assumed that every partition group contains a single shard
+      Map<String, String> shardToStartSequenceMap = kinesisStartCheckpoint.getShardToStartSequenceMap();
+      Preconditions.checkState(shardToStartSequenceMap.size() == 1, "Only 1 shard per consumer supported. Found: %s",
+          shardToStartSequenceMap.keySet());
+      Map.Entry<String, String> shardToSequenceNum = shardToStartSequenceMap.entrySet().iterator().next();
+      String shardIterator = getShardIterator(shardToSequenceNum.getKey(), shardToSequenceNum.getValue());
+
+      String kinesisEndSequenceNumber = null;
+
+      if (end != null) {
+        KinesisPartitionGroupOffset kinesisEndCheckpoint = (KinesisPartitionGroupOffset) end;
+        kinesisEndSequenceNumber = kinesisEndCheckpoint.getShardToStartSequenceMap().values().iterator().next();

Review comment:
       Should we add the similar validation as `kinesisStartCheckpoint` (checking the map size = 1)

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisStreamMetadataProvider.java
##########
@@ -0,0 +1,189 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.spi.stream.MessageBatch;
+import org.apache.pinot.spi.stream.OffsetCriteria;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.PartitionGroupConsumptionStatus;
+import org.apache.pinot.spi.stream.PartitionGroupMetadata;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConsumerFactory;
+import org.apache.pinot.spi.stream.StreamConsumerFactoryProvider;
+import org.apache.pinot.spi.stream.StreamMetadataProvider;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import software.amazon.awssdk.services.kinesis.model.Shard;
+
+
+/**
+ * A {@link StreamMetadataProvider} implementation for the Kinesis stream
+ */
+public class KinesisStreamMetadataProvider implements StreamMetadataProvider {
+  private static final String SHARD_ID_PREFIX = "shardId-";
+  private final KinesisConnectionHandler _kinesisConnectionHandler;
+  private final StreamConsumerFactory _kinesisStreamConsumerFactory;
+  private final String _clientId;
+  private final int _fetchTimeoutMs;
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig) {
+    KinesisConfig kinesisConfig = new KinesisConfig(streamConfig);
+    _kinesisConnectionHandler = new KinesisConnectionHandler(kinesisConfig);
+    _kinesisStreamConsumerFactory = StreamConsumerFactoryProvider.create(streamConfig);
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  public KinesisStreamMetadataProvider(String clientId, StreamConfig streamConfig,
+      KinesisConnectionHandler kinesisConnectionHandler, StreamConsumerFactory streamConsumerFactory) {
+    _kinesisConnectionHandler = kinesisConnectionHandler;
+    _kinesisStreamConsumerFactory = streamConsumerFactory;
+    _clientId = clientId;
+    _fetchTimeoutMs = streamConfig.getFetchTimeoutMillis();
+  }
+
+  @Override
+  public int fetchPartitionCount(long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public long fetchPartitionOffset(@Nonnull OffsetCriteria offsetCriteria, long timeoutMillis) {
+    throw new UnsupportedOperationException();
+  }
+
+  /**
+   * This call returns all active shards, taking into account the consumption status for those shards.
+   * {@link PartitionGroupMetadata} is returned for a shard if:
+   * 1. It is a branch new shard AND its parent has been consumed completely
+   * 2. It is still being actively consumed from i.e. the consuming partition has not reached the end of the shard
+   */
+  @Override
+  public List<PartitionGroupMetadata> computePartitionGroupMetadata(String clientId, StreamConfig streamConfig,
+      List<PartitionGroupConsumptionStatus> partitionGroupConsumptionStatuses, int timeoutMillis)
+      throws IOException, TimeoutException {
+
+    List<PartitionGroupMetadata> newPartitionGroupMetadataList = new ArrayList<>();
+
+    Map<String, Shard> shardIdToShardMap = _kinesisConnectionHandler.getShards().stream()
+        .collect(Collectors.toMap(Shard::shardId, s -> s, (s1, s2) -> s1));
+    Set<String> shardsInCurrent = new HashSet<>();
+    Set<String> shardsEnded = new HashSet<>();
+
+    // TODO: Once we start supporting multiple shards in a PartitionGroup,
+    //  we need to iterate over all shards to check if any of them have reached end
+
+    // Process existing shards. Add them to new list if still consuming from them
+    for (PartitionGroupConsumptionStatus currentPartitionGroupConsumptionStatus : partitionGroupConsumptionStatuses) {
+      KinesisPartitionGroupOffset kinesisStartCheckpoint =
+          (KinesisPartitionGroupOffset) currentPartitionGroupConsumptionStatus.getStartOffset();
+      String shardId = kinesisStartCheckpoint.getShardToStartSequenceMap().keySet().iterator().next();
+      shardsInCurrent.add(shardId);
+      Shard shard = shardIdToShardMap.get(shardId);
+      if (shard == null) { // Shard has expired
+        shardsEnded.add(shardId);
+        continue;
+        // FIXME: Here we assume that we were done consuming the shard before it expired.
+        //  Handle edge case where consumer lags behind, resulting in shard to expire before it is all consumed
+      }
+
+      StreamPartitionMsgOffset newStartOffset;
+      StreamPartitionMsgOffset currentEndOffset = currentPartitionGroupConsumptionStatus.getEndOffset();
+      if (currentEndOffset != null) { // Segment DONE (committing/committed)
+        String endingSequenceNumber = shard.sequenceNumberRange().endingSequenceNumber();
+        if (endingSequenceNumber != null) { // Shard has ended, check if we're also done consuming it
+          if (consumedEndOfShard(currentEndOffset, currentPartitionGroupConsumptionStatus)) {
+            shardsEnded.add(shardId);
+            continue; // Shard ended and we're done consuming it. Skip
+          }
+        }
+        newStartOffset = currentEndOffset;
+      } else { // Segment IN_PROGRESS
+        newStartOffset = currentPartitionGroupConsumptionStatus.getStartOffset();
+      }
+      newPartitionGroupMetadataList.add(
+          new PartitionGroupMetadata(currentPartitionGroupConsumptionStatus.getPartitionGroupId(), newStartOffset));
+    }
+
+    // Add brand new shards
+    for (Map.Entry<String, Shard> entry : shardIdToShardMap.entrySet()) {
+      // If shard was already in current list, skip
+      String newShardId = entry.getKey();
+      if (shardsInCurrent.contains(newShardId)) {
+        continue;
+      }
+      StreamPartitionMsgOffset newStartOffset;
+      Shard newShard = entry.getValue();
+      String parentShardId = newShard.parentShardId();
+
+      // Add the new shard in the following 3 cases:
+      // 1. Root shards - Parent shardId will be null. Will find this case when creating new table.
+      // 2. Parent expired - Parent shardId will not be part of shardIdToShard map
+      // 3. Parent reached EOL and completely consumed.
+      if (parentShardId == null || !shardIdToShardMap.containsKey(parentShardId) || shardsEnded.contains(parentShardId)) {
+        Map<String, String> shardToSequenceNumberMap = new HashMap<>();
+        shardToSequenceNumberMap.put(newShardId, newShard.sequenceNumberRange().startingSequenceNumber());
+        newStartOffset = new KinesisPartitionGroupOffset(shardToSequenceNumberMap);
+        int partitionGroupId = getPartitionGroupIdFromShardId(newShardId);
+        newPartitionGroupMetadataList.add(new PartitionGroupMetadata(partitionGroupId, newStartOffset));
+      }
+    }
+    return newPartitionGroupMetadataList;
+  }
+
+  /**
+   * Converts a shardId string to a partitionGroupId integer by parsing the digits of the shardId
+   * e.g. "shardId-000000000001" becomes 1
+   * FIXME: Although practically the shard values follow this format, the Kinesis docs don't guarantee it.
+   *  Re-evaluate if this convention needs to be changed.
+   */
+  private int getPartitionGroupIdFromShardId(String shardId) {
+    String shardIdNum = StringUtils.stripStart(StringUtils.removeStart(shardId, SHARD_ID_PREFIX), "0");
+    return shardIdNum.isEmpty() ? 0 : Integer.parseInt(shardIdNum);
+  }
+
+  private boolean consumedEndOfShard(StreamPartitionMsgOffset startCheckpoint, PartitionGroupConsumptionStatus partitionGroupConsumptionStatus)

Review comment:
       Can you apply the formatting for this class? I believe that this line probably runs over the line charact limit.

##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisConsumer.java
##########
@@ -0,0 +1,199 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
+import software.amazon.awssdk.services.kinesis.model.ExpiredIteratorException;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest;
+import software.amazon.awssdk.services.kinesis.model.GetRecordsResponse;
+import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest;
+import software.amazon.awssdk.services.kinesis.model.InvalidArgumentException;
+import software.amazon.awssdk.services.kinesis.model.KinesisException;
+import software.amazon.awssdk.services.kinesis.model.ProvisionedThroughputExceededException;
+import software.amazon.awssdk.services.kinesis.model.Record;
+import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
+
+
+/**
+ * A {@link PartitionGroupConsumer} implementation for the Kinesis stream
+ */
+public class KinesisConsumer extends KinesisConnectionHandler implements PartitionGroupConsumer {
+  private static final Logger LOGGER = LoggerFactory.getLogger(KinesisConsumer.class);
+  private final String _streamTopicName;
+  private final int _numMaxRecordsToFetch;
+  private final ExecutorService _executorService;
+  private final ShardIteratorType _shardIteratorType;
+
+  public KinesisConsumer(KinesisConfig kinesisConfig) {
+    super(kinesisConfig);
+    _streamTopicName = kinesisConfig.getStreamTopicName();
+    _numMaxRecordsToFetch = kinesisConfig.getNumMaxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  @VisibleForTesting
+  public KinesisConsumer(KinesisConfig kinesisConfig, KinesisClient kinesisClient) {
+    super(kinesisConfig, kinesisClient);
+    _kinesisClient = kinesisClient;
+    _streamTopicName = kinesisConfig.getStreamTopicName();
+    _numMaxRecordsToFetch = kinesisConfig.getNumMaxRecordsToFetch();
+    _shardIteratorType = kinesisConfig.getShardIteratorType();
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  /**
+   * Fetch records from the Kinesis stream between the start and end KinesisCheckpoint
+   */
+  @Override
+  public KinesisRecordsBatch fetchMessages(StreamPartitionMsgOffset startCheckpoint,
+      StreamPartitionMsgOffset endCheckpoint, int timeoutMs) {
+    List<Record> recordList = new ArrayList<>();
+    Future<KinesisRecordsBatch> kinesisFetchResultFuture =
+        _executorService.submit(() -> getResult(startCheckpoint, endCheckpoint, recordList));
+
+    try {
+      return kinesisFetchResultFuture.get(timeoutMs, TimeUnit.MILLISECONDS);
+    } catch (Exception e) {
+      return handleException((KinesisPartitionGroupOffset) startCheckpoint, recordList);
+    }
+  }
+
+  private KinesisRecordsBatch getResult(StreamPartitionMsgOffset start, StreamPartitionMsgOffset end,
+      List<Record> recordList) {
+    KinesisPartitionGroupOffset kinesisStartCheckpoint = (KinesisPartitionGroupOffset) start;
+
+    try {
+

Review comment:
       remove line




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r630555288



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisPartitionGroupOffset.java
##########
@@ -0,0 +1,75 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+/**
+ * A {@link StreamPartitionMsgOffset} implementation for the Kinesis partition group consumption
+ * A partition group consists of 1 or more shards. The KinesisCheckpoint maintains a Map of shards to the sequenceNumber
+ */
+public class KinesisPartitionGroupOffset implements StreamPartitionMsgOffset {
+  private final Map<String, String> _shardToStartSequenceMap;
+
+  public KinesisPartitionGroupOffset(Map<String, String> shardToStartSequenceMap) {
+    _shardToStartSequenceMap = shardToStartSequenceMap;
+  }
+
+  public KinesisPartitionGroupOffset(String offsetStr)
+      throws IOException {
+    _shardToStartSequenceMap = JsonUtils.stringToObject(offsetStr, new TypeReference<Map<String, String>>() {
+    });
+  }
+
+  public Map<String, String> getShardToStartSequenceMap() {
+    return _shardToStartSequenceMap;
+  }
+
+  @Override
+  public String toString() {
+    try {
+      return JsonUtils.objectToString(_shardToStartSequenceMap);
+    } catch (JsonProcessingException e) {
+      throw new IllegalStateException(
+          "Caught exception when converting KinesisCheckpoint to string: " + _shardToStartSequenceMap);
+    }
+  }
+
+  @Override
+  public KinesisPartitionGroupOffset fromString(String kinesisCheckpointStr) {
+    try {
+      return new KinesisPartitionGroupOffset(kinesisCheckpointStr);
+    } catch (IOException e) {
+      throw new IllegalStateException(
+          "Caught exception when converting string to KinesisCheckpoint: " + kinesisCheckpointStr);
+    }
+  }
+
+  @Override
+  public int compareTo(Object o) {
+    return this._shardToStartSequenceMap.values().iterator().next()

Review comment:
       Add preconditions




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] codecov-commenter edited a comment on pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#issuecomment-849265905


   # [Codecov](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#6661](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (8d5037b) into [master](https://codecov.io/gh/apache/incubator-pinot/commit/b8a92c41e3d063c436e37965ade577ff8e2b5f86?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b8a92c4) will **decrease** coverage by `31.36%`.
   > The diff coverage is `0.00%`.
   
   > :exclamation: Current head 8d5037b differs from pull request most recent head 9450858. Consider uploading reports for the commit 9450858 to get more accurate results
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-pinot/pull/6661/graphs/tree.svg?width=650&height=150&src=pr&token=4ibza2ugkz&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@              Coverage Diff              @@
   ##             master    #6661       +/-   ##
   =============================================
   - Coverage     73.42%   42.05%   -31.37%     
   + Complexity       12        7        -5     
   =============================================
     Files          1441     1441               
     Lines         71431    71450       +19     
     Branches      10351    10354        +3     
   =============================================
   - Hits          52446    30049    -22397     
   - Misses        15464    38793    +23329     
   + Partials       3521     2608      -913     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | integration | `42.05% <0.00%> (-0.06%)` | :arrow_down: |
   | unittests | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...erator/transform/PassThroughTransformOperator.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvY29yZS9vcGVyYXRvci90cmFuc2Zvcm0vUGFzc1Rocm91Z2hUcmFuc2Zvcm1PcGVyYXRvci5qYXZh) | `85.71% <0.00%> (-14.29%)` | :arrow_down: |
   | [...t/server/api/resources/SegmentMetadataFetcher.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zZXJ2ZXIvYXBpL3Jlc291cmNlcy9TZWdtZW50TWV0YWRhdGFGZXRjaGVyLmphdmE=) | `0.00% <0.00%> (-69.05%)` | :arrow_down: |
   | [...c/main/java/org/apache/pinot/common/tier/Tier.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3QtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9jb21tb24vdGllci9UaWVyLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...ava/org/apache/pinot/spi/data/MetricFieldSpec.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvZGF0YS9NZXRyaWNGaWVsZFNwZWMuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...a/org/apache/pinot/spi/config/table/TableType.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvY29uZmlnL3RhYmxlL1RhYmxlVHlwZS5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...a/org/apache/pinot/spi/data/DateTimeFieldSpec.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvZGF0YS9EYXRlVGltZUZpZWxkU3BlYy5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [.../org/apache/pinot/spi/data/DimensionFieldSpec.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvZGF0YS9EaW1lbnNpb25GaWVsZFNwZWMuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [.../org/apache/pinot/spi/data/readers/FileFormat.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvZGF0YS9yZWFkZXJzL0ZpbGVGb3JtYXQuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...org/apache/pinot/spi/config/table/QuotaConfig.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvY29uZmlnL3RhYmxlL1F1b3RhQ29uZmlnLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...org/apache/pinot/spi/config/tenant/TenantRole.java](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGlub3Qtc3BpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9zcGkvY29uZmlnL3RlbmFudC9UZW5hbnRSb2xlLmphdmE=) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | ... and [910 more](https://codecov.io/gh/apache/incubator-pinot/pull/6661/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [b8a92c4...9450858](https://codecov.io/gh/apache/incubator-pinot/pull/6661?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] npawar commented on a change in pull request #6661: Add Kinesis Stream Ingestion Plugin

Posted by GitBox <gi...@apache.org>.
npawar commented on a change in pull request #6661:
URL: https://github.com/apache/incubator-pinot/pull/6661#discussion_r616206657



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-kinesis/src/main/java/org/apache/pinot/plugin/stream/kinesis/KinesisPartitionGroupOffset.java
##########
@@ -0,0 +1,75 @@
+/**
+ * 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.pinot.plugin.stream.kinesis;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.apache.pinot.spi.utils.JsonUtils;
+
+
+/**
+ * A {@link StreamPartitionMsgOffset} implementation for the Kinesis partition group consumption
+ * A partition group consists of 1 or more shards. The KinesisCheckpoint maintains a Map of shards to the sequenceNumber
+ */
+public class KinesisPartitionGroupOffset implements StreamPartitionMsgOffset {
+  private final Map<String, String> _shardToStartSequenceMap;
+
+  public KinesisPartitionGroupOffset(Map<String, String> shardToStartSequenceMap) {
+    _shardToStartSequenceMap = shardToStartSequenceMap;
+  }
+
+  public KinesisPartitionGroupOffset(String offsetStr)
+      throws IOException {
+    _shardToStartSequenceMap = JsonUtils.stringToObject(offsetStr, new TypeReference<Map<String, String>>() {
+    });
+  }
+
+  public Map<String, String> getShardToStartSequenceMap() {
+    return _shardToStartSequenceMap;
+  }
+
+  @Override
+  public String toString() {
+    try {
+      return JsonUtils.objectToString(_shardToStartSequenceMap);
+    } catch (JsonProcessingException e) {
+      throw new IllegalStateException(
+          "Caught exception when converting KinesisCheckpoint to string: " + _shardToStartSequenceMap);
+    }
+  }
+
+  @Override
+  public KinesisPartitionGroupOffset fromString(String kinesisCheckpointStr) {
+    try {
+      return new KinesisPartitionGroupOffset(kinesisCheckpointStr);
+    } catch (IOException e) {
+      throw new IllegalStateException(
+          "Caught exception when converting string to KinesisCheckpoint: " + kinesisCheckpointStr);
+    }
+  }
+
+  @Override
+  public int compareTo(Object o) {

Review comment:
       Check PinotLLCRealtimeSegmentManager line 1051. Mainly when we see latest segment as OFFLINE, and then we have to decide whether we create new CONSUMING segment using start offset of previous segment vs earliest offset from stream.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org