[ 
https://issues.apache.org/jira/browse/AMQ-7009?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16555745#comment-16555745
 ] 

Nezih BEN FREDJ commented on AMQ-7009:
--------------------------------------

In attachment, a unit test reproducing the 
issue.[^MemoryMessageStoreQueueCursor.java].

To make the memoryMessageStore more robust we can modify methods setBatch and 
recoverNextMessages as follow :

    @Override
    public void setBatch(MessageId messageId) {
        synchronized (messageTable) {
            lastBatchId = messageId;
            if(!messageTable.containsKey(lastBatchId)) {
                lastBatchId = null;
            }
        }
    }

 

    @Override
    public void recoverNextMessages(int maxReturned, MessageRecoveryListener 
listener) throws Exception {
        synchronized (messageTable) {
            boolean containsLastBatchId = messageTable.containsKey(lastBatchId);
            if(!containsLastBatchId) {
                lastBatchId = null;
            }
            
            boolean pastLackBatch = lastBatchId == null;
            for (Map.Entry<MessageId, Message> entry : messageTable.entrySet()) 
{
                if (pastLackBatch) {
                    Object msg = entry.getValue();
                    lastBatchId = entry.getKey();
                    if (msg.getClass() == MessageId.class) {
                        listener.recoverMessageReference((MessageId) msg);
                    } else {
                        listener.recoverMessage((Message) msg);
                    }
                } else {
                    pastLackBatch = entry.getKey().equals(lastBatchId);
                }
            }
        }
    }

> ActiveMQ stop delivering messages
> ---------------------------------
>
>                 Key: AMQ-7009
>                 URL: https://issues.apache.org/jira/browse/AMQ-7009
>             Project: ActiveMQ
>          Issue Type: Bug
>    Affects Versions: 5.15.4
>            Reporter: Nezih BEN FREDJ
>            Priority: Critical
>         Attachments: MemoryMessageStore.java, 
> MemoryMessageStoreQueueCursor.java, activemq.log
>
>
> We have a problem with ActiveMQ 5.15.4, it stop deliver messages to clients.
> This happens completely randomly and we are not able to give a test case that 
> reproduce the problem
> Activemq is configured to use the « memoryPersistenceAdapter »
>  
> When examining memory dumps, we identified incoherent situation in the class 
> MemoryMessageStore that can lead to stop delivering messages. When :
>  - MemoryMessageStore.recoverNextMessages(...) is called
>  - « lastBatchId » is not null
>  - « messageTable » does not contains any entry with « lastBatchId » as key
> no messages are recovered
>  
> We added logs to try to understand how it is possible to have a non null « 
> lastBatchId » and «  messageTable » with no entry having « lastBatchId » as 
> key.
>  
> We noticed that the method setBatch is called with a non null « messageId » 
> parameter, but no message with this id is inserted in « messageTable ». After 
> that, when the method MemoryMessageStore.recoverNextMessages(...) is called, 
> it does nothing and no messages are recoverd. And the system go in a what 
> looks like an endless loop.
>  
> We are testing a temporary solution by resetting « lastBatchId » to null when 
> the incoherent situation is detected.
>  
> Can you help us resolving the problem at the source and not just get around.
> I joined modified source code of the class MemoryMessageStore and an extract 
> of the log file.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to