Skip to content

Commit cc1333a

Browse files
committed
fix: Resharding force coverage can sometimes set the shard size to 0, will fail producer cycle
1 parent ad1cc30 commit cc1333a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

hollow/src/main/java/com/netflix/hollow/api/producer/AbstractHollowProducer.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,15 @@ long runCycle(
403403
updateHeaderTags(writeEngine, toVersion, schemaChangedFromPriorVersion);
404404

405405
if (allowTypeResharding && forceCoverageOfTypeResharding) {
406-
int randomFactor = (int) Math.pow(2, (int) (Math.random() * 9) - 4); // random power of 2 in the range [-4, 4]
407-
long adjustedShardSize = targetMaxTypeShardSize * randomFactor;
406+
int shift = (int) (Math.random() * 9) - 4; // range [-4, 4]
407+
long adjustedShardSize;
408+
if (shift > 0) {
409+
adjustedShardSize = targetMaxTypeShardSize << shift;
410+
} else if (shift < 0) {
411+
adjustedShardSize = targetMaxTypeShardSize >> -shift;
412+
} else {
413+
adjustedShardSize = targetMaxTypeShardSize;
414+
}
408415
writeEngine.setTargetMaxTypeShardSize(adjustedShardSize);
409416
}
410417

0 commit comments

Comments
 (0)