Committed by
Gerrit Code Review
Simpler Leadership equality check + Use getLeader in place of getLeadership when appropriate
Change-Id: I527353feb18a8a7cd8e4a58cc1fb4f6954a27913
Showing
2 changed files
with
6 additions
and
10 deletions
| ... | @@ -143,10 +143,7 @@ public class Leadership { | ... | @@ -143,10 +143,7 @@ public class Leadership { |
| 143 | if (obj instanceof Leadership) { | 143 | if (obj instanceof Leadership) { |
| 144 | final Leadership other = (Leadership) obj; | 144 | final Leadership other = (Leadership) obj; |
| 145 | return Objects.equals(this.topic, other.topic) && | 145 | return Objects.equals(this.topic, other.topic) && |
| 146 | - Objects.equals(this.leader, other.leader) && | 146 | + Objects.equals(this.epoch, other.epoch); |
| 147 | - Objects.equals(this.candidates, other.candidates) && | ||
| 148 | - Objects.equals(this.epoch, other.epoch) && | ||
| 149 | - Objects.equals(this.electedTime, other.electedTime); | ||
| 150 | } | 147 | } |
| 151 | return false; | 148 | return false; |
| 152 | } | 149 | } | ... | ... |
| ... | @@ -166,8 +166,8 @@ public class ConsistentDeviceMastershipStore | ... | @@ -166,8 +166,8 @@ public class ConsistentDeviceMastershipStore |
| 166 | ? MastershipRole.MASTER : MastershipRole.STANDBY; | 166 | ? MastershipRole.MASTER : MastershipRole.STANDBY; |
| 167 | }); | 167 | }); |
| 168 | } else { | 168 | } else { |
| 169 | - Leadership leadership = leadershipService.getLeadership(leadershipTopic); | 169 | + NodeId leader = leadershipService.getLeader(leadershipTopic); |
| 170 | - if (leadership != null && leadership.leader().equals(localNodeId)) { | 170 | + if (Objects.equal(localNodeId, leader)) { |
| 171 | return CompletableFuture.completedFuture(MastershipRole.MASTER); | 171 | return CompletableFuture.completedFuture(MastershipRole.MASTER); |
| 172 | } else { | 172 | } else { |
| 173 | return CompletableFuture.completedFuture(MastershipRole.STANDBY); | 173 | return CompletableFuture.completedFuture(MastershipRole.STANDBY); |
| ... | @@ -181,8 +181,8 @@ public class ConsistentDeviceMastershipStore | ... | @@ -181,8 +181,8 @@ public class ConsistentDeviceMastershipStore |
| 181 | checkArgument(deviceId != null, DEVICE_ID_NULL); | 181 | checkArgument(deviceId != null, DEVICE_ID_NULL); |
| 182 | 182 | ||
| 183 | String leadershipTopic = createDeviceMastershipTopic(deviceId); | 183 | String leadershipTopic = createDeviceMastershipTopic(deviceId); |
| 184 | - Leadership leadership = leadershipService.getLeadership(leadershipTopic); | 184 | + NodeId leader = leadershipService.getLeader(leadershipTopic); |
| 185 | - if (leadership != null && nodeId.equals(leadership.leader())) { | 185 | + if (Objects.equal(localNodeId, leader)) { |
| 186 | return MastershipRole.MASTER; | 186 | return MastershipRole.MASTER; |
| 187 | } | 187 | } |
| 188 | return leadershipService.getCandidates(leadershipTopic).contains(nodeId) ? | 188 | return leadershipService.getCandidates(leadershipTopic).contains(nodeId) ? |
| ... | @@ -194,8 +194,7 @@ public class ConsistentDeviceMastershipStore | ... | @@ -194,8 +194,7 @@ public class ConsistentDeviceMastershipStore |
| 194 | checkArgument(deviceId != null, DEVICE_ID_NULL); | 194 | checkArgument(deviceId != null, DEVICE_ID_NULL); |
| 195 | 195 | ||
| 196 | String leadershipTopic = createDeviceMastershipTopic(deviceId); | 196 | String leadershipTopic = createDeviceMastershipTopic(deviceId); |
| 197 | - Leadership leadership = leadershipService.getLeadership(leadershipTopic); | 197 | + return leadershipService.getLeader(leadershipTopic); |
| 198 | - return leadership != null ? leadership.leader() : null; | ||
| 199 | } | 198 | } |
| 200 | 199 | ||
| 201 | @Override | 200 | @Override | ... | ... |
-
Please register or login to post a comment