Fix AtomixConsistentMap::computeIf behavior to throw a ConcurrentModificationExc…
…eption when update races are detected Change-Id: I6d2ab6b9864649e89156660949160261c511058a
Showing
1 changed file
with
9 additions
and
0 deletions
| ... | @@ -35,6 +35,7 @@ import java.util.function.Consumer; | ... | @@ -35,6 +35,7 @@ import java.util.function.Consumer; |
| 35 | import java.util.function.Predicate; | 35 | import java.util.function.Predicate; |
| 36 | 36 | ||
| 37 | import org.onlab.util.Match; | 37 | import org.onlab.util.Match; |
| 38 | +import org.onlab.util.Tools; | ||
| 38 | import org.onosproject.store.primitives.TransactionId; | 39 | import org.onosproject.store.primitives.TransactionId; |
| 39 | import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands.Clear; | 40 | import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands.Clear; |
| 40 | import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands.ContainsKey; | 41 | import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands.ContainsKey; |
| ... | @@ -53,6 +54,7 @@ import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapComman | ... | @@ -53,6 +54,7 @@ import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapComman |
| 53 | import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands.UpdateAndGet; | 54 | import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands.UpdateAndGet; |
| 54 | import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands.Values; | 55 | import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands.Values; |
| 55 | import org.onosproject.store.service.AsyncConsistentMap; | 56 | import org.onosproject.store.service.AsyncConsistentMap; |
| 57 | +import org.onosproject.store.service.ConsistentMapException; | ||
| 56 | import org.onosproject.store.service.MapEvent; | 58 | import org.onosproject.store.service.MapEvent; |
| 57 | import org.onosproject.store.service.MapEventListener; | 59 | import org.onosproject.store.service.MapEventListener; |
| 58 | import org.onosproject.store.service.MapTransaction; | 60 | import org.onosproject.store.service.MapTransaction; |
| ... | @@ -249,6 +251,13 @@ public class AtomixConsistentMap extends AbstractResource<AtomixConsistentMap> | ... | @@ -249,6 +251,13 @@ public class AtomixConsistentMap extends AbstractResource<AtomixConsistentMap> |
| 249 | valueMatch, | 251 | valueMatch, |
| 250 | versionMatch)) | 252 | versionMatch)) |
| 251 | .whenComplete((r, e) -> throwIfLocked(r.status())) | 253 | .whenComplete((r, e) -> throwIfLocked(r.status())) |
| 254 | + .thenCompose(r -> { | ||
| 255 | + if (r.status() == MapEntryUpdateResult.Status.PRECONDITION_FAILED || | ||
| 256 | + r.status() == MapEntryUpdateResult.Status.WRITE_LOCK) { | ||
| 257 | + return Tools.exceptionalFuture(new ConsistentMapException.ConcurrentModification()); | ||
| 258 | + } | ||
| 259 | + return CompletableFuture.completedFuture(r); | ||
| 260 | + }) | ||
| 252 | .thenApply(v -> v.newValue()); | 261 | .thenApply(v -> v.newValue()); |
| 253 | }); | 262 | }); |
| 254 | } | 263 | } | ... | ... |
-
Please register or login to post a comment