[Mulgara-svn] r1996 - trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11
pag at mulgara.org
pag at mulgara.org
Fri Jul 15 03:22:27 UTC 2011
Author: pag
Date: 2011-07-15 03:22:27 +0000 (Fri, 15 Jul 2011)
New Revision: 1996
Modified:
trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/XA11StringPoolImpl.java
Log:
Now handling full transaction rollback
Modified: trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/XA11StringPoolImpl.java
===================================================================
--- trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/XA11StringPoolImpl.java 2011-07-15 03:21:49 UTC (rev 1995)
+++ trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/XA11StringPoolImpl.java 2011-07-15 03:22:27 UTC (rev 1996)
@@ -99,7 +99,7 @@
/** The index file for mapping data to a gNode. */
private AVLFile dataToGNode;
- /** The file file reader for mapping gNodes to data. */
+ /** The file reader for mapping gNodes to data. */
private LBufferedFile gNodeToDataFile;
/** The object for creating the output appender. */
@@ -540,7 +540,9 @@
nextGNodeValue = committedNextGNode;
long offset = DataStruct.toOffset(nextGNodeValue);
gNodeToDataAppender.position(offset);
- // gNodeToDataAppender.truncate(offset); // can't truncate since it's mapped
+ // tell the read-only access to prepare for truncation
+ gNodeToDataFile.truncate(offset);
+ forceTruncate(gNodeToDataAppender, offset);
} catch (IOException ioe) {
throw new SimpleXAResourceException("I/O error while performing rollback (new committed phase)", ioe);
}
@@ -799,6 +801,31 @@
/**
+ * Force a file truncation. If memory maps prevent this, attempt to clean them up, and retry the truncation.
+ * @param fc A channel to the file to be truncated.
+ * @param size The new size of the file.
+ * @throws IOException If the file is open beyond the truncation point, and this cannot be overridden.
+ */
+ private void forceTruncate(FileChannel fc, long size) throws IOException {
+ long s = fc.size();
+ if (s <= size) return;
+ int retries = 10;
+ for (;;) {
+ try {
+ fc.truncate(size);
+ break;
+ } catch (IOException e) {
+ // on failure, attempt to clean up all resources keeping the file open
+ if (retries-- == 0) throw e;
+ System.gc();
+ try { Thread.sleep(100); } catch (InterruptedException ie) { }
+ System.runFinalization();
+ }
+ }
+ }
+
+
+ /**
* Closes all the files involved with a data pool
* @param deleteFiles Remove files after closing them.
* @throws IOException There was an error accessing the filesystem.
More information about the Mulgara-svn
mailing list