You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2012/09/08 22:41:56 UTC

svn commit: r1382358 - in /jena/trunk/jena-tdb/src: main/java/com/hp/hpl/jena/tdb/base/objectfile/ main/java/com/hp/hpl/jena/tdb/transaction/ test/java/com/hp/hpl/jena/tdb/nodetable/

Author: andy
Date: Sat Sep  8 20:41:55 2012
New Revision: 1382358

URL: http://svn.apache.org/viewvc?rev=1382358&view=rev
Log:
Add abortWrite(Block) to the ObjectFile interface.

Modified:
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileLogger.java
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileWrapper.java
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/ObjectFileTrans.java
    jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/nodetable/TestNodeTableBase.java

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java?rev=1382358&r1=1382357&r2=1382358&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java Sat Sep  8 20:41:55 2012
@@ -42,9 +42,12 @@ public interface ObjectFile extends Sync
     /** Allocate space for a write - pass this buffer to completeWrite */ 
     public Block allocWrite(int bytesSpace) ;
     
-    /** Announce that a write is complete (buffer must come from allocWrite) - return the accessor number */
+    /** Announce that a write is complete (buffer must come from allocWrite) */
     public void completeWrite(Block buffer) ;
 
+    /** Decide not to perform the write */
+    public void abortWrite(Block buffer) ;
+
     /** Write out the buffer - return the accessor number */ 
     public long write(ByteBuffer buffer) ;
 

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileLogger.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileLogger.java?rev=1382358&r1=1382357&r2=1382358&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileLogger.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileLogger.java Sat Sep  8 20:41:55 2012
@@ -57,6 +57,13 @@ public class ObjectFileLogger implements
     }
 
     @Override
+    public void abortWrite(Block buffer)
+    {
+        info("abortWrite("+buffer.getId()+")") ;
+        other.abortWrite(buffer) ;
+    }
+
+    @Override
     public long write(ByteBuffer buffer)
     {
         info("write"+buffer) ;

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java?rev=1382358&r1=1382357&r2=1382358&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java Sat Sep  8 20:41:55 2012
@@ -74,6 +74,11 @@ public class ObjectFileStorage implement
     private boolean inAllocWrite = false ;
     private Block allocBlock = null ;
     private long allocLocation = -1 ;
+    
+    // Old values for abort.
+    int oldBufferPosn = -1 ;
+    int oldBufferLimit = -1 ;
+
 
     public ObjectFileStorage(BufferChannel file)
     {
@@ -177,6 +182,10 @@ public class ObjectFileStorage implement
         // Will fit.
         inAllocWrite = true ;
         int start = writeBuffer.position() ;
+        // Old values for restoration
+        oldBufferPosn = start ;
+        oldBufferLimit = writeBuffer.limit() ;
+        
         // id (but don't tell the caller yet).
         allocLocation = filesize+start ;
         
@@ -224,6 +233,24 @@ public class ObjectFileStorage implement
         writeBuffer.position(newLen);
         writeBuffer.limit(writeBuffer.capacity()) ;
         allocLocation = -1 ;
+        oldBufferPosn = -1 ;
+        oldBufferLimit = -1 ;
+    }
+
+    @Override
+    public void abortWrite(Block block)
+    {
+        allocBlock = null ;
+        int oldstart = (int)(allocLocation-filesize) ;
+        if ( oldstart != oldBufferPosn)
+            throw new FileException("Wrong reset point: calc="+oldstart+" : expected="+oldBufferPosn) ;        
+        
+        writeBuffer.position(oldstart) ;
+        writeBuffer.limit(oldBufferLimit) ;
+        allocLocation = -1 ;
+        oldBufferPosn = -1 ;
+        oldBufferLimit = -1 ;
+        inAllocWrite = false ;
     }
 
     private void flushOutputBuffer()

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileWrapper.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileWrapper.java?rev=1382358&r1=1382357&r2=1382358&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileWrapper.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileWrapper.java Sat Sep  8 20:41:55 2012
@@ -43,6 +43,9 @@ public class ObjectFileWrapper implement
     public void completeWrite(Block buffer)         { other.completeWrite(buffer) ; }
 
     @Override
+    public void abortWrite(Block buffer)            { other.abortWrite(buffer) ; }
+    
+    @Override
     public long write(ByteBuffer buffer)            { return other.write(buffer) ; }
     
     @Override

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/ObjectFileTrans.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/ObjectFileTrans.java?rev=1382358&r1=1382357&r2=1382358&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/ObjectFileTrans.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/ObjectFileTrans.java Sat Sep  8 20:41:55 2012
@@ -167,6 +167,14 @@ public class ObjectFileTrans implements 
         block = new Block(block.getId()-otherAllocOffset, block.getByteBuffer()) ;
         transObjects.completeWrite(block) ;
     }
