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

 ##########
 File path: 
extensions-core/kinesis-indexing-service/src/main/java/org/apache/druid/indexing/kinesis/supervisor/KinesisSupervisor.java
 ##########
 @@ -219,7 +234,34 @@ protected int getTaskGroupIdForPartition(String 
partitionId)
       partitionIds.add(partitionId);
     }
 
-    return partitionIds.indexOf(partitionId) % 
spec.getIoConfig().getTaskCount();
+    Integer intForModulo = extractShardNumberFromShardId(partitionId);
+    if (intForModulo == null) {
+      intForModulo = getHashIntFromShardId(partitionId);
+    }
+
+    return Math.abs(intForModulo % spec.getIoConfig().getTaskCount());
+  }
+
+  private Integer extractShardNumberFromShardId(String shardId)
+  {
+    String numOnly = StringUtils.replace(shardId, "shardId-", "");
+    try {
+      Long shardNum = DimensionHandlerUtils.convertObjectToLong(numOnly);
+      if (shardNum != null) {
+        return shardNum.intValue();
+      } else {
+        return null;
+      }
+    }
+    catch (Exception e) {
+      return null;
+    }
+  }
+
+  private int getHashIntFromShardId(String shardId)
+  {
+    HashCode hashCode = HASH_FUNCTION.hashString(shardId, 
StandardCharsets.UTF_8);
 
 Review comment:
   Ah, this code is what I was suggesting above. (Except you might as well use 
a SHA here instead of Murmur, since speed likely isn’t important.)
   
   Why not always use this code path?

----------------------------------------------------------------
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