Handle nulls in DruidCoordinator.getReplicationFactor (#14447)

This commit is contained in:
Adarsh Sanjeev 2023-06-20 15:25:57 +05:30 committed by GitHub
parent 09d6c5a45e
commit f5cc823d0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -302,11 +302,11 @@ public class DruidCoordinator
@Nullable @Nullable
public Integer getReplicationFactor(SegmentId segmentId) public Integer getReplicationFactor(SegmentId segmentId)
{ {
if (segmentReplicationStatus != null) { if (segmentReplicationStatus == null) {
return segmentReplicationStatus.getReplicaCountsInCluster(segmentId).required();
} else {
return null; return null;
} }
SegmentReplicaCount replicaCountsInCluster = segmentReplicationStatus.getReplicaCountsInCluster(segmentId);
return replicaCountsInCluster == null ? null : replicaCountsInCluster.required();
} }
@Nullable @Nullable

View File

@ -249,6 +249,9 @@ public class DruidCoordinatorTest extends CuratorTestBase
EasyMock.replay(serverInventoryView, loadQueueTaskMaster); EasyMock.replay(serverInventoryView, loadQueueTaskMaster);
coordinator.start(); coordinator.start();
Assert.assertNull(coordinator.getReplicationFactor(dataSegment.getId()));
// Wait for this coordinator to become leader // Wait for this coordinator to become leader
leaderAnnouncerLatch.await(); leaderAnnouncerLatch.await();
@ -306,6 +309,7 @@ public class DruidCoordinatorTest extends CuratorTestBase
// the segments are replicated as many times as they can be given state of cluster, therefore should not be // the segments are replicated as many times as they can be given state of cluster, therefore should not be
// under-replicated. // under-replicated.
Assert.assertEquals(0L, underRepliicationCountsPerDataSourceUsingClusterView.getLong(dataSource)); Assert.assertEquals(0L, underRepliicationCountsPerDataSourceUsingClusterView.getLong(dataSource));
Assert.assertEquals(Integer.valueOf(2), coordinator.getReplicationFactor(dataSegment.getId()));
coordinator.stop(); coordinator.stop();
leaderUnannouncerLatch.await(); leaderUnannouncerLatch.await();
@ -398,6 +402,8 @@ public class DruidCoordinatorTest extends CuratorTestBase
Assert.assertEquals(0L, underReplicationCountsPerDataSourcePerTierUsingClusterView.get(hotTierName).getLong(dataSource)); Assert.assertEquals(0L, underReplicationCountsPerDataSourcePerTierUsingClusterView.get(hotTierName).getLong(dataSource));
Assert.assertEquals(0L, underReplicationCountsPerDataSourcePerTierUsingClusterView.get(coldTierName).getLong(dataSource)); Assert.assertEquals(0L, underReplicationCountsPerDataSourcePerTierUsingClusterView.get(coldTierName).getLong(dataSource));
dataSegments.values().forEach(dataSegment -> Assert.assertEquals(Integer.valueOf(1), coordinator.getReplicationFactor(dataSegment.getId())));
coordinator.stop(); coordinator.stop();
leaderUnannouncerLatch.await(); leaderUnannouncerLatch.await();