use of org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest in project controller by opendaylight.
the class LocalProxyTransactionTest method testForwardToLocalPurge.
@Test
public void testForwardToLocalPurge() throws Exception {
final TestProbe probe = createProbe();
final TransactionPurgeRequest request = new TransactionPurgeRequest(TRANSACTION_ID, 0L, probe.ref());
testForwardToLocal(request, TransactionPurgeRequest.class);
}
use of org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest 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.TransactionPurgeRequest in project controller by opendaylight.
the class AbstractProxyTransaction method enqueuePurge.
final void enqueuePurge(final Consumer<Response<?, ?>> callback, final long enqueuedTicks) {
LOG.debug("{}: initiating purge", this);
final State prev = state;
if (prev instanceof SuccessorState) {
((SuccessorState) prev).setDone();
} else {
final boolean success = STATE_UPDATER.compareAndSet(this, prev, DONE);
if (!success) {
LOG.warn("{}: moved from state {} while we were purging it", this, prev);
}
}
successfulRequests.clear();
enqueueRequest(new TransactionPurgeRequest(getIdentifier(), nextSequence(), localActor()), resp -> {
LOG.debug("{}: purge completed", this);
parent.purgeTransaction(this);
if (callback != null) {
callback.accept(resp);
}
}, enqueuedTicks);
}
use of org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest in project controller by opendaylight.
the class AbstractFrontendHistory method handleTransactionRequest.
@Nullable
final TransactionSuccess<?> handleTransactionRequest(final TransactionRequest<?> request, final RequestEnvelope envelope, final long now) throws RequestException {
if (request instanceof TransactionPurgeRequest) {
return handleTransactionPurgeRequest(request, envelope, now);
}
final TransactionIdentifier id = request.getTarget();
final UnsignedLong ul = UnsignedLong.fromLongBits(id.getTransactionId());
if (purgedTransactions.contains(ul)) {
LOG.warn("{}: Request {} is contained purged transactions {}", persistenceId, request, purgedTransactions);
throw new DeadTransactionException(purgedTransactions);
}
final Boolean closed = closedTransactions.get(ul);
if (closed != null) {
final boolean successful = closed.booleanValue();
LOG.debug("{}: Request {} refers to a {} transaction", persistenceId, request, successful ? "successful" : "failed");
throw new ClosedTransactionException(successful);
}
FrontendTransaction tx = transactions.get(id);
if (tx == null) {
// The transaction does not exist and we are about to create it, check sequence number
if (request.getSequence() != 0) {
LOG.warn("{}: no transaction state present, unexpected request {}", persistenceId(), request);
throw new OutOfOrderRequestException(0);
}
tx = createTransaction(request, id);
transactions.put(id, tx);
} else if (!(request instanceof IncrementTransactionSequenceRequest)) {
final Optional<TransactionSuccess<?>> maybeReplay = tx.replaySequence(request.getSequence());
if (maybeReplay.isPresent()) {
final TransactionSuccess<?> replay = maybeReplay.get();
LOG.debug("{}: envelope {} replaying response {}", persistenceId(), envelope, replay);
return replay;
}
}
return tx.handleRequest(request, envelope, now);
}
use of org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest in project controller by opendaylight.
the class AbstractTransmitQueueTest method testCompleteReponseNotMatchingRequest.
@Test
public void testCompleteReponseNotMatchingRequest() throws Exception {
final long requestSequence = 0L;
final long txSequence = 0L;
final long sessionId = 0L;
final Request<?, ?> request = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, requestSequence, probe.ref());
final Consumer<Response<?, ?>> callback = createConsumerMock();
final long now = Ticker.systemTicker().read();
queue.enqueueOrForward(new ConnectionEntry(request, callback, now), now);
// different transaction id
final TransactionIdentifier anotherTxId = new TransactionIdentifier(HISTORY, 1L);
final RequestSuccess<?, ?> success1 = new TransactionPurgeResponse(anotherTxId, requestSequence);
final Optional<TransmittedConnectionEntry> completed1 = queue.complete(new SuccessEnvelope(success1, sessionId, txSequence, 1L), now);
Assert.assertFalse(completed1.isPresent());
// different response sequence
final long differentResponseSequence = 1L;
final RequestSuccess<?, ?> success2 = new TransactionPurgeResponse(TRANSACTION_IDENTIFIER, differentResponseSequence);
final Optional<TransmittedConnectionEntry> completed2 = queue.complete(new SuccessEnvelope(success2, sessionId, txSequence, 1L), now);
Assert.assertFalse(completed2.isPresent());
// different tx sequence
final long differentTxSequence = 1L;
final RequestSuccess<?, ?> success3 = new TransactionPurgeResponse(TRANSACTION_IDENTIFIER, requestSequence);
final Optional<TransmittedConnectionEntry> completed3 = queue.complete(new SuccessEnvelope(success3, sessionId, differentTxSequence, 1L), now);
Assert.assertFalse(completed3.isPresent());
// different session id
final long differentSessionId = 1L;
final RequestSuccess<?, ?> success4 = new TransactionPurgeResponse(TRANSACTION_IDENTIFIER, requestSequence);
final Optional<TransmittedConnectionEntry> completed4 = queue.complete(new SuccessEnvelope(success4, differentSessionId, differentTxSequence, 1L), now);
Assert.assertFalse(completed4.isPresent());
}
Aggregations