Search in sources :

Example 6 with DuplicateIDCache

use of org.apache.activemq.artemis.core.postoffice.DuplicateIDCache in project activemq-artemis by apache.

the class PostOfficeImpl method getDuplicateIDCache.

@Override
public DuplicateIDCache getDuplicateIDCache(final SimpleString address) {
    DuplicateIDCache cache = duplicateIDCaches.get(address);
    if (cache == null) {
        cache = new DuplicateIDCacheImpl(address, idCacheSize, storageManager, persistIDCache);
        DuplicateIDCache oldCache = duplicateIDCaches.putIfAbsent(address, cache);
        if (oldCache != null) {
            cache = oldCache;
        }
    }
    return cache;
}
Also used : DuplicateIDCache(org.apache.activemq.artemis.core.postoffice.DuplicateIDCache)

Example 7 with DuplicateIDCache

use of org.apache.activemq.artemis.core.postoffice.DuplicateIDCache in project activemq-artemis by apache.

the class PostOfficeImpl method checkDuplicateID.

private boolean checkDuplicateID(final Message message, final RoutingContext context, boolean rejectDuplicates, AtomicBoolean startedTX) throws Exception {
    // Check the DuplicateCache for the Bridge first
    Object bridgeDup = message.removeExtraBytesProperty(Message.HDR_BRIDGE_DUPLICATE_ID);
    if (bridgeDup != null) {
        // if the message is being sent from the bridge, we just ignore the duplicate id, and use the internal one
        byte[] bridgeDupBytes = (byte[]) bridgeDup;
        DuplicateIDCache cacheBridge = getDuplicateIDCache(BRIDGE_CACHE_STR.concat(context.getAddress(message).toString()));
        if (context.getTransaction() == null) {
            context.setTransaction(new TransactionImpl(storageManager));
            startedTX.set(true);
        }
        if (!cacheBridge.atomicVerify(bridgeDupBytes, context.getTransaction())) {
            context.getTransaction().rollback();
            startedTX.set(false);
            message.decrementRefCount();
            return false;
        }
    } else {
        // if used BridgeDuplicate, it's not going to use the regular duplicate
        // since this will would break redistribution (re-setting the duplicateId)
        byte[] duplicateIDBytes = message.getDuplicateIDBytes();
        DuplicateIDCache cache = null;
        boolean isDuplicate = false;
        if (duplicateIDBytes != null) {
            cache = getDuplicateIDCache(context.getAddress(message));
            isDuplicate = cache.contains(duplicateIDBytes);
            if (rejectDuplicates && isDuplicate) {
                ActiveMQServerLogger.LOGGER.duplicateMessageDetected(message);
                String warnMessage = "Duplicate message detected - message will not be routed. Message information:" + message.toString();
                if (context.getTransaction() != null) {
                    context.getTransaction().markAsRollbackOnly(new ActiveMQDuplicateIdException(warnMessage));
                }
                message.decrementRefCount();
                return false;
            }
        }
        if (cache != null && !isDuplicate) {
            if (context.getTransaction() == null) {
                // We need to store the duplicate id atomically with the message storage, so we need to create a tx for this
                context.setTransaction(new TransactionImpl(storageManager));
                startedTX.set(true);
            }
            cache.addToCache(duplicateIDBytes, context.getTransaction(), false);
        }
    }
    return true;
}
Also used : DuplicateIDCache(org.apache.activemq.artemis.core.postoffice.DuplicateIDCache) ActiveMQDuplicateIdException(org.apache.activemq.artemis.api.core.ActiveMQDuplicateIdException) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 8 with DuplicateIDCache

use of org.apache.activemq.artemis.core.postoffice.DuplicateIDCache in project activemq-artemis by apache.

the class PostOfficeJournalLoader method handleDuplicateIds.

@Override
public void handleDuplicateIds(Map<SimpleString, List<Pair<byte[], Long>>> duplicateIDMap) throws Exception {
    for (Map.Entry<SimpleString, List<Pair<byte[], Long>>> entry : duplicateIDMap.entrySet()) {
        SimpleString address = entry.getKey();
        DuplicateIDCache cache = postOffice.getDuplicateIDCache(address);
        if (configuration.isPersistIDCache()) {
            cache.load(entry.getValue());
        }
    }
}
Also used : DuplicateIDCache(org.apache.activemq.artemis.core.postoffice.DuplicateIDCache) AtomicLong(java.util.concurrent.atomic.AtomicLong) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with DuplicateIDCache

use of org.apache.activemq.artemis.core.postoffice.DuplicateIDCache in project activemq-artemis by apache.

the class LiveOnlyActivation method scaleDown.

public long scaleDown() throws Exception {
    ScaleDownHandler scaleDownHandler = new ScaleDownHandler(activeMQServer.getPagingManager(), activeMQServer.getPostOffice(), activeMQServer.getNodeManager(), activeMQServer.getClusterManager().getClusterController(), activeMQServer.getStorageManager());
    ConcurrentMap<SimpleString, DuplicateIDCache> duplicateIDCaches = ((PostOfficeImpl) activeMQServer.getPostOffice()).getDuplicateIDCaches();
    Map<SimpleString, List<Pair<byte[], Long>>> duplicateIDMap = new HashMap<>();
    for (SimpleString address : duplicateIDCaches.keySet()) {
        DuplicateIDCache duplicateIDCache = activeMQServer.getPostOffice().getDuplicateIDCache(address);
        duplicateIDMap.put(address, duplicateIDCache.getMap());
    }
    return scaleDownHandler.scaleDown(scaleDownClientSessionFactory, activeMQServer.getResourceManager(), duplicateIDMap, activeMQServer.getManagementService().getManagementAddress(), null);
}
Also used : DuplicateIDCache(org.apache.activemq.artemis.core.postoffice.DuplicateIDCache) HashMap(java.util.HashMap) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) List(java.util.List) PostOfficeImpl(org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl)

Aggregations

DuplicateIDCache (org.apache.activemq.artemis.core.postoffice.DuplicateIDCache)9 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)6 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DuplicateIDCacheImpl (org.apache.activemq.artemis.core.postoffice.impl.DuplicateIDCacheImpl)2 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Xid (javax.transaction.xa.Xid)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 ActiveMQDuplicateIdException (org.apache.activemq.artemis.api.core.ActiveMQDuplicateIdException)1 Message (org.apache.activemq.artemis.api.core.Message)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1