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.setUseJmx(true);
broker.setBrokerName(getName());
broker.deleteAllMessages();
broker.start();
connection = createConnection();

View File

@ -131,6 +131,8 @@ public class PageFile {
// Persistent settings stored in the page file.
private MetaData metaData;
private ArrayList<File> tmpFilesForRemoval = new ArrayList<File>();
/**
* Use to keep track of updated pages which have not yet been committed.
*/
@ -1042,6 +1044,12 @@ public class PageFile {
// the write cache.
if (w.isDone()) {
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) {
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 {
if( writeTransactionId!=-1 ) {
if (tmpFile != null) {
tmpFile.close();
pageFile.removeTmpFile(getTempFile());
tmpFile = null;
txFile = null;
}
// Actually do the page writes...
pageFile.write(writes.entrySet());
// Release the pages that were freed up in the transaction..
@ -645,14 +651,6 @@ public class Transaction implements Iterable<Page> {
allocateList.clear();
writes.clear();
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;
}
@ -662,6 +660,12 @@ public class Transaction implements Iterable<Page> {
*/
public void rollback() throws IOException {
if( writeTransactionId!=-1 ) {
if (tmpFile != null) {
tmpFile.close();
pageFile.removeTmpFile(getTempFile());
tmpFile = null;
txFile = null;
}
// Release the pages that were allocated in the transaction...
freePages(allocateList);
@ -669,14 +673,6 @@ public class Transaction implements Iterable<Page> {
allocateList.clear();
writes.clear();
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;
}