jon-wei commented on a change in pull request #8644: Fix Kinesis resharding 
issues
URL: https://github.com/apache/incubator-druid/pull/8644#discussion_r332798533
 
 

 ##########
 File path: 
extensions-core/kinesis-indexing-service/src/main/java/org/apache/druid/indexing/kinesis/supervisor/KinesisSupervisor.java
 ##########
 @@ -314,4 +356,94 @@ protected boolean 
useExclusiveStartSequenceNumberForNonFirstSequence()
   {
     return true;
   }
+
+  @Override
+  protected Map<String, OrderedSequenceNumber<String>> 
filterDeadShardsFromStartingOffsets(
+      Map<String, OrderedSequenceNumber<String>> startingOffsets
+  )
+  {
+    Map<String, OrderedSequenceNumber<String>> filteredOffsets = new 
HashMap<>();
+    for (Map.Entry<String, OrderedSequenceNumber<String>> entry : 
startingOffsets.entrySet()) {
+      if 
(!entry.getValue().get().equals(KinesisSequenceNumber.END_OF_SHARD_MARKER)) {
+        filteredOffsets.put(entry.getKey(), entry.getValue());
+      } else {
+        log.info("Excluding shard[%s] because it has reached EOS.", 
entry.getKey());
+      }
+    }
+    return filteredOffsets;
+  }
+
+  @Override
+  protected void cleanupDeadShards(Set<String> expiredShards)
+  {
+    log.info("Cleaning up dead shards: " + expiredShards);
+
+    final KinesisDataSourceMetadata dataSourceMetadata =
+        (KinesisDataSourceMetadata) 
getIndexerMetadataStorageCoordinator().getDataSourceMetadata(dataSource);
+
+    SeekableStreamSequenceNumbers<String, String> old = 
dataSourceMetadata.getSeekableStreamSequenceNumbers();
+
+    Map<String, String> oldPartitionSequenceNumberMap = 
old.getPartitionSequenceNumberMap();
+    Map<String, String> newPartitionSequenceNumberMap = new HashMap<>();
+    for (Map.Entry<String, String> entry : 
oldPartitionSequenceNumberMap.entrySet()) {
+      if (!expiredShards.contains(entry.getKey())) {
+        newPartitionSequenceNumberMap.put(entry.getKey(), entry.getValue());
+      }
+    }
+
+    Set<String> oldExclusiveStartPartitions = null;
+    Set<String> newExclusiveStartPartitions = null;
+    if (old instanceof SeekableStreamStartSequenceNumbers) {
+      newExclusiveStartPartitions = new HashSet<>();
+      oldExclusiveStartPartitions = 
((SeekableStreamStartSequenceNumbers<String, String>) 
old).getExclusivePartitions();
+      for (String partitionId : oldExclusiveStartPartitions) {
+        if (!expiredShards.contains(partitionId)) {
+          newExclusiveStartPartitions.add(partitionId);
+        }
+      }
+    }
+
+    SeekableStreamSequenceNumbers<String, String> newSequences;
+    if (old instanceof SeekableStreamStartSequenceNumbers) {
+      newSequences = new SeekableStreamStartSequenceNumbers<String, String>(
+          old.getStream(),
+          null,
+          newPartitionSequenceNumberMap,
+          null,
+          newExclusiveStartPartitions
+      );
+    } else {
+      newSequences = new SeekableStreamEndSequenceNumbers<String, String>(
+          old.getStream(),
+          null,
+          newPartitionSequenceNumberMap,
+          null
+      );
+    }
+
+    try {
+      boolean success = 
getIndexerMetadataStorageCoordinator().resetDataSourceMetadata(
+          dataSource,
+          new KinesisDataSourceMetadata(newSequences)
+      );
+      log.info("cleanupDeadShardsFromMetadata result: " + success);
 
 Review comment:
   Changed this to `log.error("Failed to update datasource metadata[%s] with 
expired partitions removed", cleanedMetadata);`

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to