use of org.opendaylight.controller.cluster.access.commands.TransactionRequest in project controller by opendaylight.
the class RemoteProxyTransaction method handleReplayedRemoteRequest.
@Override
void handleReplayedRemoteRequest(final TransactionRequest<?> request, @Nullable final Consumer<Response<?, ?>> callback, final long enqueuedTicks) {
final Consumer<Response<?, ?>> cb = callback != null ? callback : resp -> {
};
final Optional<Long> optTicks = Optional.of(Long.valueOf(enqueuedTicks));
if (request instanceof ModifyTransactionRequest) {
handleReplayedModifyTransactionRequest(enqueuedTicks, cb, (ModifyTransactionRequest) request);
} else if (request instanceof ReadTransactionRequest) {
ensureFlushedBuider(optTicks);
enqueueRequest(new ReadTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ReadTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
recordFinishedRequest(resp);
cb.accept(resp);
}, enqueuedTicks);
} else if (request instanceof ExistsTransactionRequest) {
ensureFlushedBuider(optTicks);
enqueueRequest(new ExistsTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ExistsTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
recordFinishedRequest(resp);
cb.accept(resp);
}, enqueuedTicks);
} else if (request instanceof TransactionPreCommitRequest) {
ensureFlushedBuider(optTicks);
final TransactionRequest<?> tmp = new TransactionPreCommitRequest(getIdentifier(), nextSequence(), localActor());
enqueueRequest(tmp, resp -> {
recordSuccessfulRequest(tmp);
cb.accept(resp);
}, enqueuedTicks);
} else if (request instanceof TransactionDoCommitRequest) {
ensureFlushedBuider(optTicks);
enqueueRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), callback, enqueuedTicks);
} else if (request instanceof TransactionAbortRequest) {
ensureFlushedBuider(optTicks);
enqueueDoAbort(callback, enqueuedTicks);
} else if (request instanceof TransactionPurgeRequest) {
enqueuePurge(callback, enqueuedTicks);
} else if (request instanceof IncrementTransactionSequenceRequest) {
final IncrementTransactionSequenceRequest req = (IncrementTransactionSequenceRequest) request;
ensureFlushedBuider(optTicks);
enqueueRequest(new IncrementTransactionSequenceRequest(getIdentifier(), nextSequence(), localActor(), snapshotOnly, req.getIncrement()), callback, enqueuedTicks);
incrementSequence(req.getIncrement());
} else {
throw new IllegalArgumentException("Unhandled request {}" + request);
}
}
use of org.opendaylight.controller.cluster.access.commands.TransactionRequest in project controller by opendaylight.
the class Shard method handleRequest.
@Nullable
private RequestSuccess<?, ?> handleRequest(final RequestEnvelope envelope, final long now) throws RequestException {
// We are not the leader, hence we want to fail-fast.
if (!isLeader() || paused || !isLeaderActive()) {
LOG.debug("{}: not currently active leader, rejecting request {}. isLeader: {}, isLeaderActive: {}," + "isLeadershipTransferInProgress: {}, paused: {}", persistenceId(), envelope, isLeader(), isLeaderActive(), isLeadershipTransferInProgress(), paused);
throw new NotLeaderException(getSelf());
}
final Request<?, ?> request = envelope.getMessage();
if (request instanceof TransactionRequest) {
final TransactionRequest<?> txReq = (TransactionRequest<?>) request;
final ClientIdentifier clientId = txReq.getTarget().getHistoryId().getClientId();
return getFrontend(clientId).handleTransactionRequest(txReq, envelope, now);
} else if (request instanceof LocalHistoryRequest) {
final LocalHistoryRequest<?> lhReq = (LocalHistoryRequest<?>) request;
final ClientIdentifier clientId = lhReq.getTarget().getClientId();
return getFrontend(clientId).handleLocalHistoryRequest(lhReq, envelope, now);
} else {
LOG.warn("{}: rejecting unsupported request {}", persistenceId(), request);
throw new UnsupportedRequestException(request);
}
}
use of org.opendaylight.controller.cluster.access.commands.TransactionRequest in project controller by opendaylight.
the class RemoteProxyTransaction method handleForwardedRequest.
void handleForwardedRequest(final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback) {
if (request instanceof ModifyTransactionRequest) {
handleForwardedModifyTransactionRequest(callback, (ModifyTransactionRequest) request);
} else if (request instanceof ReadTransactionRequest) {
ensureFlushedBuider();
sendRequest(new ReadTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ReadTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
recordFinishedRequest(resp);
callback.accept(resp);
});
} else if (request instanceof ExistsTransactionRequest) {
ensureFlushedBuider();
sendRequest(new ExistsTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ExistsTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
recordFinishedRequest(resp);
callback.accept(resp);
});
} else if (request instanceof TransactionPreCommitRequest) {
ensureFlushedBuider();
final TransactionRequest<?> tmp = new TransactionPreCommitRequest(getIdentifier(), nextSequence(), localActor());
sendRequest(tmp, resp -> {
recordSuccessfulRequest(tmp);
callback.accept(resp);
});
} else if (request instanceof TransactionDoCommitRequest) {
ensureFlushedBuider();
sendRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), callback);
} else if (request instanceof TransactionAbortRequest) {
ensureFlushedBuider();
sendDoAbort(callback);
} else if (request instanceof TransactionPurgeRequest) {
enqueuePurge(callback);
} else {
throw new IllegalArgumentException("Unhandled request {}" + request);
}
}
use of org.opendaylight.controller.cluster.access.commands.TransactionRequest in project controller by opendaylight.
the class AbstractProxyTransaction method replayMessages.
// Called with the connection locked
final void replayMessages(final ProxyHistory successorHistory, final Iterable<ConnectionEntry> enqueuedEntries) {
final SuccessorState local = getSuccessorState();
final State prevState = local.getPrevState();
final AbstractProxyTransaction successor = successorHistory.createTransactionProxy(getIdentifier(), isSnapshotOnly(), local.isDone());
LOG.debug("{} created successor {}", this, successor);
local.setSuccessor(successor);
// Replay successful requests first
if (!successfulRequests.isEmpty()) {
// We need to find a good timestamp to use for successful requests, as we do not want to time them out
// nor create timing inconsistencies in the queue -- requests are expected to be ordered by their enqueue
// time. We will pick the time of the first entry available. If there is none, we will just use current
// time, as all other requests will get enqueued afterwards.
final ConnectionEntry firstInQueue = Iterables.getFirst(enqueuedEntries, null);
final long now = firstInQueue != null ? firstInQueue.getEnqueuedTicks() : parent.currentTime();
for (Object obj : successfulRequests) {
if (obj instanceof TransactionRequest) {
LOG.debug("Forwarding successful request {} to successor {}", obj, successor);
successor.doReplayRequest((TransactionRequest<?>) obj, resp -> {
/*NOOP*/
}, now);
} else {
Verify.verify(obj instanceof IncrementSequence);
final IncrementSequence increment = (IncrementSequence) obj;
successor.doReplayRequest(new IncrementTransactionSequenceRequest(getIdentifier(), increment.getSequence(), localActor(), isSnapshotOnly(), increment.getDelta()), resp -> {
/*NOOP*/
}, now);
LOG.debug("Incrementing sequence {} to successor {}", obj, successor);
}
}
LOG.debug("{} replayed {} successful requests", getIdentifier(), successfulRequests.size());
successfulRequests.clear();
}
// Now replay whatever is in the connection
final Iterator<ConnectionEntry> it = enqueuedEntries.iterator();
while (it.hasNext()) {
final ConnectionEntry e = it.next();
final Request<?, ?> req = e.getRequest();
if (getIdentifier().equals(req.getTarget())) {
Verify.verify(req instanceof TransactionRequest, "Unhandled request %s", req);
LOG.debug("Replaying queued request {} to successor {}", req, successor);
successor.doReplayRequest((TransactionRequest<?>) req, e.getCallback(), e.getEnqueuedTicks());
it.remove();
}
}
/*
* Check the state at which we have started the reconnect attempt. State transitions triggered while we were
* reconnecting have been forced to slow paths, which will be unlocked once we unblock the state latch
* at the end of this method.
*/
if (SEALED.equals(prevState)) {
LOG.debug("Proxy {} reconnected while being sealed, propagating state to successor {}", this, successor);
final long enqueuedTicks = parent.currentTime();
final java.util.Optional<ModifyTransactionRequest> optState = flushState();
if (optState.isPresent()) {
successor.handleReplayedRemoteRequest(optState.get(), null, enqueuedTicks);
}
if (successor.markSealed()) {
successor.sealAndSend(Optional.of(enqueuedTicks));
}
}
}
use of org.opendaylight.controller.cluster.access.commands.TransactionRequest in project controller by opendaylight.
the class BouncingReconnectForwarder method findCohort.
private ProxyReconnectCohort findCohort(final ConnectionEntry entry) throws CohortNotFoundException {
final Request<?, ?> request = entry.getRequest();
final LocalHistoryIdentifier historyId;
if (request instanceof TransactionRequest) {
historyId = ((TransactionRequest<?>) request).getTarget().getHistoryId();
} else if (request instanceof LocalHistoryRequest) {
historyId = ((LocalHistoryRequest<?>) request).getTarget();
} else {
throw new IllegalArgumentException("Unhandled request " + request);
}
final ProxyReconnectCohort cohort = cohorts.get(historyId);
if (cohort == null) {
LOG.warn("Cohort for request {} not found, aborting it", request);
throw new CohortNotFoundException(historyId);
}
return cohort;
}
Aggregations