Committed by
Gerrit Code Review
Always use mastershipService for querying device mastership in FlowRuleStore
Change-Id: I68051153e9555bd0e5b632fa30e7c4d844cf2163
Showing
2 changed files
with
12 additions
and
33 deletions
... | @@ -61,7 +61,6 @@ import org.onosproject.store.AbstractStore; | ... | @@ -61,7 +61,6 @@ import org.onosproject.store.AbstractStore; |
61 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; | 61 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
62 | import org.onosproject.store.cluster.messaging.ClusterMessage; | 62 | import org.onosproject.store.cluster.messaging.ClusterMessage; |
63 | import org.onosproject.store.cluster.messaging.ClusterMessageHandler; | 63 | import org.onosproject.store.cluster.messaging.ClusterMessageHandler; |
64 | -import org.onosproject.store.flow.ReplicaInfo; | ||
65 | import org.onosproject.store.flow.ReplicaInfoEvent; | 64 | import org.onosproject.store.flow.ReplicaInfoEvent; |
66 | import org.onosproject.store.flow.ReplicaInfoEventListener; | 65 | import org.onosproject.store.flow.ReplicaInfoEventListener; |
67 | import org.onosproject.store.flow.ReplicaInfoService; | 66 | import org.onosproject.store.flow.ReplicaInfoService; |
... | @@ -320,9 +319,7 @@ public class NewDistributedFlowRuleStore | ... | @@ -320,9 +319,7 @@ public class NewDistributedFlowRuleStore |
320 | 319 | ||
321 | @Override | 320 | @Override |
322 | public FlowEntry getFlowEntry(FlowRule rule) { | 321 | public FlowEntry getFlowEntry(FlowRule rule) { |
323 | - | 322 | + NodeId master = mastershipService.getMasterFor(rule.deviceId()); |
324 | - ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(rule.deviceId()); | ||
325 | - NodeId master = replicaInfo.master().orNull(); | ||
326 | 323 | ||
327 | if (master == null) { | 324 | if (master == null) { |
328 | log.warn("Failed to getFlowEntry: No master for {}", rule.deviceId()); | 325 | log.warn("Failed to getFlowEntry: No master for {}", rule.deviceId()); |
... | @@ -348,9 +345,7 @@ public class NewDistributedFlowRuleStore | ... | @@ -348,9 +345,7 @@ public class NewDistributedFlowRuleStore |
348 | 345 | ||
349 | @Override | 346 | @Override |
350 | public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { | 347 | public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { |
351 | - | 348 | + NodeId master = mastershipService.getMasterFor(deviceId); |
352 | - ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(deviceId); | ||
353 | - NodeId master = replicaInfo.master().orNull(); | ||
354 | 349 | ||
355 | if (master == null) { | 350 | if (master == null) { |
356 | log.warn("Failed to getFlowEntries: No master for {}", deviceId); | 351 | log.warn("Failed to getFlowEntries: No master for {}", deviceId); |
... | @@ -391,9 +386,7 @@ public class NewDistributedFlowRuleStore | ... | @@ -391,9 +386,7 @@ public class NewDistributedFlowRuleStore |
391 | } | 386 | } |
392 | 387 | ||
393 | DeviceId deviceId = operation.deviceId(); | 388 | DeviceId deviceId = operation.deviceId(); |
394 | - | 389 | + NodeId master = mastershipService.getMasterFor(deviceId); |
395 | - ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(deviceId); | ||
396 | - NodeId master = replicaInfo.master().orNull(); | ||
397 | 390 | ||
398 | if (master == null) { | 391 | if (master == null) { |
399 | log.warn("No master for {} : flows will be marked for removal", deviceId); | 392 | log.warn("No master for {} : flows will be marked for removal", deviceId); |
... | @@ -418,7 +411,7 @@ public class NewDistributedFlowRuleStore | ... | @@ -418,7 +411,7 @@ public class NewDistributedFlowRuleStore |
418 | APPLY_BATCH_FLOWS, | 411 | APPLY_BATCH_FLOWS, |
419 | SERIALIZER::encode, | 412 | SERIALIZER::encode, |
420 | master)) { | 413 | master)) { |
421 | - log.warn("Failed to storeBatch: {} to {}", operation, replicaInfo.master()); | 414 | + log.warn("Failed to storeBatch: {} to {}", operation, master); |
422 | 415 | ||
423 | Set<FlowRule> allFailures = operation.getOperations().stream() | 416 | Set<FlowRule> allFailures = operation.getOperations().stream() |
424 | .map(op -> op.target()) | 417 | .map(op -> op.target()) |
... | @@ -491,8 +484,8 @@ public class NewDistributedFlowRuleStore | ... | @@ -491,8 +484,8 @@ public class NewDistributedFlowRuleStore |
491 | 484 | ||
492 | @Override | 485 | @Override |
493 | public FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule) { | 486 | public FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule) { |
494 | - ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(rule.deviceId()); | 487 | + NodeId master = mastershipService.getMasterFor(rule.deviceId()); |
495 | - if (Objects.equal(local, replicaInfo.master().orNull())) { | 488 | + if (Objects.equal(local, master)) { |
496 | return addOrUpdateFlowRuleInternal(rule); | 489 | return addOrUpdateFlowRuleInternal(rule); |
497 | } | 490 | } |
498 | 491 | ||
... | @@ -524,8 +517,7 @@ public class NewDistributedFlowRuleStore | ... | @@ -524,8 +517,7 @@ public class NewDistributedFlowRuleStore |
524 | @Override | 517 | @Override |
525 | public FlowRuleEvent removeFlowRule(FlowEntry rule) { | 518 | public FlowRuleEvent removeFlowRule(FlowEntry rule) { |
526 | final DeviceId deviceId = rule.deviceId(); | 519 | final DeviceId deviceId = rule.deviceId(); |
527 | - ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(deviceId); | 520 | + NodeId master = mastershipService.getMasterFor(deviceId); |
528 | - NodeId master = replicaInfo.master().orNull(); | ||
529 | 521 | ||
530 | if (Objects.equal(local, master)) { | 522 | if (Objects.equal(local, master)) { |
531 | // bypass and handle it locally | 523 | // bypass and handle it locally |
... | @@ -580,9 +572,8 @@ public class NewDistributedFlowRuleStore | ... | @@ -580,9 +572,8 @@ public class NewDistributedFlowRuleStore |
580 | log.debug("received batch request {}", operation); | 572 | log.debug("received batch request {}", operation); |
581 | 573 | ||
582 | final DeviceId deviceId = operation.deviceId(); | 574 | final DeviceId deviceId = operation.deviceId(); |
583 | - ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(deviceId); | 575 | + NodeId master = mastershipService.getMasterFor(deviceId); |
584 | - if (!local.equals(replicaInfo.master().orNull())) { | 576 | + if (!Objects.equal(local, master)) { |
585 | - | ||
586 | Set<FlowRule> failures = new HashSet<>(operation.size()); | 577 | Set<FlowRule> failures = new HashSet<>(operation.size()); |
587 | for (FlowRuleBatchEntry op : operation.getOperations()) { | 578 | for (FlowRuleBatchEntry op : operation.getOperations()) { |
588 | failures.add(op.target()); | 579 | failures.add(op.target()); |
... | @@ -618,7 +609,8 @@ public class NewDistributedFlowRuleStore | ... | @@ -618,7 +609,8 @@ public class NewDistributedFlowRuleStore |
618 | public void event(ReplicaInfoEvent event) { | 609 | public void event(ReplicaInfoEvent event) { |
619 | if (event.type() == ReplicaInfoEvent.Type.BACKUPS_CHANGED) { | 610 | if (event.type() == ReplicaInfoEvent.Type.BACKUPS_CHANGED) { |
620 | DeviceId deviceId = event.subject(); | 611 | DeviceId deviceId = event.subject(); |
621 | - if (!Objects.equal(local, replicaInfoManager.getReplicaInfoFor(deviceId).master())) { | 612 | + NodeId master = mastershipService.getMasterFor(deviceId); |
613 | + if (!Objects.equal(local, master)) { | ||
622 | // ignore since this event is for a device this node does not manage. | 614 | // ignore since this event is for a device this node does not manage. |
623 | return; | 615 | return; |
624 | } | 616 | } | ... | ... |
... | @@ -15,9 +15,7 @@ | ... | @@ -15,9 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.store.flow.impl; | 16 | package org.onosproject.store.flow.impl; |
17 | 17 | ||
18 | -import com.google.common.base.Objects; | ||
19 | import com.google.common.collect.ImmutableList; | 18 | import com.google.common.collect.ImmutableList; |
20 | -import com.google.common.collect.Maps; | ||
21 | import org.apache.felix.scr.annotations.Activate; | 19 | import org.apache.felix.scr.annotations.Activate; |
22 | import org.apache.felix.scr.annotations.Component; | 20 | import org.apache.felix.scr.annotations.Component; |
23 | import org.apache.felix.scr.annotations.Deactivate; | 21 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -40,8 +38,6 @@ import org.slf4j.Logger; | ... | @@ -40,8 +38,6 @@ import org.slf4j.Logger; |
40 | 38 | ||
41 | import java.util.Collections; | 39 | import java.util.Collections; |
42 | import java.util.List; | 40 | import java.util.List; |
43 | -import java.util.Map; | ||
44 | - | ||
45 | import static com.google.common.base.Preconditions.checkNotNull; | 41 | import static com.google.common.base.Preconditions.checkNotNull; |
46 | import static org.onosproject.store.flow.ReplicaInfoEvent.Type.BACKUPS_CHANGED; | 42 | import static org.onosproject.store.flow.ReplicaInfoEvent.Type.BACKUPS_CHANGED; |
47 | import static org.onosproject.store.flow.ReplicaInfoEvent.Type.MASTER_CHANGED; | 43 | import static org.onosproject.store.flow.ReplicaInfoEvent.Type.MASTER_CHANGED; |
... | @@ -67,8 +63,6 @@ public class ReplicaInfoManager implements ReplicaInfoService { | ... | @@ -67,8 +63,6 @@ public class ReplicaInfoManager implements ReplicaInfoService { |
67 | protected final ListenerRegistry<ReplicaInfoEvent, ReplicaInfoEventListener> | 63 | protected final ListenerRegistry<ReplicaInfoEvent, ReplicaInfoEventListener> |
68 | listenerRegistry = new ListenerRegistry<>(); | 64 | listenerRegistry = new ListenerRegistry<>(); |
69 | 65 | ||
70 | - private final Map<DeviceId, ReplicaInfo> deviceReplicaInfoMap = Maps.newConcurrentMap(); | ||
71 | - | ||
72 | @Activate | 66 | @Activate |
73 | public void activate() { | 67 | public void activate() { |
74 | eventDispatcher.addSink(ReplicaInfoEvent.class, listenerRegistry); | 68 | eventDispatcher.addSink(ReplicaInfoEvent.class, listenerRegistry); |
... | @@ -85,9 +79,7 @@ public class ReplicaInfoManager implements ReplicaInfoService { | ... | @@ -85,9 +79,7 @@ public class ReplicaInfoManager implements ReplicaInfoService { |
85 | 79 | ||
86 | @Override | 80 | @Override |
87 | public ReplicaInfo getReplicaInfoFor(DeviceId deviceId) { | 81 | public ReplicaInfo getReplicaInfoFor(DeviceId deviceId) { |
88 | - return deviceReplicaInfoMap.computeIfAbsent( | 82 | + return buildFromRoleInfo(mastershipService.getNodesFor(deviceId)); |
89 | - deviceId, | ||
90 | - id -> buildFromRoleInfo(mastershipService.getNodesFor(deviceId))); | ||
91 | } | 83 | } |
92 | 84 | ||
93 | @Override | 85 | @Override |
... | @@ -110,12 +102,7 @@ public class ReplicaInfoManager implements ReplicaInfoService { | ... | @@ -110,12 +102,7 @@ public class ReplicaInfoManager implements ReplicaInfoService { |
110 | 102 | ||
111 | @Override | 103 | @Override |
112 | public void event(MastershipEvent event) { | 104 | public void event(MastershipEvent event) { |
113 | - final DeviceId deviceId = event.subject(); | ||
114 | final ReplicaInfo replicaInfo = buildFromRoleInfo(event.roleInfo()); | 105 | final ReplicaInfo replicaInfo = buildFromRoleInfo(event.roleInfo()); |
115 | - ReplicaInfo oldReplicaInfo = deviceReplicaInfoMap.put(deviceId, replicaInfo); | ||
116 | - if (Objects.equal(oldReplicaInfo, replicaInfo)) { | ||
117 | - return; | ||
118 | - } | ||
119 | switch (event.type()) { | 106 | switch (event.type()) { |
120 | case MASTER_CHANGED: | 107 | case MASTER_CHANGED: |
121 | eventDispatcher.post(new ReplicaInfoEvent(MASTER_CHANGED, | 108 | eventDispatcher.post(new ReplicaInfoEvent(MASTER_CHANGED, | ... | ... |
-
Please register or login to post a comment