+    
+    @Override
+    public void abortWrite(Block block)
+    {
+        if ( passthrough ) { base.abortWrite(block) ; return ; } 
+        block = new Block(block.getId()-otherAllocOffset, block.getByteBuffer()) ;
+        transObjects.abortWrite(block) ;
+    }
 
     /** Convert from a id to the id in the "other" file */ 
     private long mapToOther(long x) { return x-otherAllocOffset ; }

Modified: jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/nodetable/TestNodeTableBase.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/nodetable/TestNodeTableBase.java?rev=1382358&r1=1382357&r2=1382358&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/nodetable/TestNodeTableBase.java (original)
+++ jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/nodetable/TestNodeTableBase.java Sat Sep  8 20:41:55 2012
@@ -23,6 +23,7 @@ import org.openjena.atlas.junit.BaseTest
 
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.sparql.util.NodeFactory ;
+import com.hp.hpl.jena.tdb.TDBException ;
 import com.hp.hpl.jena.tdb.store.NodeId ;
 
 public abstract class TestNodeTableBase extends BaseTest
@@ -40,6 +41,16 @@ public abstract class TestNodeTableBase 
     protected void testNode(Node n)
     {
         NodeTable nt = createEmptyNodeTable() ;
+        writeNode(nt, n) ;
+    }
+    
+    protected static void writeNode(NodeTable nt, String str)
+    {
+        writeNode(nt, NodeFactory.parseNode(str)) ;
+    }
+    
+    protected static void writeNode(NodeTable nt, Node n)
+    {
         NodeId nodeId = nt.getAllocateNodeId(n) ;
         assertNotNull(nodeId) ;
         assertNotEquals(NodeId.NodeDoesNotExist, nodeId) ;
@@ -52,10 +63,43 @@ public abstract class TestNodeTableBase 
         assertEquals(nodeId, nodeId2) ;
     }
     
+    protected static void writeBadNode(NodeTable nt, Node badNode)
+    {
+        NodeId id1 = nt.allocOffset() ;
+        try {
+            NodeId nodeId = nt.getAllocateNodeId(badNode) ;
+            fail("Expected exception for bad node: "+badNode) ;
+        } catch (TDBException ex) { }
+        NodeId id2 = nt.allocOffset() ;
+        assertEquals(id1, id2) ;
+    }
+    
     @Test public void nodetable_01()    { testNode("<http://example/x>") ; }
     @Test public void nodetable_02()    { testNode("1") ; }
     @Test public void nodetable_03()    { testNode("_:x") ; }
     @Test public void nodetable_04()    { testNode("'x'") ; }
     @Test public void nodetable_05()    { testNode("'x'@en") ; }
     @Test public void nodetable_06()    { testNode("'x'^^<http://example/dt>") ; }
+    
+    static Node badNode1 = Node.createLiteral("abc", "99bad", null) ;
+    
+    @Test public void nodetable_bad_01()    { testNodeBad(badNode1) ; }
+    @Test public void nodetable_bad_02()    
+    { 
+        NodeTable nt = createEmptyNodeTable() ;
+        writeNode(nt, "'x'") ;
+        NodeId id1 = nt.allocOffset() ;
+        writeBadNode(nt, badNode1) ; 
+        NodeId id2 = nt.allocOffset() ;
+        assertEquals(id1, id2) ;
+        writeNode(nt, "<http://example/x>") ;
+        
+    }
+
+    protected void testNodeBad(Node badNode)
+    {
+        NodeTable nt = createEmptyNodeTable() ;
+        writeBadNode(nt, badNode) ;
+    }
+
 }