8e4c757d33767877bb2065a3de45ab201d1bfaf7
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / AbstractProxyTransaction.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.databroker.actors.dds;
9
10 import akka.actor.ActorRef;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.base.Optional;
13 import com.google.common.base.Preconditions;
14 import com.google.common.base.Throwables;
15 import com.google.common.base.Verify;
16 import com.google.common.collect.Iterables;
17 import com.google.common.util.concurrent.CheckedFuture;
18 import com.google.common.util.concurrent.ListenableFuture;
19 import com.google.common.util.concurrent.SettableFuture;
20 import java.util.ArrayDeque;
21 import java.util.Deque;
22 import java.util.Iterator;
23 import java.util.concurrent.CountDownLatch;
24 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
25 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
26 import java.util.function.Consumer;
27 import javax.annotation.Nonnull;
28 import javax.annotation.Nullable;
29 import javax.annotation.concurrent.GuardedBy;
30 import javax.annotation.concurrent.NotThreadSafe;
31 import org.opendaylight.controller.cluster.access.client.ConnectionEntry;
32 import org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest;
33 import org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest;
34 import org.opendaylight.controller.cluster.access.commands.TransactionAbortRequest;
35 import org.opendaylight.controller.cluster.access.commands.TransactionAbortSuccess;
36 import org.opendaylight.controller.cluster.access.commands.TransactionCanCommitSuccess;
37 import org.opendaylight.controller.cluster.access.commands.TransactionCommitSuccess;
38 import org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRequest;
39 import org.opendaylight.controller.cluster.access.commands.TransactionPreCommitRequest;
40 import org.opendaylight.controller.cluster.access.commands.TransactionPreCommitSuccess;
41 import org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest;
42 import org.opendaylight.controller.cluster.access.commands.TransactionRequest;
43 import org.opendaylight.controller.cluster.access.concepts.Request;
44 import org.opendaylight.controller.cluster.access.concepts.RequestFailure;
45 import org.opendaylight.controller.cluster.access.concepts.Response;
46 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
47 import org.opendaylight.mdsal.common.api.ReadFailedException;
48 import org.opendaylight.yangtools.concepts.Identifiable;
49 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
50 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53
54 /**
55  * Class translating transaction operations towards a particular backend shard.
56  *
57  * <p>
58  * This class is not safe to access from multiple application threads, as is usual for transactions. Internal state
59  * transitions coming from interactions with backend are expected to be thread-safe.
60  *
61  * <p>
62  * This class interacts with the queueing mechanism in ClientActorBehavior, hence once we arrive at a decision
63  * to use either a local or remote implementation, we are stuck with it. We can re-evaluate on the next transaction.
64  *
65  * @author Robert Varga
66  */
67 abstract class AbstractProxyTransaction implements Identifiable<TransactionIdentifier> {
68     /**
69      * Marker object used instead of read-type of requests, which are satisfied only once. This has a lower footprint
70      * and allows compressing multiple requests into a single entry.
71      */
72     @NotThreadSafe
73     private static final class IncrementSequence {
74         private final long sequence;
75         private long delta = 0;
76
77         IncrementSequence(final long sequence) {
78             this.sequence = sequence;
79         }
80
81         long getDelta() {
82             return delta;
83         }
84
85         long getSequence() {
86             return sequence;
87         }
88
89         void incrementDelta() {
90             delta++;
91         }
92     }
93
94     // Generic state base class. Direct instances are used for fast paths, sub-class is used for successor transitions
95     private static class State {
96         private final String string;
97
98         State(final String string) {
99             this.string = Preconditions.checkNotNull(string);
100         }
101
102         @Override
103         public final String toString() {
104             return string;
105         }
106     }
107
108     // State class used when a successor has interfered. Contains coordinator latch, the successor and previous state
109     private static final class SuccessorState extends State {
110         private final CountDownLatch latch = new CountDownLatch(1);
111         private AbstractProxyTransaction successor;
112         private State prevState;
113
114         SuccessorState() {
115             super("successor");
116         }
117
118         // Synchronize with succession process and return the successor
119         AbstractProxyTransaction await() {
120             try {
121                 latch.await();
122             } catch (InterruptedException e) {
123                 LOG.warn("Interrupted while waiting for latch of {}", successor);
124                 throw Throwables.propagate(e);
125             }
126             return successor;
127         }
128
129         void finish() {
130             latch.countDown();
131         }
132
133         State getPrevState() {
134             return prevState;
135         }
136
137         void setPrevState(final State prevState) {
138             Verify.verify(this.prevState == null);
139             this.prevState = Preconditions.checkNotNull(prevState);
140         }
141
142         // To be called from safe contexts, where successor is known to be completed
143         AbstractProxyTransaction getSuccessor() {
144             return Verify.verifyNotNull(successor);
145         }
146
147         void setSuccessor(final AbstractProxyTransaction successor) {
148             Verify.verify(this.successor == null);
149             this.successor = Preconditions.checkNotNull(successor);
150         }
151     }
152
153     private static final Logger LOG = LoggerFactory.getLogger(AbstractProxyTransaction.class);
154     private static final AtomicIntegerFieldUpdater<AbstractProxyTransaction> SEALED_UPDATER =
155             AtomicIntegerFieldUpdater.newUpdater(AbstractProxyTransaction.class, "sealed");
156     private static final AtomicReferenceFieldUpdater<AbstractProxyTransaction, State> STATE_UPDATER =
157             AtomicReferenceFieldUpdater.newUpdater(AbstractProxyTransaction.class, State.class, "state");
158     private static final State OPEN = new State("open");
159     private static final State SEALED = new State("sealed");
160     private static final State FLUSHED = new State("flushed");
161
162     // Touched from client actor thread only
163     private final Deque<Object> successfulRequests = new ArrayDeque<>();
164     private final ProxyHistory parent;
165
166     // Accessed from user thread only, which may not access this object concurrently
167     private long sequence;
168
169     /*
170      * Atomic state-keeping is required to synchronize the process of propagating completed transaction state towards
171      * the backend -- which may include a successor.
172      *
173      * Successor, unlike {@link AbstractProxyTransaction#seal()} is triggered from the client actor thread, which means
174      * the successor placement needs to be atomic with regard to the application thread.
175      *
176      * In the common case, the application thread performs performs the seal operations and then "immediately" sends
177      * the corresponding message. The uncommon case is when the seal and send operations race with a connect completion
178      * or timeout, when a successor is injected.
179      *
180      * This leaves the problem of needing to completely transferring state just after all queued messages are replayed
181      * after a successor was injected, so that it can be properly sealed if we are racing. Further complication comes
182      * from lock ordering, where the successor injection works with a locked queue and locks proxy objects -- leading
183      * to a potential AB-BA deadlock in case of a naive implementation.
184      *
185      * For tracking user-visible state we use a single volatile int, which is flipped atomically from 0 to 1 exactly
186      * once in {@link AbstractProxyTransaction#seal()}. That keeps common operations fast, as they need to perform
187      * only a single volatile read to assert state correctness.
188      *
189      * For synchronizing client actor (successor-injecting) and user (commit-driving) thread, we keep a separate state
190      * variable. It uses pre-allocated objects for fast paths (i.e. no successor present) and a per-transition object
191      * for slow paths (when successor is injected/present).
192      */
193     private volatile int sealed = 0;
194     private volatile State state = OPEN;
195
196     AbstractProxyTransaction(final ProxyHistory parent) {
197         this.parent = Preconditions.checkNotNull(parent);
198     }
199
200     final ActorRef localActor() {
201         return parent.localActor();
202     }
203
204     final void incrementSequence(final long delta) {
205         sequence += delta;
206         LOG.debug("Transaction {} incremented sequence to {}", this, sequence);
207     }
208
209     final long nextSequence() {
210         final long ret = sequence++;
211         LOG.debug("Transaction {} allocated sequence {}", this, ret);
212         return ret;
213     }
214
215     final void delete(final YangInstanceIdentifier path) {
216         checkReadWrite();
217         checkNotSealed();
218         doDelete(path);
219     }
220
221     final void merge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
222         checkReadWrite();
223         checkNotSealed();
224         doMerge(path, data);
225     }
226
227     final void write(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
228         checkReadWrite();
229         checkNotSealed();
230         doWrite(path, data);
231     }
232
233     final CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
234         checkNotSealed();
235         return doExists(path);
236     }
237
238     final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
239         checkNotSealed();
240         return doRead(path);
241     }
242
243     final void enqueueRequest(final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback,
244             final long enqueuedTicks) {
245         LOG.debug("Transaction proxy {} enqueing request {} callback {}", this, request, callback);
246         parent.enqueueRequest(request, callback, enqueuedTicks);
247     }
248
249     final void sendRequest(final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback) {
250         LOG.debug("Transaction proxy {} sending request {} callback {}", this, request, callback);
251         parent.sendRequest(request, callback);
252     }
253
254     /**
255      * Seal this transaction before it is either committed or aborted.
256      */
257     final void seal() {
258         // Transition user-visible state first
259         final boolean success = SEALED_UPDATER.compareAndSet(this, 0, 1);
260         Preconditions.checkState(success, "Proxy %s was already sealed", getIdentifier());
261         internalSeal();
262     }
263
264     final void ensureSealed() {
265         if (SEALED_UPDATER.compareAndSet(this, 0, 1)) {
266             internalSeal();
267         }
268     }
269
270     private void internalSeal() {
271         doSeal();
272         parent.onTransactionSealed(this);
273
274         // Now deal with state transfer, which can occur via successor or a follow-up canCommit() or directCommit().
275         if (!STATE_UPDATER.compareAndSet(this, OPEN, SEALED)) {
276             // Slow path: wait for the successor to complete
277             final AbstractProxyTransaction successor = awaitSuccessor();
278
279             // At this point the successor has completed transition and is possibly visible by the user thread, which is
280             // still stuck here. The successor has not seen final part of our state, nor the fact it is sealed.
281             // Propagate state and seal the successor.
282             flushState(successor);
283             successor.ensureSealed();
284         }
285     }
286
287     private void checkNotSealed() {
288         Preconditions.checkState(sealed == 0, "Transaction %s has already been sealed", getIdentifier());
289     }
290
291     private void checkSealed() {
292         Preconditions.checkState(sealed != 0, "Transaction %s has not been sealed yet", getIdentifier());
293     }
294
295     private SuccessorState getSuccessorState() {
296         final State local = state;
297         Verify.verify(local instanceof SuccessorState, "State %s has unexpected class", local);
298         return (SuccessorState) local;
299     }
300
301     private void checkReadWrite() {
302         if (isSnapshotOnly()) {
303             throw new UnsupportedOperationException("Transaction " + getIdentifier() + " is a read-only snapshot");
304         }
305     }
306
307     final void recordSuccessfulRequest(final @Nonnull TransactionRequest<?> req) {
308         successfulRequests.add(Verify.verifyNotNull(req));
309     }
310
311     final void recordFinishedRequest(final Response<?, ?> response) {
312         final Object last = successfulRequests.peekLast();
313         if (last instanceof IncrementSequence) {
314             ((IncrementSequence) last).incrementDelta();
315         } else {
316             successfulRequests.addLast(new IncrementSequence(response.getSequence()));
317         }
318     }
319
320     /**
321      * Abort this transaction. This is invoked only for read-only transactions and will result in an explicit message
322      * being sent to the backend.
323      */
324     final void abort() {
325         checkNotSealed();
326         doAbort();
327         parent.abortTransaction(this);
328     }
329
330     final void abort(final VotingFuture<Void> ret) {
331         checkSealed();
332
333         sendAbort(t -> {
334             if (t instanceof TransactionAbortSuccess) {
335                 ret.voteYes();
336             } else if (t instanceof RequestFailure) {
337                 ret.voteNo(((RequestFailure<?, ?>) t).getCause().unwrap());
338             } else {
339                 ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass()));
340             }
341
342             // This is a terminal request, hence we do not need to record it
343             LOG.debug("Transaction {} abort completed", this);
344             sendPurge();
345         });
346     }
347
348     final void enqueueAbort(final Consumer<Response<?, ?>> callback, final long enqueuedTicks) {
349         enqueueRequest(new TransactionAbortRequest(getIdentifier(), nextSequence(), localActor()), callback,
350             enqueuedTicks);
351     }
352
353     final void sendAbort(final Consumer<Response<?, ?>> callback) {
354         sendRequest(new TransactionAbortRequest(getIdentifier(), nextSequence(), localActor()), callback);
355     }
356
357     /**
358      * Commit this transaction, possibly in a coordinated fashion.
359      *
360      * @param coordinated True if this transaction should be coordinated across multiple participants.
361      * @return Future completion
362      */
363     final ListenableFuture<Boolean> directCommit() {
364         checkReadWrite();
365         checkSealed();
366
367         // Precludes startReconnect() from interfering with the fast path
368         synchronized (this) {
369             if (STATE_UPDATER.compareAndSet(this, SEALED, FLUSHED)) {
370                 final SettableFuture<Boolean> ret = SettableFuture.create();
371                 sendRequest(Verify.verifyNotNull(commitRequest(false)), t -> {
372                     if (t instanceof TransactionCommitSuccess) {
373                         ret.set(Boolean.TRUE);
374                     } else if (t instanceof RequestFailure) {
375                         ret.setException(((RequestFailure<?, ?>) t).getCause().unwrap());
376                     } else {
377                         ret.setException(new IllegalStateException("Unhandled response " + t.getClass()));
378                     }
379
380                     // This is a terminal request, hence we do not need to record it
381                     LOG.debug("Transaction {} directCommit completed", this);
382                     sendPurge();
383                 });
384
385                 return ret;
386             }
387         }
388
389         // We have had some interference with successor injection, wait for it to complete and defer to the successor.
390         return awaitSuccessor().directCommit();
391     }
392
393     final void canCommit(final VotingFuture<?> ret) {
394         checkReadWrite();
395         checkSealed();
396
397         // Precludes startReconnect() from interfering with the fast path
398         synchronized (this) {
399             if (STATE_UPDATER.compareAndSet(this, SEALED, FLUSHED)) {
400                 final TransactionRequest<?> req = Verify.verifyNotNull(commitRequest(true));
401
402                 sendRequest(req, t -> {
403                     if (t instanceof TransactionCanCommitSuccess) {
404                         ret.voteYes();
405                     } else if (t instanceof RequestFailure) {
406                         ret.voteNo(((RequestFailure<?, ?>) t).getCause().unwrap());
407                     } else {
408                         ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass()));
409                     }
410
411                     recordSuccessfulRequest(req);
412                     LOG.debug("Transaction {} canCommit completed", this);
413                 });
414
415                 return;
416             }
417         }
418
419         // We have had some interference with successor injection, wait for it to complete and defer to the successor.
420         awaitSuccessor().canCommit(ret);
421     }
422
423     private AbstractProxyTransaction awaitSuccessor() {
424         return getSuccessorState().await();
425     }
426
427     final void preCommit(final VotingFuture<?> ret) {
428         checkReadWrite();
429         checkSealed();
430
431         final TransactionRequest<?> req = new TransactionPreCommitRequest(getIdentifier(), nextSequence(),
432             localActor());
433         sendRequest(req, t -> {
434             if (t instanceof TransactionPreCommitSuccess) {
435                 ret.voteYes();
436             } else if (t instanceof RequestFailure) {
437                 ret.voteNo(((RequestFailure<?, ?>) t).getCause().unwrap());
438             } else {
439                 ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass()));
440             }
441
442             onPreCommitComplete(req);
443         });
444     }
445
446     private void onPreCommitComplete(final TransactionRequest<?> req) {
447         /*
448          * The backend has agreed that the transaction has entered PRE_COMMIT phase, meaning it will be committed
449          * to storage after the timeout completes.
450          *
451          * All state has been replicated to the backend, hence we do not need to keep it around. Retain only
452          * the precommit request, so we know which request to use for resync.
453          */
454         LOG.debug("Transaction {} preCommit completed, clearing successfulRequests", this);
455         successfulRequests.clear();
456
457         // TODO: this works, but can contain some useless state (like batched operations). Create an empty
458         //       equivalent of this request and store that.
459         recordSuccessfulRequest(req);
460     }
461
462     final void doCommit(final VotingFuture<?> ret) {
463         checkReadWrite();
464         checkSealed();
465
466         sendRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), t -> {
467             if (t instanceof TransactionCommitSuccess) {
468                 ret.voteYes();
469             } else if (t instanceof RequestFailure) {
470                 ret.voteNo(((RequestFailure<?, ?>) t).getCause().unwrap());
471             } else {
472                 ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass()));
473             }
474
475             LOG.debug("Transaction {} doCommit completed", this);
476             sendPurge();
477         });
478     }
479
480     final void sendPurge() {
481         successfulRequests.clear();
482
483         final TransactionRequest<?> req = new TransactionPurgeRequest(getIdentifier(), nextSequence(), localActor());
484         sendRequest(req, t -> {
485             LOG.debug("Transaction {} purge completed", this);
486             parent.completeTransaction(this);
487         });
488     }
489
490     final void enqueuePurge(final long enqueuedTicks) {
491         successfulRequests.clear();
492
493         final TransactionRequest<?> req = new TransactionPurgeRequest(getIdentifier(), nextSequence(), localActor());
494         enqueueRequest(req, t -> {
495             LOG.debug("Transaction {} purge completed", this);
496             parent.completeTransaction(this);
497         }, enqueuedTicks);
498     }
499
500     // Called with the connection unlocked
501     final synchronized void startReconnect() {
502         // At this point canCommit/directCommit are blocked, we assert a new successor state, retrieving the previous
503         // state. This method is called with the queue still unlocked.
504         final SuccessorState nextState = new SuccessorState();
505         final State prevState = STATE_UPDATER.getAndSet(this, nextState);
506
507         LOG.debug("Start reconnect of proxy {} previous state {}", this, prevState);
508         Verify.verify(!(prevState instanceof SuccessorState), "Proxy %s duplicate reconnect attempt after %s", this,
509             prevState);
510
511         // We have asserted a slow-path state, seal(), canCommit(), directCommit() are forced to slow paths, which will
512         // wait until we unblock nextState's latch before accessing state. Now we record prevState for later use and we
513         // are done.
514         nextState.setPrevState(prevState);
515     }
516
517     // Called with the connection locked
518     final void replayMessages(final AbstractProxyTransaction successor,
519             final Iterable<ConnectionEntry> enqueuedEntries) {
520         final SuccessorState local = getSuccessorState();
521         local.setSuccessor(successor);
522
523         // Replay successful requests first
524         if (!successfulRequests.isEmpty()) {
525             // We need to find a good timestamp to use for successful requests, as we do not want to time them out
526             // nor create timing inconsistencies in the queue -- requests are expected to be ordered by their enqueue
527             // time. We will pick the time of the first entry available. If there is none, we will just use current
528             // time, as all other requests will get enqueued afterwards.
529             final ConnectionEntry firstInQueue = Iterables.getFirst(enqueuedEntries, null);
530             final long now = firstInQueue != null ? firstInQueue.getEnqueuedTicks() : parent.currentTime();
531
532             for (Object obj : successfulRequests) {
533                 if (obj instanceof TransactionRequest) {
534                     LOG.debug("Forwarding successful request {} to successor {}", obj, successor);
535                     successor.replayRequest((TransactionRequest<?>) obj, resp -> { }, now);
536                 } else {
537                     Verify.verify(obj instanceof IncrementSequence);
538                     final IncrementSequence increment = (IncrementSequence) obj;
539                     successor.replayRequest(new IncrementTransactionSequenceRequest(getIdentifier(),
540                         increment.getSequence(), localActor(), increment.getDelta()), resp -> { }, now);
541                     LOG.debug("Incrementing sequence {} to successor {}", obj, successor);
542                 }
543             }
544             LOG.debug("{} replayed {} successful requests", getIdentifier(), successfulRequests.size());
545             successfulRequests.clear();
546         }
547
548         // Now replay whatever is in the connection
549         final Iterator<ConnectionEntry> it = enqueuedEntries.iterator();
550         while (it.hasNext()) {
551             final ConnectionEntry e = it.next();
552             final Request<?, ?> req = e.getRequest();
553
554             if (getIdentifier().equals(req.getTarget())) {
555                 Verify.verify(req instanceof TransactionRequest, "Unhandled request %s", req);
556                 LOG.debug("Replaying queued request {} to successor {}", req, successor);
557                 successor.replayRequest((TransactionRequest<?>) req, e.getCallback(), e.getEnqueuedTicks());
558                 it.remove();
559             }
560         }
561
562         /*
563          * Check the state at which we have started the reconnect attempt. State transitions triggered while we were
564          * reconnecting have been forced to slow paths, which will be unlocked once we unblock the state latch
565          * at the end of this method.
566          */
567         final State prevState = local.getPrevState();
568         if (SEALED.equals(prevState)) {
569             LOG.debug("Proxy {} reconnected while being sealed, propagating state to successor {}", this, successor);
570             flushState(successor);
571             successor.ensureSealed();
572         }
573     }
574
575     /**
576      * Invoked from {@link #replayMessages(AbstractProxyTransaction, Iterable)} to have successor adopt an in-flight
577      * request.
578      *
579      * <p>
580      * Note: this method is invoked by the predecessor on the successor.
581      *
582      * @param request Request which needs to be forwarded
583      * @param callback Callback to be invoked once the request completes
584      * @param enqueuedTicks ticker-based time stamp when the request was enqueued
585      */
586     private void replayRequest(final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback,
587             final long enqueuedTicks) {
588         if (request instanceof AbstractLocalTransactionRequest) {
589             handleReplayedLocalRequest((AbstractLocalTransactionRequest<?>) request, callback, enqueuedTicks);
590         } else {
591             handleReplayedRemoteRequest(request, callback, enqueuedTicks);
592         }
593     }
594
595     // Called with the connection locked
596     final void finishReconnect() {
597         final SuccessorState local = getSuccessorState();
598         LOG.debug("Finishing reconnect of proxy {}", this);
599
600         // All done, release the latch, unblocking seal() and canCommit() slow paths
601         local.finish();
602     }
603
604     /**
605      * Invoked from a retired connection for requests which have been in-flight and need to be re-adjusted
606      * and forwarded to the successor connection.
607      *
608      * @param request Request to be forwarded
609      * @param callback Original callback
610      */
611     final void forwardRequest(final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback) {
612         forwardToSuccessor(getSuccessorState().getSuccessor(), request, callback);
613     }
614
615     final void forwardToSuccessor(final AbstractProxyTransaction successor, final TransactionRequest<?> request,
616             final Consumer<Response<?, ?>> callback) {
617         if (successor instanceof LocalProxyTransaction) {
618             forwardToLocal((LocalProxyTransaction)successor, request, callback);
619         } else if (successor instanceof RemoteProxyTransaction) {
620             forwardToRemote((RemoteProxyTransaction)successor, request, callback);
621         } else {
622             throw new IllegalStateException("Unhandled successor " + successor);
623         }
624     }
625
626     abstract boolean isSnapshotOnly();
627
628     abstract void doDelete(YangInstanceIdentifier path);
629
630     abstract void doMerge(YangInstanceIdentifier path, NormalizedNode<?, ?> data);
631
632     abstract void doWrite(YangInstanceIdentifier path, NormalizedNode<?, ?> data);
633
634     abstract CheckedFuture<Boolean, ReadFailedException> doExists(YangInstanceIdentifier path);
635
636     abstract CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> doRead(YangInstanceIdentifier path);
637
638     abstract void doSeal();
639
640     abstract void doAbort();
641
642     @GuardedBy("this")
643     abstract void flushState(AbstractProxyTransaction successor);
644
645     abstract TransactionRequest<?> commitRequest(boolean coordinated);
646
647     /**
648      * Replay a request originating in this proxy to a successor remote proxy.
649      */
650     abstract void forwardToRemote(RemoteProxyTransaction successor, TransactionRequest<?> request,
651             Consumer<Response<?, ?>> callback);
652
653     /**
654      * Replay a request originating in this proxy to a successor local proxy.
655      */
656     abstract void forwardToLocal(LocalProxyTransaction successor, TransactionRequest<?> request,
657             Consumer<Response<?, ?>> callback);
658
659     /**
660      * Invoked from {@link LocalProxyTransaction} when it replays its successful requests to its successor.
661      *
662      * <p>
663      * Note: this method is invoked by the predecessor on the successor.
664      *
665      * @param request Request which needs to be forwarded
666      * @param callback Callback to be invoked once the request completes
667      * @param enqueuedTicks Time stamp to use for enqueue time
668      */
669     abstract void handleReplayedLocalRequest(AbstractLocalTransactionRequest<?> request,
670             @Nullable Consumer<Response<?, ?>> callback, long enqueuedTicks);
671
672     /**
673      * Invoked from {@link RemoteProxyTransaction} when it replays its successful requests to its successor.
674      *
675      * <p>
676      * Note: this method is invoked by the predecessor on the successor.
677      *
678      * @param request Request which needs to be forwarded
679      * @param callback Callback to be invoked once the request completes
680      * @param enqueuedTicks Time stamp to use for enqueue time
681      */
682     abstract void handleReplayedRemoteRequest(TransactionRequest<?> request,
683             @Nullable Consumer<Response<?, ?>> callback, long enqueuedTicks);
684
685     @Override
686     public final String toString() {
687         return MoreObjects.toStringHelper(this).add("identifier", getIdentifier()).add("state", state).toString();
688     }
689 }