From 72146d2daed7d86396a5c9fbb21dbbe555ace914 Mon Sep 17 00:00:00 2001 From: gtully Date: Fri, 11 Sep 2020 17:04:15 +0100 Subject: [PATCH] AMQ-8040 - ensure state relating to diskbound tmp file pages is preserved on next update, fix and test --- .../store/kahadb/disk/page/PageFile.java | 1 - .../index/PageFileTransactionAsyncTest.java | 85 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/PageFileTransactionAsyncTest.java diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/page/PageFile.java b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/page/PageFile.java index 519a1a27e6..a8f975ed88 100644 --- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/page/PageFile.java +++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/page/PageFile.java @@ -178,7 +178,6 @@ public class PageFile { this.page = page; current = data; currentLocation = -1; - diskBoundLocation = -1; } public void setCurrentLocation(Page page, long location, int length) { diff --git a/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/PageFileTransactionAsyncTest.java b/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/PageFileTransactionAsyncTest.java new file mode 100644 index 0000000000..97509ae687 --- /dev/null +++ b/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/disk/index/PageFileTransactionAsyncTest.java @@ -0,0 +1,85 @@ +/** + * 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.index; + +import org.apache.activemq.store.kahadb.disk.page.PageFile; +import org.apache.activemq.store.kahadb.disk.page.Transaction; +import org.apache.activemq.store.kahadb.disk.util.LongMarshaller; +import org.apache.activemq.store.kahadb.disk.util.StringMarshaller; +import org.junit.Test; + +import java.io.File; +import java.util.LinkedList; + +public class PageFileTransactionAsyncTest { + + @Test(timeout=60000) + public void testLargeTransactionPageOkForReuse() throws Exception { + + int numPagesToExercise = 4000; + + PageFile pf = new PageFile(new File("target/test-data"), "PageFileTransactionAsyncTest"); + pf.setEnableWriteThread(true); + pf.setWriteBatchSize(5000); + pf.load(); + + LinkedList indices = new LinkedList<>(); + for (int i=0; i createIndex(PageFile pf) throws Exception { + + Transaction tx = pf.tx(); + long id = tx.allocate().getPageId(); + + BTreeIndex index = new BTreeIndex(pf, id); + index.setKeyMarshaller(StringMarshaller.INSTANCE); + index.setValueMarshaller(LongMarshaller.INSTANCE); + index.load(tx); + tx.commit(); + + return index; + } + +}