use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.
the class ServerSessionImpl method doRollback.
private void doRollback(final boolean clientFailed, final boolean lastMessageAsDelived, final Transaction theTx) throws Exception {
boolean wasStarted = started;
List<MessageReference> toCancel = new ArrayList<>();
for (ServerConsumer consumer : consumers.values()) {
if (wasStarted) {
consumer.setStarted(false);
}
toCancel.addAll(consumer.cancelRefs(clientFailed, lastMessageAsDelived, theTx));
}
// we add them to a new tx and roll them back as the calling client will assume that this has happened.
if (theTx.getState() == State.ROLLEDBACK) {
Transaction newTX = newTransaction();
cancelAndRollback(clientFailed, newTX, wasStarted, toCancel);
} else {
cancelAndRollback(clientFailed, theTx, wasStarted, toCancel);
}
}
use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.
the class ServerSessionImpl method acknowledge.
@Override
public void acknowledge(final long consumerID, final long messageID) throws Exception {
ServerConsumer consumer = findConsumer(consumerID);
if (tx != null && tx.getState() == State.ROLLEDBACK) {
// JBPAPP-8845 - if we let stuff to be acked on a rolled back TX, we will just
// have these messages to be stuck on the limbo until the server is restarted
// The tx has already timed out, so we need to ack and rollback immediately
Transaction newTX = newTransaction();
try {
consumer.acknowledge(newTX, messageID);
} catch (Exception e) {
// just ignored
// will log it just in case
logger.debug("Ignored exception while acking messageID " + messageID + " on a rolledback TX", e);
}
newTX.rollback();
} else {
consumer.acknowledge(autoCommitAcks ? null : tx, messageID);
}
}
use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.
the class RefsOperation method afterRollback.
@Override
public void afterRollback(final Transaction tx) {
Map<QueueImpl, LinkedList<MessageReference>> queueMap = new HashMap<>();
long timeBase = System.currentTimeMillis();
// add any already acked refs, this means that they have been transferred via a producer.send() and have no
// previous state persisted.
List<MessageReference> ackedRefs = new ArrayList<>();
for (MessageReference ref : refsToAck) {
ref.emptyConsumerID();
if (logger.isTraceEnabled()) {
logger.trace("rolling back " + ref);
}
try {
if (ref.isAlreadyAcked()) {
ackedRefs.add(ref);
}
rollbackRedelivery(tx, ref, timeBase, queueMap);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.errorCheckingDLQ(e);
}
}
for (Map.Entry<QueueImpl, LinkedList<MessageReference>> entry : queueMap.entrySet()) {
LinkedList<MessageReference> refs = entry.getValue();
QueueImpl queue = entry.getKey();
synchronized (queue) {
queue.postRollback(refs);
}
}
if (!ackedRefs.isEmpty()) {
// message references
try {
Transaction ackedTX = new TransactionImpl(storageManager);
for (MessageReference ref : ackedRefs) {
Message message = ref.getMessage();
if (message.isDurable()) {
int durableRefCount = message.incrementDurableRefCount();
if (durableRefCount == 1) {
storageManager.storeMessageTransactional(ackedTX.getID(), message);
}
Queue queue = ref.getQueue();
storageManager.storeReferenceTransactional(ackedTX.getID(), queue.getID(), message.getMessageID());
ackedTX.setContainsPersistent();
}
message.incrementRefCount();
}
ackedTX.commit(true);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.failedToProcessMessageReferenceAfterRollback(e);
}
}
}
use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.
the class SimpleOpenWireTest method testXAResourceRolledBackRemoved.
@Test
public void testXAResourceRolledBackRemoved() throws Exception {
Queue queue = null;
Xid xid = newXID();
try (XAConnection xaconnection = xaFactory.createXAConnection()) {
XASession session = xaconnection.createXASession();
queue = session.createQueue(queueName);
session.getXAResource().start(xid, XAResource.TMNOFLAGS);
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("xa message"));
session.getXAResource().end(xid, XAResource.TMSUCCESS);
session.getXAResource().rollback(xid);
}
XidImpl xid1 = new XidImpl(xid);
Transaction transaction = server.getResourceManager().getTransaction(xid1);
assertNull(transaction);
}
use of org.apache.activemq.artemis.core.transaction.Transaction in project activemq-artemis by apache.
the class PagingCounterTest method testCleanupCounter.
@Test
public void testCleanupCounter() throws Exception {
ClientSessionFactory sf = createSessionFactory(sl);
ClientSession session = sf.createSession();
try {
server.addAddressInfo(new AddressInfo(new SimpleString("A1"), RoutingType.ANYCAST));
Queue queue = server.createQueue(new SimpleString("A1"), RoutingType.ANYCAST, new SimpleString("A1"), null, true, false);
PageSubscriptionCounter counter = locateCounter(queue);
StorageManager storage = server.getStorageManager();
Transaction tx = new TransactionImpl(server.getStorageManager());
for (int i = 0; i < 2100; i++) {
counter.increment(tx, 1, 1000);
if (i % 200 == 0) {
tx.commit();
storage.waitOnOperations();
assertEquals(i + 1, counter.getValue());
assertEquals((i + 1) * 1000, counter.getPersistentSize());
tx = new TransactionImpl(server.getStorageManager());
}
}
tx.commit();
storage.waitOnOperations();
assertEquals(2100, counter.getValue());
assertEquals(2100 * 1000, counter.getPersistentSize());
server.stop();
server = newActiveMQServer();
server.start();
queue = server.locateQueue(new SimpleString("A1"));
assertNotNull(queue);
counter = locateCounter(queue);
assertEquals(2100, counter.getValue());
assertEquals(2100 * 1000, counter.getPersistentSize());
} finally {
sf.close();
session.close();
}
}
Aggregations