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
This commit is contained in:
Hiram R. Chirino 2007-10-26 18:00:14 +00:00
parent 6084b6061b
commit 3a4a360d3f
2 changed files with 22 additions and 2 deletions

View File

@ -374,9 +374,20 @@ public final class AsyncDataManager {
}
}
public synchronized void consolidateDataFilesNotIn(Set<Integer> inUse) throws IOException {
public synchronized void consolidateDataFilesNotIn(Set<Integer> inUse, Integer lastDataFile) throws IOException {
Set<Integer> unUsed = new HashSet<Integer>(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<DataFile> purgeList = new ArrayList<DataFile>();
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();
}
}

View File

@ -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<Integer> inUse = referenceStoreAdapter.getReferenceFileIdsInUse();
asyncDataManager.consolidateDataFilesNotIn(inUse);
asyncDataManager.consolidateDataFilesNotIn(inUse, lastDataFile);
} catch (IOException e) {
LOG.error("Could not cleanup data files: " + e, e);
}