Committed by
Gerrit Code Review
Fixes NPE in map event listener
Minor logging improvements in IntentPartitionManager Change-Id: I7b41428c5b56fcb7f98850f50a804468743b984a
Showing
3 changed files
with
11 additions
and
5 deletions
| ... | @@ -72,6 +72,7 @@ public class IntentPartitionManager implements IntentPartitionService { | ... | @@ -72,6 +72,7 @@ public class IntentPartitionManager implements IntentPartitionService { |
| 72 | 72 | ||
| 73 | private static final String ELECTION_PREFIX = "intent-partition-"; | 73 | private static final String ELECTION_PREFIX = "intent-partition-"; |
| 74 | 74 | ||
| 75 | + protected NodeId localNodeId; | ||
| 75 | private ListenerRegistry<IntentPartitionEvent, IntentPartitionEventListener> listenerRegistry; | 76 | private ListenerRegistry<IntentPartitionEvent, IntentPartitionEventListener> listenerRegistry; |
| 76 | private LeadershipEventListener leaderListener = new InternalLeadershipListener(); | 77 | private LeadershipEventListener leaderListener = new InternalLeadershipListener(); |
| 77 | 78 | ||
| ... | @@ -80,6 +81,7 @@ public class IntentPartitionManager implements IntentPartitionService { | ... | @@ -80,6 +81,7 @@ public class IntentPartitionManager implements IntentPartitionService { |
| 80 | 81 | ||
| 81 | @Activate | 82 | @Activate |
| 82 | public void activate() { | 83 | public void activate() { |
| 84 | + localNodeId = clusterService.getLocalNode().id(); | ||
| 83 | leadershipService.addListener(leaderListener); | 85 | leadershipService.addListener(leaderListener); |
| 84 | 86 | ||
| 85 | listenerRegistry = new ListenerRegistry<>(); | 87 | listenerRegistry = new ListenerRegistry<>(); |
| ... | @@ -87,10 +89,12 @@ public class IntentPartitionManager implements IntentPartitionService { | ... | @@ -87,10 +89,12 @@ public class IntentPartitionManager implements IntentPartitionService { |
| 87 | 89 | ||
| 88 | for (int i = 0; i < NUM_PARTITIONS; i++) { | 90 | for (int i = 0; i < NUM_PARTITIONS; i++) { |
| 89 | leadershipService.runForLeadership(getPartitionPath(i)); | 91 | leadershipService.runForLeadership(getPartitionPath(i)); |
| 92 | + log.debug("Registered to run for {}", getPartitionPath(i)); | ||
| 90 | } | 93 | } |
| 91 | 94 | ||
| 92 | executor.scheduleAtFixedRate(() -> scheduleRebalance(0), 0, | 95 | executor.scheduleAtFixedRate(() -> scheduleRebalance(0), 0, |
| 93 | CHECK_PARTITION_BALANCE_PERIOD_SEC, TimeUnit.SECONDS); | 96 | CHECK_PARTITION_BALANCE_PERIOD_SEC, TimeUnit.SECONDS); |
| 97 | + log.info("Started"); | ||
| 94 | } | 98 | } |
| 95 | 99 | ||
| 96 | @Deactivate | 100 | @Deactivate |
| ... | @@ -99,6 +103,7 @@ public class IntentPartitionManager implements IntentPartitionService { | ... | @@ -99,6 +103,7 @@ public class IntentPartitionManager implements IntentPartitionService { |
| 99 | 103 | ||
| 100 | eventDispatcher.removeSink(IntentPartitionEvent.class); | 104 | eventDispatcher.removeSink(IntentPartitionEvent.class); |
| 101 | leadershipService.removeListener(leaderListener); | 105 | leadershipService.removeListener(leaderListener); |
| 106 | + log.info("Stopped"); | ||
| 102 | } | 107 | } |
| 103 | 108 | ||
| 104 | /** | 109 | /** |
| ... | @@ -132,7 +137,7 @@ public class IntentPartitionManager implements IntentPartitionService { | ... | @@ -132,7 +137,7 @@ public class IntentPartitionManager implements IntentPartitionService { |
| 132 | @Override | 137 | @Override |
| 133 | public boolean isMine(Key intentKey) { | 138 | public boolean isMine(Key intentKey) { |
| 134 | return Objects.equals(leadershipService.getLeader(getPartitionPath(getPartitionForKey(intentKey))), | 139 | return Objects.equals(leadershipService.getLeader(getPartitionPath(getPartitionForKey(intentKey))), |
| 135 | - clusterService.getLocalNode().id()); | 140 | + localNodeId); |
| 136 | } | 141 | } |
| 137 | 142 | ||
| 138 | @Override | 143 | @Override |
| ... | @@ -175,7 +180,7 @@ public class IntentPartitionManager implements IntentPartitionService { | ... | @@ -175,7 +180,7 @@ public class IntentPartitionManager implements IntentPartitionService { |
| 175 | 180 | ||
| 176 | List<Leadership> myPartitions = leadershipService.getLeaderBoard().values() | 181 | List<Leadership> myPartitions = leadershipService.getLeaderBoard().values() |
| 177 | .stream() | 182 | .stream() |
| 178 | - .filter(l -> clusterService.getLocalNode().id().equals(l.leaderNodeId())) | 183 | + .filter(l -> localNodeId.equals(l.leaderNodeId())) |
| 179 | .filter(l -> l.topic().startsWith(ELECTION_PREFIX)) | 184 | .filter(l -> l.topic().startsWith(ELECTION_PREFIX)) |
| 180 | .collect(Collectors.toList()); | 185 | .collect(Collectors.toList()); |
| 181 | 186 | ||
| ... | @@ -215,7 +220,7 @@ public class IntentPartitionManager implements IntentPartitionService { | ... | @@ -215,7 +220,7 @@ public class IntentPartitionManager implements IntentPartitionService { |
| 215 | public void event(LeadershipEvent event) { | 220 | public void event(LeadershipEvent event) { |
| 216 | Leadership leadership = event.subject(); | 221 | Leadership leadership = event.subject(); |
| 217 | 222 | ||
| 218 | - if (Objects.equals(leadership.leaderNodeId(), clusterService.getLocalNode().id()) && | 223 | + if (Objects.equals(leadership.leaderNodeId(), localNodeId) && |
| 219 | leadership.topic().startsWith(ELECTION_PREFIX)) { | 224 | leadership.topic().startsWith(ELECTION_PREFIX)) { |
| 220 | 225 | ||
| 221 | eventDispatcher.post(new IntentPartitionEvent(IntentPartitionEvent.Type.LEADER_CHANGED, | 226 | eventDispatcher.post(new IntentPartitionEvent(IntentPartitionEvent.Type.LEADER_CHANGED, | ... | ... |
| ... | @@ -87,6 +87,7 @@ public class IntentPartitionManagerTest { | ... | @@ -87,6 +87,7 @@ public class IntentPartitionManagerTest { |
| 87 | .withScheduledExecutor(new NullScheduledExecutor()); | 87 | .withScheduledExecutor(new NullScheduledExecutor()); |
| 88 | 88 | ||
| 89 | partitionManager.clusterService = new TestClusterService(); | 89 | partitionManager.clusterService = new TestClusterService(); |
| 90 | + partitionManager.localNodeId = MY_NODE_ID; | ||
| 90 | partitionManager.leadershipService = leadershipService; | 91 | partitionManager.leadershipService = leadershipService; |
| 91 | partitionManager.eventDispatcher = new TestEventDispatcher(); | 92 | partitionManager.eventDispatcher = new TestEventDispatcher(); |
| 92 | } | 93 | } | ... | ... |
| ... | @@ -208,8 +208,8 @@ public class TranscodingAsyncConsistentMap<K1, V1, K2, V2> implements AsyncConsi | ... | @@ -208,8 +208,8 @@ public class TranscodingAsyncConsistentMap<K1, V1, K2, V2> implements AsyncConsi |
| 208 | public void event(MapEvent<K2, V2> event) { | 208 | public void event(MapEvent<K2, V2> event) { |
| 209 | listener.event(new MapEvent<K1, V1>(event.name(), | 209 | listener.event(new MapEvent<K1, V1>(event.name(), |
| 210 | keyDecoder.apply(event.key()), | 210 | keyDecoder.apply(event.key()), |
| 211 | - event.newValue().map(valueDecoder), | 211 | + event.newValue() != null ? event.newValue().map(valueDecoder) : null, |
| 212 | - event.oldValue().map(valueDecoder))); | 212 | + event.oldValue() != null ? event.oldValue().map(valueDecoder) : null)); |
| 213 | } | 213 | } |
| 214 | } | 214 | } |
| 215 | } | 215 | } | ... | ... |
-
Please register or login to post a comment