Committed by
Gerrit Code Review
Moving group store to consistent map
Change-Id: Id3c23c0cd9d7c713bceffc7bd9125aa3de99c45e
Showing
2 changed files
with
34 additions
and
45 deletions
... | @@ -56,11 +56,12 @@ import org.onosproject.store.AbstractStore; | ... | @@ -56,11 +56,12 @@ import org.onosproject.store.AbstractStore; |
56 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; | 56 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
57 | import org.onosproject.store.service.MultiValuedTimestamp; | 57 | import org.onosproject.store.service.MultiValuedTimestamp; |
58 | import org.onosproject.store.serializers.KryoNamespaces; | 58 | import org.onosproject.store.serializers.KryoNamespaces; |
59 | -import org.onosproject.store.service.EventuallyConsistentMap; | 59 | +import org.onosproject.store.service.ConsistentMap; |
60 | -import org.onosproject.store.service.EventuallyConsistentMapBuilder; | 60 | +import org.onosproject.store.service.MapEvent; |
61 | -import org.onosproject.store.service.EventuallyConsistentMapEvent; | 61 | +import org.onosproject.store.service.MapEventListener; |
62 | -import org.onosproject.store.service.EventuallyConsistentMapListener; | 62 | +import org.onosproject.store.service.Serializer; |
63 | import org.onosproject.store.service.StorageService; | 63 | import org.onosproject.store.service.StorageService; |
64 | +import org.onosproject.store.service.Versioned; | ||
64 | import org.slf4j.Logger; | 65 | import org.slf4j.Logger; |
65 | 66 | ||
66 | import java.util.ArrayList; | 67 | import java.util.ArrayList; |
... | @@ -70,6 +71,7 @@ import java.util.HashMap; | ... | @@ -70,6 +71,7 @@ import java.util.HashMap; |
70 | import java.util.HashSet; | 71 | import java.util.HashSet; |
71 | import java.util.Iterator; | 72 | import java.util.Iterator; |
72 | import java.util.List; | 73 | import java.util.List; |
74 | +import java.util.Map; | ||
73 | import java.util.Map.Entry; | 75 | import java.util.Map.Entry; |
74 | import java.util.Objects; | 76 | import java.util.Objects; |
75 | import java.util.Optional; | 77 | import java.util.Optional; |
... | @@ -79,7 +81,6 @@ import java.util.concurrent.ConcurrentMap; | ... | @@ -79,7 +81,6 @@ import java.util.concurrent.ConcurrentMap; |
79 | import java.util.concurrent.ExecutorService; | 81 | import java.util.concurrent.ExecutorService; |
80 | import java.util.concurrent.Executors; | 82 | import java.util.concurrent.Executors; |
81 | import java.util.concurrent.atomic.AtomicInteger; | 83 | import java.util.concurrent.atomic.AtomicInteger; |
82 | -import java.util.concurrent.atomic.AtomicLong; | ||
83 | import java.util.stream.Collectors; | 84 | import java.util.stream.Collectors; |
84 | 85 | ||
85 | import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked; | 86 | import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked; |
... | @@ -113,12 +114,12 @@ public class DistributedGroupStore | ... | @@ -113,12 +114,12 @@ public class DistributedGroupStore |
113 | protected MastershipService mastershipService; | 114 | protected MastershipService mastershipService; |
114 | 115 | ||
115 | // Per device group table with (device id + app cookie) as key | 116 | // Per device group table with (device id + app cookie) as key |
116 | - private EventuallyConsistentMap<GroupStoreKeyMapKey, | 117 | + private ConsistentMap<GroupStoreKeyMapKey, |
117 | StoredGroupEntry> groupStoreEntriesByKey = null; | 118 | StoredGroupEntry> groupStoreEntriesByKey = null; |
118 | // Per device group table with (device id + group id) as key | 119 | // Per device group table with (device id + group id) as key |
119 | private final ConcurrentMap<DeviceId, ConcurrentMap<GroupId, StoredGroupEntry>> | 120 | private final ConcurrentMap<DeviceId, ConcurrentMap<GroupId, StoredGroupEntry>> |
120 | groupEntriesById = new ConcurrentHashMap<>(); | 121 | groupEntriesById = new ConcurrentHashMap<>(); |
121 | - private EventuallyConsistentMap<GroupStoreKeyMapKey, | 122 | + private ConsistentMap<GroupStoreKeyMapKey, |
122 | StoredGroupEntry> auditPendingReqQueue = null; | 123 | StoredGroupEntry> auditPendingReqQueue = null; |
123 | private final ConcurrentMap<DeviceId, ConcurrentMap<GroupId, Group>> | 124 | private final ConcurrentMap<DeviceId, ConcurrentMap<GroupId, Group>> |
124 | extraneousGroupEntriesById = new ConcurrentHashMap<>(); | 125 | extraneousGroupEntriesById = new ConcurrentHashMap<>(); |
... | @@ -131,8 +132,6 @@ public class DistributedGroupStore | ... | @@ -131,8 +132,6 @@ public class DistributedGroupStore |
131 | 132 | ||
132 | private KryoNamespace.Builder kryoBuilder = null; | 133 | private KryoNamespace.Builder kryoBuilder = null; |
133 | 134 | ||
134 | - private final AtomicLong sequenceNumber = new AtomicLong(0); | ||
135 | - | ||
136 | private KryoNamespace clusterMsgSerializer; | 135 | private KryoNamespace clusterMsgSerializer; |
137 | 136 | ||
138 | @Activate | 137 | @Activate |
... | @@ -169,29 +168,21 @@ public class DistributedGroupStore | ... | @@ -169,29 +168,21 @@ public class DistributedGroupStore |
169 | this::process, | 168 | this::process, |
170 | messageHandlingExecutor); | 169 | messageHandlingExecutor); |
171 | 170 | ||
172 | - log.debug("Creating EC map groupstorekeymap"); | 171 | + log.debug("Creating Consistent map onos-group-store-keymap"); |
173 | - EventuallyConsistentMapBuilder<GroupStoreKeyMapKey, StoredGroupEntry> | ||
174 | - keyMapBuilder = storageService.eventuallyConsistentMapBuilder(); | ||
175 | 172 | ||
176 | - groupStoreEntriesByKey = keyMapBuilder | 173 | + groupStoreEntriesByKey = storageService.<GroupStoreKeyMapKey, StoredGroupEntry>consistentMapBuilder() |
177 | - .withName("groupstorekeymap") | 174 | + .withName("onos-group-store-keymap") |
178 | - .withSerializer(kryoBuilder) | 175 | + .withSerializer(Serializer.using(kryoBuilder.build())) |
179 | - .withTimestampProvider((k, v) -> new MultiValuedTimestamp<>(System.currentTimeMillis(), | ||
180 | - sequenceNumber.getAndIncrement())) | ||
181 | .build(); | 176 | .build(); |
182 | groupStoreEntriesByKey.addListener(new GroupStoreKeyMapListener()); | 177 | groupStoreEntriesByKey.addListener(new GroupStoreKeyMapListener()); |
183 | log.debug("Current size of groupstorekeymap:{}", | 178 | log.debug("Current size of groupstorekeymap:{}", |
184 | groupStoreEntriesByKey.size()); | 179 | groupStoreEntriesByKey.size()); |
185 | 180 | ||
186 | - log.debug("Creating EC map pendinggroupkeymap"); | 181 | + log.debug("Creating Consistent map pendinggroupkeymap"); |
187 | - EventuallyConsistentMapBuilder<GroupStoreKeyMapKey, StoredGroupEntry> | ||
188 | - auditMapBuilder = storageService.eventuallyConsistentMapBuilder(); | ||
189 | 182 | ||
190 | - auditPendingReqQueue = auditMapBuilder | 183 | + auditPendingReqQueue = storageService.<GroupStoreKeyMapKey, StoredGroupEntry>consistentMapBuilder() |
191 | - .withName("pendinggroupkeymap") | 184 | + .withName("onos-pending-group-keymap") |
192 | - .withSerializer(kryoBuilder) | 185 | + .withSerializer(Serializer.using(kryoBuilder.build())) |
193 | - .withTimestampProvider((k, v) -> new MultiValuedTimestamp<>(System.currentTimeMillis(), | ||
194 | - sequenceNumber.getAndIncrement())) | ||
195 | .build(); | 186 | .build(); |
196 | log.debug("Current size of pendinggroupkeymap:{}", | 187 | log.debug("Current size of pendinggroupkeymap:{}", |
197 | auditPendingReqQueue.size()); | 188 | auditPendingReqQueue.size()); |
... | @@ -222,9 +213,9 @@ public class DistributedGroupStore | ... | @@ -222,9 +213,9 @@ public class DistributedGroupStore |
222 | * | 213 | * |
223 | * @return Map representing group key table. | 214 | * @return Map representing group key table. |
224 | */ | 215 | */ |
225 | - private EventuallyConsistentMap<GroupStoreKeyMapKey, StoredGroupEntry> | 216 | + private Map<GroupStoreKeyMapKey, StoredGroupEntry> |
226 | getGroupStoreKeyMap() { | 217 | getGroupStoreKeyMap() { |
227 | - return groupStoreEntriesByKey; | 218 | + return groupStoreEntriesByKey.asJavaMap(); |
228 | } | 219 | } |
229 | 220 | ||
230 | /** | 221 | /** |
... | @@ -243,9 +234,9 @@ public class DistributedGroupStore | ... | @@ -243,9 +234,9 @@ public class DistributedGroupStore |
243 | * | 234 | * |
244 | * @return Map representing group key table. | 235 | * @return Map representing group key table. |
245 | */ | 236 | */ |
246 | - private EventuallyConsistentMap<GroupStoreKeyMapKey, StoredGroupEntry> | 237 | + private Map<GroupStoreKeyMapKey, StoredGroupEntry> |
247 | getPendingGroupKeyTable() { | 238 | getPendingGroupKeyTable() { |
248 | - return auditPendingReqQueue; | 239 | + return auditPendingReqQueue.asJavaMap(); |
249 | } | 240 | } |
250 | 241 | ||
251 | /** | 242 | /** |
... | @@ -445,7 +436,7 @@ public class DistributedGroupStore | ... | @@ -445,7 +436,7 @@ public class DistributedGroupStore |
445 | groupDesc.deviceId()); | 436 | groupDesc.deviceId()); |
446 | StoredGroupEntry group = new DefaultGroup(dummyGroupId, groupDesc); | 437 | StoredGroupEntry group = new DefaultGroup(dummyGroupId, groupDesc); |
447 | group.setState(GroupState.WAITING_AUDIT_COMPLETE); | 438 | group.setState(GroupState.WAITING_AUDIT_COMPLETE); |
448 | - EventuallyConsistentMap<GroupStoreKeyMapKey, StoredGroupEntry> pendingKeyTable = | 439 | + Map<GroupStoreKeyMapKey, StoredGroupEntry> pendingKeyTable = |
449 | getPendingGroupKeyTable(); | 440 | getPendingGroupKeyTable(); |
450 | pendingKeyTable.put(new GroupStoreKeyMapKey(groupDesc.deviceId(), | 441 | pendingKeyTable.put(new GroupStoreKeyMapKey(groupDesc.deviceId(), |
451 | groupDesc.appCookie()), | 442 | groupDesc.appCookie()), |
... | @@ -851,7 +842,7 @@ public class DistributedGroupStore | ... | @@ -851,7 +842,7 @@ public class DistributedGroupStore |
851 | Set<Entry<GroupStoreKeyMapKey, StoredGroupEntry>> entryPendingRemove = | 842 | Set<Entry<GroupStoreKeyMapKey, StoredGroupEntry>> entryPendingRemove = |
852 | new HashSet<>(); | 843 | new HashSet<>(); |
853 | 844 | ||
854 | - groupStoreEntriesByKey.entrySet().stream() | 845 | + getGroupStoreKeyMap().entrySet().stream() |
855 | .filter(entry -> entry.getKey().deviceId().equals(deviceId)) | 846 | .filter(entry -> entry.getKey().deviceId().equals(deviceId)) |
856 | .forEach(entryPendingRemove::add); | 847 | .forEach(entryPendingRemove::add); |
857 | 848 | ||
... | @@ -987,14 +978,13 @@ public class DistributedGroupStore | ... | @@ -987,14 +978,13 @@ public class DistributedGroupStore |
987 | * Map handler to receive any events when the group key map is updated. | 978 | * Map handler to receive any events when the group key map is updated. |
988 | */ | 979 | */ |
989 | private class GroupStoreKeyMapListener implements | 980 | private class GroupStoreKeyMapListener implements |
990 | - EventuallyConsistentMapListener<GroupStoreKeyMapKey, StoredGroupEntry> { | 981 | + MapEventListener<GroupStoreKeyMapKey, StoredGroupEntry> { |
991 | 982 | ||
992 | @Override | 983 | @Override |
993 | - public void event(EventuallyConsistentMapEvent<GroupStoreKeyMapKey, | 984 | + public void event(MapEvent<GroupStoreKeyMapKey, StoredGroupEntry> mapEvent) { |
994 | - StoredGroupEntry> mapEvent) { | ||
995 | GroupEvent groupEvent = null; | 985 | GroupEvent groupEvent = null; |
996 | GroupStoreKeyMapKey key = mapEvent.key(); | 986 | GroupStoreKeyMapKey key = mapEvent.key(); |
997 | - StoredGroupEntry group = mapEvent.value(); | 987 | + StoredGroupEntry group = Versioned.valueOrNull(mapEvent.newValue()); |
998 | if ((key == null) && (group == null)) { | 988 | if ((key == null) && (group == null)) { |
999 | log.error("GroupStoreKeyMapListener: Received " | 989 | log.error("GroupStoreKeyMapListener: Received " |
1000 | + "event {} with null entry", mapEvent.type()); | 990 | + "event {} with null entry", mapEvent.type()); |
... | @@ -1014,25 +1004,24 @@ public class DistributedGroupStore | ... | @@ -1014,25 +1004,24 @@ public class DistributedGroupStore |
1014 | mapEvent.type(), | 1004 | mapEvent.type(), |
1015 | group.id(), | 1005 | group.id(), |
1016 | key.deviceId()); | 1006 | key.deviceId()); |
1017 | - if (mapEvent.type() == EventuallyConsistentMapEvent.Type.PUT) { | 1007 | + if (mapEvent.type() == MapEvent.Type.INSERT || mapEvent.type() == MapEvent.Type.UPDATE) { |
1018 | // Update the group ID table | 1008 | // Update the group ID table |
1019 | getGroupIdTable(group.deviceId()).put(group.id(), group); | 1009 | getGroupIdTable(group.deviceId()).put(group.id(), group); |
1020 | - if (mapEvent.value().state() == Group.GroupState.ADDED) { | 1010 | + StoredGroupEntry value = Versioned.valueOrNull(mapEvent.newValue()); |
1021 | - if (mapEvent.value().isGroupStateAddedFirstTime()) { | 1011 | + if (value.state() == Group.GroupState.ADDED) { |
1022 | - groupEvent = new GroupEvent(Type.GROUP_ADDED, | 1012 | + if (value.isGroupStateAddedFirstTime()) { |
1023 | - mapEvent.value()); | 1013 | + groupEvent = new GroupEvent(Type.GROUP_ADDED, value); |
1024 | log.trace("Received first time GROUP_ADDED state update for id {} in device {}", | 1014 | log.trace("Received first time GROUP_ADDED state update for id {} in device {}", |
1025 | group.id(), | 1015 | group.id(), |
1026 | group.deviceId()); | 1016 | group.deviceId()); |
1027 | } else { | 1017 | } else { |
1028 | - groupEvent = new GroupEvent(Type.GROUP_UPDATED, | 1018 | + groupEvent = new GroupEvent(Type.GROUP_UPDATED, value); |
1029 | - mapEvent.value()); | ||
1030 | log.trace("Received following GROUP_ADDED state update for id {} in device {}", | 1019 | log.trace("Received following GROUP_ADDED state update for id {} in device {}", |
1031 | group.id(), | 1020 | group.id(), |
1032 | group.deviceId()); | 1021 | group.deviceId()); |
1033 | } | 1022 | } |
1034 | } | 1023 | } |
1035 | - } else if (mapEvent.type() == EventuallyConsistentMapEvent.Type.REMOVE) { | 1024 | + } else if (mapEvent.type() == MapEvent.Type.REMOVE) { |
1036 | groupEvent = new GroupEvent(Type.GROUP_REMOVED, group); | 1025 | groupEvent = new GroupEvent(Type.GROUP_REMOVED, group); |
1037 | // Remove the entry from the group ID table | 1026 | // Remove the entry from the group ID table |
1038 | getGroupIdTable(group.deviceId()).remove(group.id(), group); | 1027 | getGroupIdTable(group.deviceId()).remove(group.id(), group); | ... | ... |
... | @@ -46,7 +46,7 @@ import org.onosproject.net.group.GroupOperation; | ... | @@ -46,7 +46,7 @@ import org.onosproject.net.group.GroupOperation; |
46 | import org.onosproject.net.group.GroupStore; | 46 | import org.onosproject.net.group.GroupStore; |
47 | import org.onosproject.net.group.GroupStoreDelegate; | 47 | import org.onosproject.net.group.GroupStoreDelegate; |
48 | import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter; | 48 | import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter; |
49 | -import org.onosproject.store.service.EventuallyConsistentMap; | 49 | +import org.onosproject.store.service.ConsistentMap; |
50 | import org.onosproject.store.service.TestStorageService; | 50 | import org.onosproject.store.service.TestStorageService; |
51 | 51 | ||
52 | import com.google.common.collect.ImmutableList; | 52 | import com.google.common.collect.ImmutableList; |
... | @@ -109,7 +109,7 @@ public class DistributedGroupStoreTest { | ... | @@ -109,7 +109,7 @@ public class DistributedGroupStoreTest { |
109 | 109 | ||
110 | DistributedGroupStore groupStoreImpl; | 110 | DistributedGroupStore groupStoreImpl; |
111 | GroupStore groupStore; | 111 | GroupStore groupStore; |
112 | - EventuallyConsistentMap auditPendingReqQueue; | 112 | + ConsistentMap auditPendingReqQueue; |
113 | 113 | ||
114 | static class MasterOfAll extends MastershipServiceAdapter { | 114 | static class MasterOfAll extends MastershipServiceAdapter { |
115 | @Override | 115 | @Override | ... | ... |
-
Please register or login to post a comment