Code Review
/
controller.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
BUG-7033: Fix commit exception due to pipe-lining
[controller.git]
/
opendaylight
/
md-sal
/
sal-distributed-datastore
/
src
/
main
/
java
/
org
/
opendaylight
/
controller
/
cluster
/
datastore
/
SimpleShardDataTreeCohort.java
diff --git
a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java
b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java
index 7da174fec583bd1f2ac998383fc8f3677d019712..197c90a60bd62ea15aff24b23b1e17d9a47c5cfa 100644
(file)
--- a/
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java
+++ b/
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java
@@
-13,9
+13,6
@@
import com.google.common.base.Preconditions;
import com.google.common.base.Verify;
import com.google.common.primitives.UnsignedLong;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.base.Verify;
import com.google.common.primitives.UnsignedLong;
import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.SettableFuture;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
@@
-29,7
+26,7
@@
import scala.concurrent.Future;
final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
private static final Logger LOG = LoggerFactory.getLogger(SimpleShardDataTreeCohort.class);
final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
private static final Logger LOG = LoggerFactory.getLogger(SimpleShardDataTreeCohort.class);
- private static final ListenableFuture<Void> VOID_FUTURE = Futures.immediateFuture(null);
+
private final DataTreeModification transaction;
private final ShardDataTree dataTree;
private final TransactionIdentifier transactionId;
private final DataTreeModification transaction;
private final ShardDataTree dataTree;
private final TransactionIdentifier transactionId;
@@
-59,7
+56,6
@@
final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
}
@Override
}
@Override
-
DataTreeModification getDataTreeModification() {
return transaction;
}
DataTreeModification getDataTreeModification() {
return transaction;
}
@@
-94,33
+90,37
@@
final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
}
@Override
}
@Override
- public ListenableFuture<Void> abort() {
- dataTree.startAbort(this);
+ public void abort(final FutureCallback<Void> abortCallback) {
+ if (!dataTree.startAbort(this)) {
+ abortCallback.onSuccess(null);
+ return;
+ }
+
+ candidate = null;
state = State.ABORTED;
final Optional<Future<Iterable<Object>>> maybeAborts = userCohorts.abort();
if (!maybeAborts.isPresent()) {
state = State.ABORTED;
final Optional<Future<Iterable<Object>>> maybeAborts = userCohorts.abort();
if (!maybeAborts.isPresent()) {
- return VOID_FUTURE;
+ abortCallback.onSuccess(null);
+ return;
}
final Future<Iterable<Object>> aborts = maybeAborts.get();
if (aborts.isCompleted()) {
}
final Future<Iterable<Object>> aborts = maybeAborts.get();
if (aborts.isCompleted()) {
- return VOID_FUTURE;
+ abortCallback.onSuccess(null);
+ return;
}
}
- final SettableFuture<Void> ret = SettableFuture.create();
aborts.onComplete(new OnComplete<Iterable<Object>>() {
@Override
public void onComplete(final Throwable failure, final Iterable<Object> objs) {
if (failure != null) {
aborts.onComplete(new OnComplete<Iterable<Object>>() {
@Override
public void onComplete(final Throwable failure, final Iterable<Object> objs) {
if (failure != null) {
-
ret.setException
(failure);
+
abortCallback.onFailure
(failure);
} else {
} else {
-
ret.set
(null);
+
abortCallback.onSuccess
(null);
}
}
}, ExecutionContexts.global());
}
}
}, ExecutionContexts.global());
-
- return ret;
}
@Override
}
@Override
@@
-128,7
+128,12
@@
final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
checkState(State.PRE_COMMIT_COMPLETE);
this.callback = Preconditions.checkNotNull(newCallback);
state = State.COMMIT_PENDING;
checkState(State.PRE_COMMIT_COMPLETE);
this.callback = Preconditions.checkNotNull(newCallback);
state = State.COMMIT_PENDING;
- dataTree.startCommit(this, candidate);
+
+ if (nextFailure == null) {
+ dataTree.startCommit(this, candidate);
+ } else {
+ failedCommit(nextFailure);
+ }
}
private <T> FutureCallback<T> switchState(final State newState) {
}
private <T> FutureCallback<T> switchState(final State newState) {
@@
-140,6
+145,11
@@
final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
return ret;
}
return ret;
}
+ void setNewCandidate(DataTreeCandidateTip dataTreeCandidate) {
+ checkState(State.PRE_COMMIT_COMPLETE);
+ this.candidate = Verify.verifyNotNull(dataTreeCandidate);
+ }
+
void successfulCanCommit() {
switchState(State.CAN_COMMIT_COMPLETE).onSuccess(null);
}
void successfulCanCommit() {
switchState(State.CAN_COMMIT_COMPLETE).onSuccess(null);
}
@@
-158,6
+168,7
@@
final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
*/
// FIXME: this should be asynchronous
void userPreCommit(final DataTreeCandidate dataTreeCandidate) throws ExecutionException, TimeoutException {
*/
// FIXME: this should be asynchronous
void userPreCommit(final DataTreeCandidate dataTreeCandidate) throws ExecutionException, TimeoutException {
+ userCohorts.reset();
userCohorts.canCommit(dataTreeCandidate);
userCohorts.preCommit();
}
userCohorts.canCommit(dataTreeCandidate);
userCohorts.preCommit();
}
@@
-201,6
+212,12
@@
final class SimpleShardDataTreeCohort extends ShardDataTreeCohort {
switchState(State.FAILED).onFailure(cause);
}
switchState(State.FAILED).onFailure(cause);
}
+ void finishCommitPending() {
+ checkState(State.COMMIT_PENDING);
+ // We want to switch the state but keep the callback.
+ callback = switchState(State.FINISH_COMMIT_PENDING);
+ }
+
@Override
public State getState() {
return state;
@Override
public State getState() {
return state;