From 3a4a360d3f2c83282fc5fad5c0bc8edc8a1a4165 Mon Sep 17 00:00:00 2001 From: "Hiram R. Chirino" Date: Fri, 26 Oct 2007 18:00:14 +0000 Subject: [PATCH] Avoid deleting datafiles that are in-use.. timing issue was making this possible git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@588725 13f79535-47bb-0310-9956-ffa450edef68 --- .../kaha/impl/async/AsyncDataManager.java | 19 ++++++++++++++++++- .../store/amq/AMQPersistenceAdapter.java | 5 ++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java index 97e86a28be..197dfd454b 100644 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java @@ -374,9 +374,20 @@ public final class AsyncDataManager { } } - public synchronized void consolidateDataFilesNotIn(Set inUse) throws IOException { + public synchronized void consolidateDataFilesNotIn(Set inUse, Integer lastDataFile) throws IOException { Set unUsed = new HashSet(fileMap.keySet()); unUsed.removeAll(inUse); + + // Don't purge any data files past lastDataFile + if( lastDataFile!=null ) { + for (Iterator iterator = unUsed.iterator(); iterator.hasNext();) { + DataFile dataFile = (DataFile)iterator.next(); + if( dataFile.getDataFileId() >= lastDataFile ) { + iterator.remove(); + } + } + } + List purgeList = new ArrayList(); for (Integer key : unUsed) { DataFile dataFile = (DataFile)fileMap.get(key); @@ -581,4 +592,10 @@ public final class AsyncDataManager { this.useNio = useNio; } + + synchronized public Integer getCurrentDataFileId() { + if( currentWriteFile==null ) + return null; + return currentWriteFile.getDataFileId(); + } } diff --git a/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java b/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java index b0e3105ea2..ebe5ac7745 100644 --- a/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java @@ -351,8 +351,11 @@ public class AMQPersistenceAdapter implements PersistenceAdapter, UsageListener, */ public void cleanup() { try { + // Capture the lastDataFile so that we don't delete any data files + // after this one. + Integer lastDataFile = asyncDataManager.getCurrentDataFileId(); Set inUse = referenceStoreAdapter.getReferenceFileIdsInUse(); - asyncDataManager.consolidateDataFilesNotIn(inUse); + asyncDataManager.consolidateDataFilesNotIn(inUse, lastDataFile); } catch (IOException e) { LOG.error("Could not cleanup data files: " + e, e); }