mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-27 22:31:18 +01:00
Workaround for ConcurrentModificationException
- Workaround fix for ONOS-1193 - If locking the whole link collection damages the performance, apply the fix suggested on GossipLinkStore comment. Change-Id: Idd4d2e5b8e3a50843fe7abd10a615cfbd9a16478
This commit is contained in:
parent
dc9d7b85be
commit
4d973ebae6
@ -246,13 +246,26 @@ public class GossipLinkStore
|
|||||||
@Override
|
@Override
|
||||||
public Set<Link> getEgressLinks(ConnectPoint src) {
|
public Set<Link> getEgressLinks(ConnectPoint src) {
|
||||||
Set<Link> egress = new HashSet<>();
|
Set<Link> egress = new HashSet<>();
|
||||||
for (LinkKey linkKey : srcLinks.get(src.deviceId())) {
|
//
|
||||||
if (linkKey.src().equals(src)) {
|
// Change `srcLinks` to ConcurrentMap<DeviceId, (Concurrent)Set>
|
||||||
Link link = links.get(linkKey);
|
// to remove this synchronized block, if we hit performance issue.
|
||||||
if (link != null) {
|
// SetMultiMap#get returns wrapped collection to provide modifiable-view.
|
||||||
egress.add(link);
|
// And the wrapped collection is not concurrent access safe.
|
||||||
} else {
|
//
|
||||||
log.debug("Egress link for {} was null, skipped", linkKey);
|
// Our use case here does not require returned collection to be modifiable,
|
||||||
|
// so the wrapped collection forces us to lock the whole multiset,
|
||||||
|
// for benefit we don't need.
|
||||||
|
//
|
||||||
|
// Same applies to `dstLinks`
|
||||||
|
synchronized (srcLinks) {
|
||||||
|
for (LinkKey linkKey : srcLinks.get(src.deviceId())) {
|
||||||
|
if (linkKey.src().equals(src)) {
|
||||||
|
Link link = links.get(linkKey);
|
||||||
|
if (link != null) {
|
||||||
|
egress.add(link);
|
||||||
|
} else {
|
||||||
|
log.debug("Egress link for {} was null, skipped", linkKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,13 +275,15 @@ public class GossipLinkStore
|
|||||||
@Override
|
@Override
|
||||||
public Set<Link> getIngressLinks(ConnectPoint dst) {
|
public Set<Link> getIngressLinks(ConnectPoint dst) {
|
||||||
Set<Link> ingress = new HashSet<>();
|
Set<Link> ingress = new HashSet<>();
|
||||||
for (LinkKey linkKey : dstLinks.get(dst.deviceId())) {
|
synchronized (dstLinks) {
|
||||||
if (linkKey.dst().equals(dst)) {
|
for (LinkKey linkKey : dstLinks.get(dst.deviceId())) {
|
||||||
Link link = links.get(linkKey);
|
if (linkKey.dst().equals(dst)) {
|
||||||
if (link != null) {
|
Link link = links.get(linkKey);
|
||||||
ingress.add(link);
|
if (link != null) {
|
||||||
} else {
|
ingress.add(link);
|
||||||
log.debug("Ingress link for {} was null, skipped", linkKey);
|
} else {
|
||||||
|
log.debug("Ingress link for {} was null, skipped", linkKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -146,9 +146,11 @@ public class SimpleLinkStore
|
|||||||
@Override
|
@Override
|
||||||
public Set<Link> getEgressLinks(ConnectPoint src) {
|
public Set<Link> getEgressLinks(ConnectPoint src) {
|
||||||
Set<Link> egress = new HashSet<>();
|
Set<Link> egress = new HashSet<>();
|
||||||
for (LinkKey linkKey : srcLinks.get(src.deviceId())) {
|
synchronized (srcLinks) {
|
||||||
if (linkKey.src().equals(src)) {
|
for (LinkKey linkKey : srcLinks.get(src.deviceId())) {
|
||||||
egress.add(links.get(linkKey));
|
if (linkKey.src().equals(src)) {
|
||||||
|
egress.add(links.get(linkKey));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return egress;
|
return egress;
|
||||||
@ -157,9 +159,11 @@ public class SimpleLinkStore
|
|||||||
@Override
|
@Override
|
||||||
public Set<Link> getIngressLinks(ConnectPoint dst) {
|
public Set<Link> getIngressLinks(ConnectPoint dst) {
|
||||||
Set<Link> ingress = new HashSet<>();
|
Set<Link> ingress = new HashSet<>();
|
||||||
for (LinkKey linkKey : dstLinks.get(dst.deviceId())) {
|
synchronized (dstLinks) {
|
||||||
if (linkKey.dst().equals(dst)) {
|
for (LinkKey linkKey : dstLinks.get(dst.deviceId())) {
|
||||||
ingress.add(links.get(linkKey));
|
if (linkKey.dst().equals(dst)) {
|
||||||
|
ingress.add(links.get(linkKey));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ingress;
|
return ingress;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user