Skip to content

Commit

Permalink
[controller] Handle NPE for incremental push reporting (#677)
Browse files Browse the repository at this point in the history
* throw exception with partition id when hit NPE
  • Loading branch information
adamxchen authored Oct 3, 2023
1 parent 2396100 commit 97df1e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ public Map<Integer, Map<CharSequence, Integer>> getIncrementalPushStatus(
for (PartitionStatus partitionStatus: getPartitionStatuses()) {
Map<CharSequence, Integer> partitionPushStatus = new HashMap<>();
Partition partition = partitionAssignment.getPartition(partitionStatus.getPartitionId());
if (partition == null) {
throw new VeniceException(
"Partition " + partitionStatus.getPartitionId() + " not found in partition assignment");
}
Set<String> workingInstances =
partition.getWorkingInstances().stream().map(Instance::getNodeId).collect(Collectors.toSet());
for (ReplicaStatus replicaStatus: partitionStatus.getReplicaStatuses()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.linkedin.venice.exceptions.VeniceException;
import com.linkedin.venice.meta.OfflinePushStrategy;
import com.linkedin.venice.meta.PartitionAssignment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -163,6 +164,14 @@ public void testCloneOfflinePushStatus() {
Assert.assertNotEquals(clonedPush, offlinePushStatus);
}

@Test(expectedExceptions = VeniceException.class, expectedExceptionsMessageRegExp = "Partition 0 not found in partition assignment")
public void testNPECaughtWhenPollingIncPushStatus() {
OfflinePushStatus offlinePushStatus =
new OfflinePushStatus(kafkaTopic, numberOfPartition, replicationFactor, strategy);
PartitionAssignment partitionAssignment = new PartitionAssignment("test-topic", 10);
offlinePushStatus.getIncrementalPushStatus(partitionAssignment, "ignore");
}

private void testValidTargetStatuses(ExecutionStatus from, ExecutionStatus... statuses) {
for (ExecutionStatus status: statuses) {
OfflinePushStatus offlinePushStatus =
Expand Down

0 comments on commit 97df1e7

Please sign in to comment.