Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EAA831741F for ; Mon, 2 Feb 2015 13:02:48 +0000 (UTC) Received: (qmail 67222 invoked by uid 500); 2 Feb 2015 13:02:49 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 67178 invoked by uid 500); 2 Feb 2015 13:02:49 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 67166 invoked by uid 99); 2 Feb 2015 13:02:49 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Feb 2015 13:02:49 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 85AA5E035D; Mon, 2 Feb 2015 13:02:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gtully@apache.org To: commits@activemq.apache.org Message-Id: <0e7fd6c1b7b24ba9a2a530ddcde2f3c9@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: activemq git commit: https://issues.apache.org/jira/browse/AMQ-5542 fix (via revert below) and test case applied with thanks. Date: Mon, 2 Feb 2015 13:02:49 +0000 (UTC) Repository: activemq Updated Branches: refs/heads/trunk b35b8e37f -> b0a1bd833 https://issues.apache.org/jira/browse/AMQ-5542 fix (via revert below) and test case applied with thanks. Revert "resolve https://issues.apache.org/activemq/browse/AMQ-2736, logic issue in code that keeps data files with acks around pending message file gc. thanks jgenender - test case to follow" This reverts commit dd68c61e65f24b7dc498b36e34960a4bc46ded4b. resolves: https://issues.apache.org/jira/browse/AMQ-5542 and applies test case that nicely demonstrates the defect, thanks Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/b0a1bd83 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/b0a1bd83 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/b0a1bd83 Branch: refs/heads/trunk Commit: b0a1bd833c2ea8e4ce2063636b0ee638f3f97f9b Parents: b35b8e3 Author: gtully Authored: Fri Jan 30 14:45:26 2015 +0000 Committer: gtully Committed: Mon Feb 2 11:34:06 2015 +0000 ---------------------------------------------------------------------- .../activemq/store/kahadb/MessageDatabase.java | 3 +- .../org/apache/activemq/bugs/AMQ2832Test.java | 51 ++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/b0a1bd83/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java ---------------------------------------------------------------------- diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java index 35a59ce..477f42c 100644 --- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java +++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java @@ -1672,14 +1672,13 @@ public abstract class MessageDatabase extends ServiceSupport implements BrokerSe if (LOG.isTraceEnabled()) { LOG.trace("gc candidates: " + gcCandidateSet); } - final TreeSet gcCandidates = new TreeSet(gcCandidateSet); Iterator candidates = gcCandidateSet.iterator(); while (candidates.hasNext()) { Integer candidate = candidates.next(); Set referencedFileIds = metadata.ackMessageFileMap.get(candidate); if (referencedFileIds != null) { for (Integer referencedFileId : referencedFileIds) { - if (completeFileSet.contains(referencedFileId) && !gcCandidates.contains(referencedFileId)) { + if (completeFileSet.contains(referencedFileId) && !gcCandidateSet.contains(referencedFileId)) { // active file that is not targeted for deletion is referenced so don't delete candidates.remove(); break; http://git-wip-us.apache.org/repos/asf/activemq/blob/b0a1bd83/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2832Test.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2832Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2832Test.java index 319fcc2..22ad6ab 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2832Test.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2832Test.java @@ -17,6 +17,7 @@ package org.apache.activemq.bugs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -117,7 +118,57 @@ public class AMQ2832Test { } } + /** + * Scenario: + * db-1.log has an unacknowledged message, + * db-2.log contains acks for the messages from db-1.log, + * db-3.log contains acks for the messages from db-2.log + * + * Expected behavior: since db-1.log is blocked, db-2.log and db-3.log should not be removed during the cleanup. + * Current situation on 5.10.0, 5.10.1 is that db-3.log is removed causing all messages from db-2.log, whose acks were in db-3.log, to be replayed. + * + * @throws Exception + */ @Test + public void testAckChain() throws Exception { + startBroker(); + + StagedConsumer consumer = new StagedConsumer(); + // file #1 + produceMessagesToConsumeMultipleDataFiles(5); + // acknowledge first 2 messages and leave the 3rd one unacknowledged blocking db-1.log + consumer.receive(3); + + // send messages by consuming and acknowledging every message right after sent in order to get KahadbAdd and Remove command to be saved together + // this is necessary in order to get KahaAddMessageCommand to be saved in one db file and the corresponding KahaRemoveMessageCommand in the next one + produceAndConsumeImmediately(20, consumer); + consumer.receive(2).acknowledge(); // consume and ack the last 2 unconsumed + + // now we have 3 files written and started with #4 + consumer.close(); + + broker.stop(); + broker.waitUntilStopped(); + + recoverBroker(); + + consumer = new StagedConsumer(); + Message message = consumer.receive(1); + assertNotNull("One message stays unacked from db-1.log", message); + message.acknowledge(); + message = consumer.receive(1); + assertNull("There should not be any unconsumed messages any more", message); + consumer.close(); + } + + private void produceAndConsumeImmediately(int numOfMsgs, StagedConsumer consumer) throws Exception { + for (int i = 0; i < numOfMsgs; i++) { + produceMessagesToConsumeMultipleDataFiles(1); + consumer.receive(1).acknowledge(); + } + } + + @Test public void testAckRemovedMessageReplayedAfterRecovery() throws Exception { startBroker();