Committed by
Yuta HIGUCHI
DistHostStore: HOST_MOVED based on distributed state
- Use information in the distributed Map to determine if the Host has moved instead of instance local cache view. Change-Id: I374e7cf9f4f03451770b137ef2e835e6c578a463
Showing
1 changed file
with
6 additions
and
11 deletions
... | @@ -55,7 +55,6 @@ import java.util.HashSet; | ... | @@ -55,7 +55,6 @@ import java.util.HashSet; |
55 | import java.util.Map; | 55 | import java.util.Map; |
56 | import java.util.Objects; | 56 | import java.util.Objects; |
57 | import java.util.Set; | 57 | import java.util.Set; |
58 | -import java.util.concurrent.ConcurrentHashMap; | ||
59 | import java.util.function.Predicate; | 58 | import java.util.function.Predicate; |
60 | import java.util.stream.Collectors; | 59 | import java.util.stream.Collectors; |
61 | 60 | ||
... | @@ -82,9 +81,6 @@ public class DistributedHostStore | ... | @@ -82,9 +81,6 @@ public class DistributedHostStore |
82 | private ConsistentMap<HostId, DefaultHost> hostsConsistentMap; | 81 | private ConsistentMap<HostId, DefaultHost> hostsConsistentMap; |
83 | private Map<HostId, DefaultHost> hosts; | 82 | private Map<HostId, DefaultHost> hosts; |
84 | 83 | ||
85 | - private final ConcurrentHashMap<HostId, DefaultHost> prevHosts = | ||
86 | - new ConcurrentHashMap<>(); | ||
87 | - | ||
88 | private MapEventListener<HostId, DefaultHost> hostLocationTracker = | 84 | private MapEventListener<HostId, DefaultHost> hostLocationTracker = |
89 | new HostLocationTracker(); | 85 | new HostLocationTracker(); |
90 | 86 | ||
... | @@ -101,7 +97,6 @@ public class DistributedHostStore | ... | @@ -101,7 +97,6 @@ public class DistributedHostStore |
101 | 97 | ||
102 | hosts = hostsConsistentMap.asJavaMap(); | 98 | hosts = hostsConsistentMap.asJavaMap(); |
103 | 99 | ||
104 | - prevHosts.putAll(hosts); | ||
105 | 100 | ||
106 | hostsConsistentMap.addListener(hostLocationTracker); | 101 | hostsConsistentMap.addListener(hostLocationTracker); |
107 | 102 | ||
... | @@ -111,7 +106,6 @@ public class DistributedHostStore | ... | @@ -111,7 +106,6 @@ public class DistributedHostStore |
111 | @Deactivate | 106 | @Deactivate |
112 | public void deactivate() { | 107 | public void deactivate() { |
113 | hostsConsistentMap.removeListener(hostLocationTracker); | 108 | hostsConsistentMap.removeListener(hostLocationTracker); |
114 | - prevHosts.clear(); | ||
115 | 109 | ||
116 | log.info("Stopped"); | 110 | log.info("Stopped"); |
117 | } | 111 | } |
... | @@ -283,13 +277,15 @@ public class DistributedHostStore | ... | @@ -283,13 +277,15 @@ public class DistributedHostStore |
283 | private class HostLocationTracker implements MapEventListener<HostId, DefaultHost> { | 277 | private class HostLocationTracker implements MapEventListener<HostId, DefaultHost> { |
284 | @Override | 278 | @Override |
285 | public void event(MapEvent<HostId, DefaultHost> event) { | 279 | public void event(MapEvent<HostId, DefaultHost> event) { |
286 | - DefaultHost host = checkNotNull(event.value().value()); | 280 | + Host host; |
287 | - Host prevHost = prevHosts.put(host.id(), host); | ||
288 | switch (event.type()) { | 281 | switch (event.type()) { |
289 | case INSERT: | 282 | case INSERT: |
283 | + host = checkNotNull(event.newValue().value()); | ||
290 | notifyDelegate(new HostEvent(HOST_ADDED, host)); | 284 | notifyDelegate(new HostEvent(HOST_ADDED, host)); |
291 | break; | 285 | break; |
292 | case UPDATE: | 286 | case UPDATE: |
287 | + host = checkNotNull(event.newValue().value()); | ||
288 | + Host prevHost = checkNotNull(event.oldValue().value()); | ||
293 | if (!Objects.equals(prevHost.location(), host.location())) { | 289 | if (!Objects.equals(prevHost.location(), host.location())) { |
294 | notifyDelegate(new HostEvent(HOST_MOVED, host, prevHost)); | 290 | notifyDelegate(new HostEvent(HOST_MOVED, host, prevHost)); |
295 | } else if (!Objects.equals(prevHost, host)) { | 291 | } else if (!Objects.equals(prevHost, host)) { |
... | @@ -297,9 +293,8 @@ public class DistributedHostStore | ... | @@ -297,9 +293,8 @@ public class DistributedHostStore |
297 | } | 293 | } |
298 | break; | 294 | break; |
299 | case REMOVE: | 295 | case REMOVE: |
300 | - if (prevHosts.remove(host.id()) != null) { | 296 | + host = checkNotNull(event.oldValue().value()); |
301 | - notifyDelegate(new HostEvent(HOST_REMOVED, host)); | 297 | + notifyDelegate(new HostEvent(HOST_REMOVED, host)); |
302 | - } | ||
303 | break; | 298 | break; |
304 | default: | 299 | default: |
305 | log.warn("Unknown map event type: {}", event.type()); | 300 | log.warn("Unknown map event type: {}", event.type()); | ... | ... |
-
Please register or login to post a comment