This is an automated email from the ASF dual-hosted git repository.
jiajunwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git
The following commit(s) were added to refs/heads/master by this push:
new 5dd01c0 Fix testInstancesStoppable_zoneBased (#880)
5dd01c0 is described below
commit 5dd01c0cf3445b900f3cdbfeb0fe15f82518e54d
Author: Neal Sun <[email protected]>
AuthorDate: Tue Mar 10 10:58:42 2020 -0700
Fix testInstancesStoppable_zoneBased (#880)
The changes merged in #858 broke testInstancesStoppable_zoneBased. The test
didn't create external views at all, which will encounter exceptions with the
new logic.
The logic added wasn't supposed to break the tests because the logic is to
perform null checks before an if condition that utilizes maps. However, the
tests were passing because in the "and" if condition, it failed at
isPartitionMap.containsKey(instanceName) without accessing the second part of
the "and" condition. Therefore, even though the second part could cause a null
pointer failure, it was never an issue. The fix is to reorder the logic such
that the conditions are performed sep [...]
Co-authored-by: Neal Sun <[email protected]>
---
.../apache/helix/util/InstanceValidationUtil.java | 26 ++++++++++++----------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git
a/helix-core/src/main/java/org/apache/helix/util/InstanceValidationUtil.java
b/helix-core/src/main/java/org/apache/helix/util/InstanceValidationUtil.java
index 055e797..9603518 100644
--- a/helix-core/src/main/java/org/apache/helix/util/InstanceValidationUtil.java
+++ b/helix-core/src/main/java/org/apache/helix/util/InstanceValidationUtil.java
@@ -284,18 +284,20 @@ public class InstanceValidationUtil {
.format("Partition %s of resource %s does not have an ideal
state partition map",
partition, idealStateName));
}
- Map<String, String> evPartitionMap =
externalView.getStateMap(partition);
- if (evPartitionMap == null) {
- throw new HelixException(String
- .format("Partition %s of resource %s does not have an external
view partition map",
- partition, idealStateName));
- }
- if (isPartitionMap.containsKey(instanceName) &&
(!evPartitionMap.containsKey(instanceName)
- ||
!evPartitionMap.get(instanceName).equals(isPartitionMap.get(instanceName)))) {
- // only checks the state from IS matches EV. Return false when
- // 1. This partition not has current state on this instance
- // 2. The state does not match the state on ideal state
- return false;
+ if (isPartitionMap.containsKey(instanceName)) {
+ Map<String, String> evPartitionMap =
externalView.getStateMap(partition);
+ if (evPartitionMap == null) {
+ throw new HelixException(String
+ .format("Partition %s of resource %s does not have an external
view partition map",
+ partition, idealStateName));
+ }
+ if (!evPartitionMap.containsKey(instanceName)
+ ||
!evPartitionMap.get(instanceName).equals(isPartitionMap.get(instanceName))) {
+ // only checks the state from IS matches EV. Return false when
+ // 1. This partition not has current state on this instance
+ // 2. The state does not match the state on ideal state
+ return false;
+ }
}
}
}