/** * @return */ @Override public Transaction newTransaction() { return new TransactionImpl(null, storageManager, timeoutSeconds); }
/** * @param xid * @return */ private Transaction newTransaction(final Xid xid) { return new TransactionImpl(xid, storageManager, timeoutSeconds); }
private void purgeAfterRollback(LinkedList<MessageReference> refs) { try { Transaction transaction = new TransactionImpl(storageManager); for (MessageReference reference : refs) { incDelivering(reference); // post ack will decrement this, so need to inc acknowledge(transaction, reference, AckReason.KILLED, null); } transaction.commit(); } catch (Exception e) { logger.warn(e.getMessage(), e); } }
@Override public void ack(final PagedReference reference) throws Exception { // Need to do the ACK and counter atomically (inside a TX) or the counter could get out of sync Transaction tx = new TransactionImpl(this.store); ackTx(tx, reference); tx.commit(); }
@Override public void delete() throws Exception { Transaction tx = new TransactionImpl(storage); delete(tx); tx.commit(); }
/** * Cleanup temporary page counters on non transactional paged messages * * @param pageID */ @Override public void cleanupNonTXCounters(final long pageID) throws Exception { PendingCounter pendingInfo; synchronized (this) { pendingInfo = pendingCounters.remove(pageID); } if (pendingInfo != null) { final int valueCleaned = pendingInfo.getCount(); final long valueSizeCleaned = pendingInfo.getPersistentSize(); Transaction tx = new TransactionImpl(storage); storage.deletePendingPageCounter(tx.getID(), pendingInfo.getId()); // To apply the increment of the value just being cleaned increment(tx, valueCleaned, valueSizeCleaned); tx.addOperation(new TransactionOperationAbstract() { @Override public void afterCommit(Transaction tx) { pendingValue.addAndGet(-valueCleaned); pendingPersistentSize.updateAndGet(val -> val >= valueSizeCleaned ? val - valueSizeCleaned : 0); } }); tx.commit(); } }
/** * Delete everything associated with any queue on this address. * This is to be called when the address is about to be released from paging. * Hence the PagingStore will be holding a write lock, meaning no messages are going to be paged at this time. * So, we shouldn't lock anything after this method, to avoid dead locks between the writeLock and any synchronization with the CursorProvider. */ @Override public void onPageModeCleared() { ArrayList<PageSubscription> subscriptions = cloneSubscriptions(); Transaction tx = new TransactionImpl(storageManager); for (PageSubscription sub : subscriptions) { try { sub.onPageModeCleared(tx); } catch (Exception e) { ActiveMQServerLogger.LOGGER.errorCleaningPagingOnQueue(e, sub.getQueue().getName().toString()); } } try { tx.commit(); } catch (Exception e) { ActiveMQServerLogger.LOGGER.errorCleaningPagingDuringCommit(e); } }
final Transaction tx = new TransactionImpl(storageManager);
@Override public synchronized int expireReferences(final Filter filter) throws Exception { if (isExpirationRedundant()) { return 0; } Transaction tx = new TransactionImpl(storageManager); int count = 0; try (LinkedListIterator<MessageReference> iter = iterator()) { while (iter.hasNext()) { MessageReference ref = iter.next(); if (filter == null || filter.match(ref.getMessage())) { incDelivering(ref); expire(tx, ref); iter.remove(); refRemoved(ref); count++; } } tx.commit(); return count; } }
@Override public synchronized boolean deleteReference(final long messageID) throws Exception { boolean deleted = false; Transaction tx = new TransactionImpl(storageManager); try (LinkedListIterator<MessageReference> iter = iterator()) { while (iter.hasNext()) { MessageReference ref = iter.next(); if (ref.getMessage().getMessageID() == messageID) { incDelivering(ref); acknowledge(tx, ref); iter.remove(); refRemoved(ref); deleted = true; break; } } if (!deleted) { // Look in scheduled deliveries deleted = scheduledDeliveryHandler.removeReferenceWithID(messageID) != null ? true : false; } tx.commit(); return deleted; } }
@Test public void testTimeoutAndThenCommitWithARollback() throws Exception { TransactionImpl tx = new TransactionImpl(newXID(), new FakeSM(), 10); Assert.assertTrue(tx.hasTimedOut(System.currentTimeMillis() + 60000, 10));
@Test public void testTimeoutThenRollbackWithRollback() throws Exception { TransactionImpl tx = new TransactionImpl(newXID(), new FakeSM(), 10); Assert.assertTrue(tx.hasTimedOut(System.currentTimeMillis() + 60000, 10));
Transaction tx = new TransactionImpl(storageManager);
@Test public void testDuplicateNonPersistent() throws Exception { createStorage(); DuplicateIDCache cache = new DuplicateIDCacheImpl(new SimpleString("test"), 2000, journal, false); TransactionImpl tx = new TransactionImpl(journal); for (int i = 0; i < 5000; i++) { byte[] bytes = RandomUtil.randomBytes(); cache.addToCache(bytes, tx); } tx.commit(); for (int i = 0; i < 5000; i++) { byte[] bytes = RandomUtil.randomBytes(); cache.addToCache(bytes, null); } } }
TransactionImpl tx = new TransactionImpl(journal); tx = new TransactionImpl(journal);
Transaction tx = new TransactionImpl(server.getStorageManager()); assertEquals((i + 1) * 1000, counter.getPersistentSize()); tx = new TransactionImpl(server.getStorageManager());
Transaction tx = new TransactionImpl(server.getStorageManager()); assertEquals((i + 1) * 1000, counter.getPersistentSize()); tx = new TransactionImpl(server.getStorageManager());
@Test public void testCounter() 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()); counter.increment(tx, 1, 1000); assertEquals(0, counter.getValue()); assertEquals(0, counter.getPersistentSize()); tx.commit(); storage.waitOnOperations(); assertEquals(1, counter.getValue()); assertEquals(1000, counter.getPersistentSize()); } finally { sf.close(); session.close(); } }
@Test public void testPrepareCounter() throws Exception { Xid xid = newXID(); 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(xid, server.getStorageManager(), 300); for (int i = 0; i < 2000; i++) { counter.increment(tx, 1, 1000); } assertEquals(0, counter.getValue()); tx.prepare(); storage.waitOnOperations(); assertEquals(0, counter.getValue()); server.stop(); server = newActiveMQServer(); server.start(); storage = server.getStorageManager(); queue = server.locateQueue(new SimpleString("A1")); assertNotNull(queue); counter = locateCounter(queue); tx = server.getResourceManager().removeTransaction(xid); assertNotNull(tx); assertEquals(0, counter.getValue()); tx.commit(false); storage.waitOnOperations(); assertEquals(2000, counter.getValue()); }
@Test public void testRestartCounter() throws Exception { 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()); counter.increment(tx, 1, 1000); assertEquals(0, counter.getValue()); assertEquals(0, counter.getPersistentSize()); tx.commit(); storage.waitOnOperations(); assertEquals(1, counter.getValue()); assertEquals(1000, counter.getPersistentSize()); sl.close(); server.stop(); server = newActiveMQServer(); server.start(); queue = server.locateQueue(new SimpleString("A1")); assertNotNull(queue); counter = locateCounter(queue); assertEquals(1, counter.getValue()); assertEquals(1000, counter.getPersistentSize()); }