activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cshan...@apache.org
Subject activemq git commit: https://issues.apache.org/jira/browse/AMQ-6572
Date Mon, 23 Jan 2017 16:05:02 GMT
Repository: activemq
Updated Branches:
  refs/heads/activemq-5.14.x cab6f73c9 -> f947a74f4


https://issues.apache.org/jira/browse/AMQ-6572

On journal start use lastFileLength instead of maxFileLength when
checking for unused space in the last journal file as it is possible the
length of the last journal file is not the same length as maxFileLength

(cherry picked from commit 0ad62f722fef6c2123ef7acb116a80574a43c250)


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/f947a74f
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/f947a74f
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/f947a74f

Branch: refs/heads/activemq-5.14.x
Commit: f947a74f4acd1a60d6a2bac94b8515a50a82564b
Parents: cab6f73
Author: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Authored: Mon Jan 23 11:00:11 2017 -0500
Committer: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Committed: Mon Jan 23 11:04:49 2017 -0500

----------------------------------------------------------------------
 .../store/kahadb/disk/journal/Journal.java      |   5 +-
 .../journal/JournalMaxFileLengthChangeTest.java | 143 +++++++++++++++++++
 2 files changed, 146 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/f947a74f/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java
b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java
index a68b460..415bc99 100644
--- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java
+++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/Journal.java
@@ -306,8 +306,9 @@ public class Journal {
         }
 
         // ensure we don't report unused space of last journal file in size metric
-        if (totalLength.get() > maxFileLength && lastAppendLocation.get().getOffset()
> 0) {
-            totalLength.addAndGet(lastAppendLocation.get().getOffset() - maxFileLength);
+        int lastFileLength = dataFiles.getTail().getLength();
+        if (totalLength.get() > lastFileLength && lastAppendLocation.get().getOffset()
> 0) {
+            totalLength.addAndGet(lastAppendLocation.get().getOffset() - lastFileLength);
         }
 
         cleanupTask = scheduler.scheduleAtFixedRate(new Runnable() {

http://git-wip-us.apache.org/repos/asf/activemq/blob/f947a74f/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/journal/JournalMaxFileLengthChangeTest.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/journal/JournalMaxFileLengthChangeTest.java
b/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/journal/JournalMaxFileLengthChangeTest.java
new file mode 100644
index 0000000..b28f1e3
--- /dev/null
+++ b/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/journal/JournalMaxFileLengthChangeTest.java
@@ -0,0 +1,143 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.store.kahadb.disk.journal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.activemq.broker.ConnectionContext;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTextMessage;
+import org.apache.activemq.command.MessageId;
+import org.apache.activemq.store.MessageStore;
+import org.apache.activemq.store.kahadb.KahaDBStore;
+import org.junit.After;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.Timeout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JournalMaxFileLengthChangeTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(JournalMaxFileLengthChangeTest.class);
+
+    private static int ONE_MB = 1024*1024;
+
+    @Rule
+    public TemporaryFolder dataDir = new TemporaryFolder();
+
+    @Rule
+    public Timeout globalTimeout= new Timeout(20, TimeUnit.SECONDS);
+
+    private KahaDBStore store;
+
+    @After
+    public void after() throws Exception {
+        if (store != null) {
+            store.stop();
+        }
+    }
+
+    /**
+     * Test that reported size is correct if the maxFileLength grows
+     * in between journal restarts.  Verify all messages still received.
+     */
+    @Test
+    public void testMaxFileLengthGrow() throws Exception {
+        MessageStore messageStore = createStore(8 * ONE_MB);
+        addMessages(messageStore, 4);
+
+        long sizeBeforeChange = store.getJournal().getDiskSize();
+        LOG.info("Journal size before: " + sizeBeforeChange);
+
+        store.stop();
+        messageStore = createStore(6 * ONE_MB);
+        verifyMessages(messageStore, 4);
+
+        long sizeAfterChange = store.getJournal().getDiskSize();
+        LOG.info("Journal size after: " + sizeAfterChange);
+
+        //verify the size is the same - will be slightly different as checkpoint journal
+        //commands are written but should be close
+        assertEquals(sizeBeforeChange, sizeAfterChange, 4096);
+    }
+
+    /**
+     * Test that reported size is correct if the maxFileLength shrinks
+     * in between journal restarts.  Verify all messages still received.
+     */
+    @Test
+    public void testMaxFileLengthShrink() throws Exception {
+        MessageStore messageStore = createStore(8 * ONE_MB);
+        addMessages(messageStore, 4);
+
+        long sizeBeforeChange = store.getJournal().getDiskSize();
+        LOG.info("Journal size before: " + sizeBeforeChange);
+
+        store.stop();
+        messageStore = createStore(2 * ONE_MB);
+        verifyMessages(messageStore, 4);
+
+        long sizeAfterChange = store.getJournal().getDiskSize();
+        LOG.info("Journal size after: " + sizeAfterChange);
+
+        //verify the size is the same - will be slightly different as checkpoint journal
+        //commands are written but should be close
+        assertEquals(sizeBeforeChange, sizeAfterChange, 4096);
+    }
+
+    private void addMessages(MessageStore messageStore, int num) throws Exception {
+        String text = getString(ONE_MB);
+
+        for (int i=0; i < num; i++) {
+            ActiveMQTextMessage textMessage = new ActiveMQTextMessage();
+            textMessage.setMessageId(new MessageId("1:2:3:" + i));
+            textMessage.setText(text);
+            messageStore.addMessage(new ConnectionContext(), textMessage);
+        }
+    }
+
+    private void verifyMessages(MessageStore messageStore, int num) throws Exception {
+        for (int i=0; i < num; i++) {
+            assertNotNull(messageStore.getMessage(new MessageId("1:2:3:" + i)));
+        }
+    }
+
+    private String getString(int size) {
+        StringBuilder builder = new StringBuilder();
+
+        for (int i = 0; i < size; i++) {
+            builder.append("a");
+        }
+        return builder.toString();
+    }
+
+    private MessageStore createStore(int length) throws Exception {
+        File dataDirectory = dataDir.getRoot();
+        store = new KahaDBStore();
+        store.setJournalMaxFileLength(length);
+        store.setDirectory(dataDirectory);
+        store.setForceRecoverIndex(true);
+        store.start();
+        return store.createQueueMessageStore(new ActiveMQQueue("test"));
+    }
+}


Mime
View raw message