git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1159570 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2011-08-19 10:16:33 +00:00
parent 0d12055926
commit 6994ecb5ac
3 changed files with 25 additions and 16 deletions

View File

@ -104,6 +104,7 @@ public class DurableUnsubscribeTest extends org.apache.activemq.TestSupport {
//broker.setPersistent(false); //broker.setPersistent(false);
broker.setUseJmx(true); broker.setUseJmx(true);
broker.setBrokerName(getName()); broker.setBrokerName(getName());
broker.deleteAllMessages();
broker.start(); broker.start();
connection = createConnection(); connection = createConnection();

View File

@ -131,6 +131,8 @@ public class PageFile {
// Persistent settings stored in the page file. // Persistent settings stored in the page file.
private MetaData metaData; private MetaData metaData;
private ArrayList<File> tmpFilesForRemoval = new ArrayList<File>();
/** /**
* Use to keep track of updated pages which have not yet been committed. * Use to keep track of updated pages which have not yet been committed.
*/ */
@ -1042,6 +1044,12 @@ public class PageFile {
// the write cache. // the write cache.
if (w.isDone()) { if (w.isDone()) {
writes.remove(w.page.getPageId()); writes.remove(w.page.getPageId());
if (w.tmpFile != null && tmpFilesForRemoval.contains(w.tmpFile)) {
if (!w.tmpFile.delete()) {
throw new IOException("Can't delete temporary KahaDB transaction file:" + w.tmpFile);
}
tmpFilesForRemoval.remove(w.tmpFile);
}
} }
} }
} }
@ -1052,6 +1060,10 @@ public class PageFile {
} }
} }
public void removeTmpFile(File file) {
tmpFilesForRemoval.add(file);
}
private long recoveryFileSizeForPages(int pageCount) { private long recoveryFileSizeForPages(int pageCount) {
return RECOVERY_FILE_HEADER_SIZE+((pageSize+8)*pageCount); return RECOVERY_FILE_HEADER_SIZE+((pageSize+8)*pageCount);
} }

View File

@ -636,6 +636,12 @@ public class Transaction implements Iterable<Page> {
*/ */
public void commit() throws IOException { public void commit() throws IOException {
if( writeTransactionId!=-1 ) { if( writeTransactionId!=-1 ) {
if (tmpFile != null) {
tmpFile.close();
pageFile.removeTmpFile(getTempFile());
tmpFile = null;
txFile = null;
}
// Actually do the page writes... // Actually do the page writes...
pageFile.write(writes.entrySet()); pageFile.write(writes.entrySet());
// Release the pages that were freed up in the transaction.. // Release the pages that were freed up in the transaction..
@ -645,14 +651,6 @@ public class Transaction implements Iterable<Page> {
allocateList.clear(); allocateList.clear();
writes.clear(); writes.clear();
writeTransactionId = -1; writeTransactionId = -1;
if (tmpFile != null) {
tmpFile.close();
if (!getTempFile().delete()) {
throw new IOException("Can't delete temporary KahaDB transaction file:" + getTempFile());
}
tmpFile = null;
txFile = null;
}
} }
size = 0; size = 0;
} }
@ -662,6 +660,12 @@ public class Transaction implements Iterable<Page> {
*/ */
public void rollback() throws IOException { public void rollback() throws IOException {
if( writeTransactionId!=-1 ) { if( writeTransactionId!=-1 ) {
if (tmpFile != null) {
tmpFile.close();
pageFile.removeTmpFile(getTempFile());
tmpFile = null;
txFile = null;
}
// Release the pages that were allocated in the transaction... // Release the pages that were allocated in the transaction...
freePages(allocateList); freePages(allocateList);
@ -669,14 +673,6 @@ public class Transaction implements Iterable<Page> {
allocateList.clear(); allocateList.clear();
writes.clear(); writes.clear();
writeTransactionId = -1; writeTransactionId = -1;
if (tmpFile != null) {
tmpFile.close();
if (getTempFile().delete()) {
throw new IOException("Can't delete temporary KahaDB transaction file:" + getTempFile());
}
tmpFile = null;
txFile = null;
}
} }
size = 0; size = 0;
} }