|
19 | 19 | package accord.coordinate; |
20 | 20 |
|
21 | 21 | import java.util.ArrayList; |
| 22 | +import java.util.HashMap; |
22 | 23 | import java.util.List; |
| 24 | +import java.util.Map; |
23 | 25 | import java.util.function.BiConsumer; |
24 | 26 |
|
25 | 27 | import accord.coordinate.tracking.InvalidationTracker; |
26 | 28 | import accord.coordinate.tracking.InvalidationTracker.InvalidationShardTracker; |
27 | 29 | import accord.coordinate.tracking.RequestStatus; |
| 30 | +import accord.local.Node.Id; |
28 | 31 | import accord.local.Status; |
29 | 32 | import accord.messages.Commit; |
30 | 33 | import accord.primitives.*; |
@@ -59,6 +62,7 @@ public class Invalidate implements Callback<InvalidateReply> |
59 | 62 | private final List<InvalidateReply> replies = new ArrayList<>(); |
60 | 63 | private final InvalidationTracker tracker; |
61 | 64 | private Throwable failure; |
| 65 | + private final Map<Id, InvalidateReply> debug = Invariants.debug() ? new HashMap<>() : null; |
62 | 66 |
|
63 | 67 | private Invalidate(Node node, Ballot ballot, TxnId txnId, Unseekables<?, ?> invalidateWith, boolean transitivelyInvokedByPriorInvalidation, BiConsumer<Outcome, Throwable> callback) |
64 | 68 | { |
@@ -91,17 +95,18 @@ private void start() |
91 | 95 | } |
92 | 96 |
|
93 | 97 | @Override |
94 | | - public synchronized void onSuccess(Node.Id from, InvalidateReply reply) |
| 98 | + public synchronized void onSuccess(Id from, InvalidateReply reply) |
95 | 99 | { |
96 | 100 | if (isDone || isPrepareDone) |
97 | 101 | return; |
98 | 102 |
|
| 103 | + if (debug != null) debug.put(from, reply); |
99 | 104 | replies.add(reply); |
100 | 105 | handle(tracker.recordSuccess(from, reply.isPromised(), reply.acceptedFastPath)); |
101 | 106 | } |
102 | 107 |
|
103 | 108 | @Override |
104 | | - public void onFailure(Node.Id from, Throwable failure) |
| 109 | + public void onFailure(Id from, Throwable failure) |
105 | 110 | { |
106 | 111 | if (isDone || isPrepareDone) |
107 | 112 | return; |
@@ -227,8 +232,9 @@ else if (homeKey != null) |
227 | 232 |
|
228 | 233 | // if we have witnessed the transaction, but are able to invalidate, do we want to proceed? |
229 | 234 | // Probably simplest to do so, but perhaps better for user if we don't. |
230 | | - // TODO (now, rangetxns): This should be a Routable, or we should guarantee it is safe to operate on any key in the range |
231 | | - RoutingKey invalidateWithKey = invalidateWith.slice(Ranges.of(tracker.promisedShard().range)).get(0).someIntersectingRoutingKey(); |
| 235 | + Ranges ranges = Ranges.of(tracker.promisedShard().range); |
| 236 | + // we look up by TxnId at the target node, so it's fine to pick a RoutingKey even if it's a range transaction |
| 237 | + RoutingKey invalidateWithKey = invalidateWith.slice(ranges).get(0).someIntersectingRoutingKey(ranges); |
232 | 238 | proposeInvalidate(node, ballot, txnId, invalidateWithKey, (success, fail) -> { |
233 | 239 | /* |
234 | 240 | We're now inside our *exactly once* callback we registered with proposeInvalidate, and we need to |
@@ -271,7 +277,7 @@ private void commitInvalidate() |
271 | 277 | } |
272 | 278 |
|
273 | 279 | @Override |
274 | | - public void onCallbackFailure(Node.Id from, Throwable failure) |
| 280 | + public void onCallbackFailure(Id from, Throwable failure) |
275 | 281 | { |
276 | 282 | if (isDone) |
277 | 283 | return; |
|
0 commit comments