Aaron Kruglikov

Fixes for a hanging issue when creating treemaps and multimaps through the storage parition client.

Change-Id: I3886310bcabbec7499a57f1e91b21e8a36d33e4e
...@@ -15,13 +15,12 @@ ...@@ -15,13 +15,12 @@
15 */ 15 */
16 package org.onosproject.store.primitives.impl; 16 package org.onosproject.store.primitives.impl;
17 17
18 -import java.util.Arrays; 18 +import com.google.common.collect.ImmutableList;
19 - 19 +import com.google.common.collect.Maps;
20 import io.atomix.catalyst.serializer.Serializer; 20 import io.atomix.catalyst.serializer.Serializer;
21 import io.atomix.catalyst.serializer.TypeSerializerFactory; 21 import io.atomix.catalyst.serializer.TypeSerializerFactory;
22 import io.atomix.manager.util.ResourceManagerTypeResolver; 22 import io.atomix.manager.util.ResourceManagerTypeResolver;
23 import io.atomix.variables.internal.LongCommands; 23 import io.atomix.variables.internal.LongCommands;
24 -
25 import org.onlab.util.Match; 24 import org.onlab.util.Match;
26 import org.onosproject.cluster.Leader; 25 import org.onosproject.cluster.Leader;
27 import org.onosproject.cluster.Leadership; 26 import org.onosproject.cluster.Leadership;
...@@ -31,7 +30,10 @@ import org.onosproject.store.primitives.MapUpdate; ...@@ -31,7 +30,10 @@ import org.onosproject.store.primitives.MapUpdate;
31 import org.onosproject.store.primitives.TransactionId; 30 import org.onosproject.store.primitives.TransactionId;
32 import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands; 31 import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands;
33 import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapFactory; 32 import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapFactory;
33 +import org.onosproject.store.primitives.resources.impl.AtomixConsistentMultimapCommands;
34 +import org.onosproject.store.primitives.resources.impl.AtomixConsistentSetMultimapFactory;
34 import org.onosproject.store.primitives.resources.impl.AtomixConsistentTreeMapCommands; 35 import org.onosproject.store.primitives.resources.impl.AtomixConsistentTreeMapCommands;
36 +import org.onosproject.store.primitives.resources.impl.AtomixConsistentTreeMapFactory;
35 import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorCommands; 37 import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorCommands;
36 import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorFactory; 38 import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorFactory;
37 import org.onosproject.store.primitives.resources.impl.AtomixWorkQueueCommands; 39 import org.onosproject.store.primitives.resources.impl.AtomixWorkQueueCommands;
...@@ -47,8 +49,7 @@ import org.onosproject.store.service.Task; ...@@ -47,8 +49,7 @@ import org.onosproject.store.service.Task;
47 import org.onosproject.store.service.Versioned; 49 import org.onosproject.store.service.Versioned;
48 import org.onosproject.store.service.WorkQueueStats; 50 import org.onosproject.store.service.WorkQueueStats;
49 51
50 -import com.google.common.collect.ImmutableList; 52 +import java.util.Arrays;
51 -import com.google.common.collect.Maps;
52 53
53 /** 54 /**
54 * Serializer utility for Atomix Catalyst. 55 * Serializer utility for Atomix Catalyst.
...@@ -63,12 +64,12 @@ public final class CatalystSerializers { ...@@ -63,12 +64,12 @@ public final class CatalystSerializers {
63 TypeSerializerFactory factory = 64 TypeSerializerFactory factory =
64 new DefaultCatalystTypeSerializerFactory( 65 new DefaultCatalystTypeSerializerFactory(
65 org.onosproject.store.service.Serializer.using(Arrays.asList((KryoNamespaces.API)), 66 org.onosproject.store.service.Serializer.using(Arrays.asList((KryoNamespaces.API)),
66 - MapEntryUpdateResult.class, 67 + MapEntryUpdateResult.class,
67 - MapEntryUpdateResult.Status.class, 68 + MapEntryUpdateResult.Status.class,
68 - Transaction.State.class, 69 + Transaction.State.class,
69 - PrepareResult.class, 70 + PrepareResult.class,
70 - CommitResult.class, 71 + CommitResult.class,
71 - RollbackResult.class)); 72 + RollbackResult.class));
72 // ONOS classes 73 // ONOS classes
73 serializer.register(Change.class, factory); 74 serializer.register(Change.class, factory);
74 serializer.register(Leader.class, factory); 75 serializer.register(Leader.class, factory);
...@@ -98,10 +99,13 @@ public final class CatalystSerializers { ...@@ -98,10 +99,13 @@ public final class CatalystSerializers {
98 serializer.resolve(new AtomixWorkQueueCommands.TypeResolver()); 99 serializer.resolve(new AtomixWorkQueueCommands.TypeResolver());
99 serializer.resolve(new ResourceManagerTypeResolver()); 100 serializer.resolve(new ResourceManagerTypeResolver());
100 serializer.resolve(new AtomixConsistentTreeMapCommands.TypeResolver()); 101 serializer.resolve(new AtomixConsistentTreeMapCommands.TypeResolver());
102 + serializer.resolve(new AtomixConsistentMultimapCommands.TypeResolver());
101 103
102 serializer.registerClassLoader(AtomixConsistentMapFactory.class) 104 serializer.registerClassLoader(AtomixConsistentMapFactory.class)
103 - .registerClassLoader(AtomixLeaderElectorFactory.class) 105 + .registerClassLoader(AtomixLeaderElectorFactory.class)
104 - .registerClassLoader(AtomixWorkQueueFactory.class); 106 + .registerClassLoader(AtomixWorkQueueFactory.class)
107 + .registerClassLoader(AtomixConsistentTreeMapFactory.class)
108 + .registerClassLoader(AtomixConsistentSetMultimapFactory.class);
105 109
106 return serializer; 110 return serializer;
107 } 111 }
......
...@@ -38,7 +38,12 @@ import java.util.function.Predicate; ...@@ -38,7 +38,12 @@ import java.util.function.Predicate;
38 import java.util.stream.Collectors; 38 import java.util.stream.Collectors;
39 39
40 /** 40 /**
41 - * Created by admin on 8/3/16. 41 + * An {@code AsyncConsistentTreeMap} that maps its operations to operations on
42 + * a differently typed {@code AsyncConsistentTreeMap} by transcoding operation
43 + * inputs and outputs.
44 + *
45 + * @param <V2> value type of other map
46 + * @param <V1> value type of this map
42 */ 47 */
43 public class TranscodingAsyncConsistentTreeMap<V1, V2> 48 public class TranscodingAsyncConsistentTreeMap<V1, V2>
44 implements AsyncConsistentTreeMap<V1> { 49 implements AsyncConsistentTreeMap<V1> {
...@@ -79,7 +84,8 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2> ...@@ -79,7 +84,8 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2>
79 entry -> 84 entry ->
80 Maps.immutableEntry( 85 Maps.immutableEntry(
81 entry.getKey(), 86 entry.getKey(),
82 - entry.getValue().map(valueDecoder))); 87 + versionedValueTransform
88 + .apply(entry.getValue())));
83 } 89 }
84 90
85 @Override 91 @Override
...@@ -90,7 +96,8 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2> ...@@ -90,7 +96,8 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2>
90 entry -> 96 entry ->
91 Maps.immutableEntry( 97 Maps.immutableEntry(
92 entry.getKey(), 98 entry.getKey(),
93 - entry.getValue().map(valueDecoder))); 99 + versionedValueTransform
100 + .apply(entry.getValue())));
94 } 101 }
95 102
96 @Override 103 @Override
...@@ -99,19 +106,21 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2> ...@@ -99,19 +106,21 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2>
99 return backingMap 106 return backingMap
100 .higherEntry(key) 107 .higherEntry(key)
101 .thenApply(entry -> 108 .thenApply(entry ->
102 - Maps.immutableEntry( 109 + Maps.immutableEntry(
103 - entry.getKey(), 110 + entry.getKey(),
104 - entry.getValue().map(valueDecoder))); 111 + versionedValueTransform
105 -} 112 + .apply(entry.getValue())));
113 + }
106 114
107 @Override 115 @Override
108 public CompletableFuture<Map.Entry<String, Versioned<V1>>> 116 public CompletableFuture<Map.Entry<String, Versioned<V1>>>
109 lowerEntry(String key) { 117 lowerEntry(String key) {
110 return backingMap.lowerEntry(key).thenApply( 118 return backingMap.lowerEntry(key).thenApply(
111 entry -> 119 entry ->
112 - Maps.immutableEntry( 120 + Maps.immutableEntry(
113 - entry.getKey(), 121 + entry.getKey(),
114 - entry.getValue().map(valueDecoder))); 122 + versionedValueTransform
123 + .apply(entry.getValue())));
115 } 124 }
116 125
117 @Override 126 @Override
...@@ -120,8 +129,9 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2> ...@@ -120,8 +129,9 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2>
120 return backingMap.firstEntry() 129 return backingMap.firstEntry()
121 .thenApply(entry -> 130 .thenApply(entry ->
122 Maps.immutableEntry( 131 Maps.immutableEntry(
123 - entry.getKey(), 132 + entry.getKey(),
124 - entry.getValue().map(valueDecoder))); 133 + versionedValueTransform
134 + .apply(entry.getValue())));
125 } 135 }
126 136
127 @Override 137 @Override
...@@ -131,7 +141,8 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2> ...@@ -131,7 +141,8 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2>
131 .thenApply( 141 .thenApply(
132 entry -> Maps.immutableEntry( 142 entry -> Maps.immutableEntry(
133 entry.getKey(), 143 entry.getKey(),
134 - entry.getValue().map(valueDecoder))); 144 + versionedValueTransform
145 + .apply(entry.getValue())));
135 } 146 }
136 147
137 @Override 148 @Override
...@@ -141,7 +152,8 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2> ...@@ -141,7 +152,8 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2>
141 .thenApply( 152 .thenApply(
142 entry -> Maps.immutableEntry( 153 entry -> Maps.immutableEntry(
143 entry.getKey(), 154 entry.getKey(),
144 - entry.getValue().map(valueDecoder))); 155 + versionedValueTransform
156 + .apply(entry.getValue())));
145 } 157 }
146 158
147 @Override 159 @Override
...@@ -150,7 +162,7 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2> ...@@ -150,7 +162,7 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2>
150 return backingMap.pollLastEntry() 162 return backingMap.pollLastEntry()
151 .thenApply(entry -> Maps.immutableEntry( 163 .thenApply(entry -> Maps.immutableEntry(
152 entry.getKey(), 164 entry.getKey(),
153 - entry.getValue().map(valueDecoder))); 165 + versionedValueTransform.apply(entry.getValue())));
154 } 166 }
155 167
156 @Override 168 @Override
...@@ -210,7 +222,7 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2> ...@@ -210,7 +222,7 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2>
210 222
211 @Override 223 @Override
212 public CompletableFuture<Versioned<V1>> get(String key) { 224 public CompletableFuture<Versioned<V1>> get(String key) {
213 - return backingMap.get(key).thenApply(value -> value.map(valueDecoder)); 225 + return backingMap.get(key).thenApply(versionedValueTransform);
214 } 226 }
215 227
216 @Override 228 @Override
...@@ -237,18 +249,18 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2> ...@@ -237,18 +249,18 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2>
237 @Override 249 @Override
238 public CompletableFuture<Versioned<V1>> put(String key, V1 value) { 250 public CompletableFuture<Versioned<V1>> put(String key, V1 value) {
239 return backingMap.put(key, valueEncoder.apply(value)) 251 return backingMap.put(key, valueEncoder.apply(value))
240 - .thenApply(v -> v.map(valueDecoder)); 252 + .thenApply(versionedValueTransform);
241 } 253 }
242 254
243 @Override 255 @Override
244 public CompletableFuture<Versioned<V1>> putAndGet(String key, V1 value) { 256 public CompletableFuture<Versioned<V1>> putAndGet(String key, V1 value) {
245 return backingMap.putAndGet(key, valueEncoder.apply(value)) 257 return backingMap.putAndGet(key, valueEncoder.apply(value))
246 - .thenApply(v -> v.map(valueDecoder)); 258 + .thenApply(versionedValueTransform);
247 } 259 }
248 260
249 @Override 261 @Override
250 public CompletableFuture<Versioned<V1>> remove(String key) { 262 public CompletableFuture<Versioned<V1>> remove(String key) {
251 - return backingMap.remove(key).thenApply(v -> v.map(valueDecoder)); 263 + return backingMap.remove(key).thenApply(versionedValueTransform);
252 } 264 }
253 265
254 @Override 266 @Override
...@@ -264,7 +276,7 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2> ...@@ -264,7 +276,7 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2>
264 @Override 276 @Override
265 public CompletableFuture<Collection<Versioned<V1>>> values() { 277 public CompletableFuture<Collection<Versioned<V1>>> values() {
266 return backingMap.values().thenApply(valueSet -> valueSet.stream() 278 return backingMap.values().thenApply(valueSet -> valueSet.stream()
267 - .map(v -> v.map(valueDecoder)).collect(Collectors.toSet())); 279 + .map(versionedValueTransform).collect(Collectors.toSet()));
268 } 280 }
269 281
270 @Override 282 @Override
...@@ -272,19 +284,21 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2> ...@@ -272,19 +284,21 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2>
272 entrySet() { 284 entrySet() {
273 return backingMap.entrySet() 285 return backingMap.entrySet()
274 .thenApply( 286 .thenApply(
275 - entries -> entries 287 + entries -> entries
276 - .stream() 288 + .stream()
277 - .map(entry -> 289 + .map(entry ->
278 - Maps.immutableEntry(entry.getKey(), 290 + Maps.immutableEntry(
279 - entry.getValue() 291 + entry.getKey(),
280 - .map(valueDecoder))) 292 + versionedValueTransform
281 - .collect(Collectors.toSet())); 293 + .apply(entry.getValue())
282 - } 294 + ))
295 + .collect(Collectors.toSet()));
296 + }
283 297
284 @Override 298 @Override
285 public CompletableFuture<Versioned<V1>> putIfAbsent(String key, V1 value) { 299 public CompletableFuture<Versioned<V1>> putIfAbsent(String key, V1 value) {
286 return backingMap.putIfAbsent(key, valueEncoder.apply(value)) 300 return backingMap.putIfAbsent(key, valueEncoder.apply(value))
287 - .thenApply(v -> v.map(valueDecoder)); 301 + .thenApply(versionedValueTransform);
288 } 302 }
289 303
290 @Override 304 @Override
...@@ -300,7 +314,7 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2> ...@@ -300,7 +314,7 @@ public class TranscodingAsyncConsistentTreeMap<V1, V2>
300 @Override 314 @Override
301 public CompletableFuture<Versioned<V1>> replace(String key, V1 value) { 315 public CompletableFuture<Versioned<V1>> replace(String key, V1 value) {
302 return backingMap.replace(key, valueEncoder.apply(value)) 316 return backingMap.replace(key, valueEncoder.apply(value))
303 - .thenApply(v -> v.map(valueDecoder)); 317 + .thenApply(versionedValueTransform);
304 } 318 }
305 319
306 @Override 320 @Override
......