Madan Jampani
Committed by Gerrit Code Review

Fix AtomixConsistentMap::computeIf behavior to throw a ConcurrentModificationExc…

…eption when update races are detected

Change-Id: I6d2ab6b9864649e89156660949160261c511058a
......@@ -35,6 +35,7 @@ import java.util.function.Consumer;
import java.util.function.Predicate;
import org.onlab.util.Match;
import org.onlab.util.Tools;
import org.onosproject.store.primitives.TransactionId;
import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands.Clear;
import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands.ContainsKey;
......@@ -53,6 +54,7 @@ import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapComman
import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands.UpdateAndGet;
import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands.Values;
import org.onosproject.store.service.AsyncConsistentMap;
import org.onosproject.store.service.ConsistentMapException;
import org.onosproject.store.service.MapEvent;
import org.onosproject.store.service.MapEventListener;
import org.onosproject.store.service.MapTransaction;
......@@ -249,6 +251,13 @@ public class AtomixConsistentMap extends AbstractResource<AtomixConsistentMap>
valueMatch,
versionMatch))
.whenComplete((r, e) -> throwIfLocked(r.status()))
.thenCompose(r -> {
if (r.status() == MapEntryUpdateResult.Status.PRECONDITION_FAILED ||
r.status() == MapEntryUpdateResult.Status.WRITE_LOCK) {
return Tools.exceptionalFuture(new ConsistentMapException.ConcurrentModification());
}
return CompletableFuture.completedFuture(r);
})
.thenApply(v -> v.newValue());
});
}
......