jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1127984 - in /incubator/jena/Experimental/TxTDB/trunk: src-dev/tx/ src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ src/main/java/com/hp/hpl/jena/tdb/lib/
Date Thu, 26 May 2011 16:20:30 GMT
Author: andy
Date: Thu May 26 16:20:30 2011
New Revision: 1127984

URL: http://svn.apache.org/viewvc?rev=1127984&view=rev
Log: (empty)

Modified:
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/ObjectFileTrans.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileMem.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileSink.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileWrapper.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/StringFile.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/lib/NodeLib.java

Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java?rev=1127984&r1=1127983&r2=1127984&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java Thu May 26 16:20:30 2011
@@ -6,9 +6,8 @@ public class DevTx
     // BlockMgrJournal
     // FileRefs : builtin names<->numbers
     
-    // BlockMgr: address by long.
-    //   Can we use BlockMgr for ObjectFile?
-    // BlockAccess
+    // ObjectFile is "just" BlockAccess with different preallocate.
+    // Delete.
     
     // NodeTable over Journal.
     // One transaction dataset - reuse.  Pool?

Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/ObjectFileTrans.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/ObjectFileTrans.java?rev=1127984&r1=1127983&r2=1127984&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/ObjectFileTrans.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/ObjectFileTrans.java Thu May 26 16:20:30
2011
@@ -11,8 +11,8 @@ import java.util.Iterator ;
 
 import org.openjena.atlas.lib.Pair ;
 import tx.journal.Journal ;
-import tx.journal.JournalEntryType ;
 
+import com.hp.hpl.jena.tdb.base.block.Block ;
 import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
 
 public class ObjectFileTrans implements ObjectFile
@@ -39,16 +39,16 @@ public class ObjectFileTrans implements 
     {}
 
     @Override
-    public ByteBuffer allocWrite(int maxBytes)
+    public Block allocWrite(int maxBytes)
     {
-        return ByteBuffer.allocate(maxBytes) ;
+        ByteBuffer bb = ByteBuffer.allocate(maxBytes) ;
+        // Allocation in ObjectFile.other?
+        return null ;
     }
 
     @Override
-    public long completeWrite(ByteBuffer buffer)
+    public void completeWrite(Block buffer)
     {
-        // Ah.  This is not the id!
-        return journal.writeJournal(JournalEntryType.Object, buffer) ;
     }
 
     @Override

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java?rev=1127984&r1=1127983&r2=1127984&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFile.java
Thu May 26 16:20:30 2011
@@ -10,6 +10,8 @@ package com.hp.hpl.jena.tdb.base.objectf
 import java.nio.ByteBuffer ;
 import java.util.Iterator ;
 
+import com.hp.hpl.jena.tdb.base.block.Block ;
+
 import org.openjena.atlas.lib.Closeable ;
 import org.openjena.atlas.lib.Pair ;
 import org.openjena.atlas.lib.Sync ;
@@ -23,20 +25,11 @@ public interface ObjectFile extends Sync
 {
     public static final String type = "object" ;
     
-//  /** Allocate space for a write - pass this block to completeWrite */ 
-//  public Block allocWrite(int maxBytes) ;
-//  
-//  //public Block alloc(int maxBytes) ;
-//  //public void completeWrite(Block block) ;
-//  
-//  /** Announce that a write is complete (buffer must come from allocWrite) - return the
accessor number */
-//  public void completeWrite(Block buffer) ;
-
     /** Allocate space for a write - pass this buffer to completeWrite */ 
-    public ByteBuffer allocWrite(int maxBytes) ;
+    public Block allocWrite(int maxBytes) ;
     
     /** Announce that a write is complete (buffer must come from allocWrite) - return the
accessor number */
-    public long completeWrite(ByteBuffer buffer) ;
+    public void completeWrite(Block buffer) ;
 
     /** Write out the buffer - return the accessor number */ 
     public long write(ByteBuffer buffer) ;

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileMem.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileMem.java?rev=1127984&r1=1127983&r2=1127984&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileMem.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileMem.java
Thu May 26 16:20:30 2011
@@ -11,6 +11,9 @@ import java.util.ArrayList ;
 import java.util.Iterator ;
 import java.util.List ;
 
+import com.hp.hpl.jena.tdb.base.StorageException ;
+import com.hp.hpl.jena.tdb.base.block.Block ;
+
 import org.openjena.atlas.iterator.Iter ;
 import org.openjena.atlas.iterator.IteratorInteger ;
 import org.openjena.atlas.iterator.Transform ;
@@ -63,21 +66,36 @@ public class ObjectFileMem implements Ob
     {
         if ( closed )
             throw new IllegalStateException("Closed") ;
-        ByteBuffer bb2 = ByteBufferLib.duplicate(bb) ;
-        buffers.add(bb2) ;
-        return buffers.size()-1 ; 
+        int id = buffers.size() ;
+        buffers.add(null) ;
+        write(id, bb) ;
+        return id ; 
     }
 
+    private void write(long id, ByteBuffer bb)
+    {
+        if ( closed )
+            throw new IllegalStateException("Closed") ;
+        ByteBuffer bb2 = ByteBufferLib.duplicate(bb) ;
+        buffers.set((int)id, bb2) ;
+    }
+    
+    
     @Override
-    public ByteBuffer allocWrite(int maxBytes)
+    public Block allocWrite(int maxBytes)
     {
-        return ByteBuffer.allocate(maxBytes) ;
+        long id = buffers.size() ;
+        buffers.add(null) ;
+        return new Block(id, ByteBuffer.allocate(maxBytes)) ;
     }
 
     @Override
-    public long completeWrite(ByteBuffer buffer)
+    public void completeWrite(Block block)
     {
-        return write(buffer) ;
+        if ( block.getId() != buffers.size() )
+            throw new StorageException() ;
+        
+        write(block.getId(), block.getByteBuffer()) ;
     }
 
     @Override

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileSink.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileSink.java?rev=1127984&r1=1127983&r2=1127984&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileSink.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileSink.java
Thu May 26 16:20:30 2011
@@ -9,6 +9,8 @@ package com.hp.hpl.jena.tdb.base.objectf
 import java.nio.ByteBuffer ;
 import java.util.Iterator ;
 
+import com.hp.hpl.jena.tdb.base.block.Block ;
+
 import org.openjena.atlas.lib.Pair ;
 
 
@@ -40,15 +42,15 @@ public class ObjectFileSink implements O
     }
 
     @Override
-    public ByteBuffer allocWrite(int maxBytes)
+    public Block allocWrite(int maxBytes)
     {
-        return ByteBuffer.allocate(maxBytes) ;
+        return new Block(id+1, ByteBuffer.allocate(maxBytes)) ;
     }
 
     @Override
-    public long completeWrite(ByteBuffer buffer)
+    public void completeWrite(Block buffer)
     {
-        return write(buffer) ;
+        write(buffer.getByteBuffer()) ;
     }
 
     @Override

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java?rev=1127984&r1=1127983&r2=1127984&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
Thu May 26 16:20:30 2011
@@ -15,6 +15,7 @@ import java.util.Iterator ;
 import org.openjena.atlas.lib.Bytes ;
 import org.openjena.atlas.lib.Pair ;
 
+import com.hp.hpl.jena.tdb.base.block.Block ;
 import com.hp.hpl.jena.tdb.base.file.BufferChannel ;
 import com.hp.hpl.jena.tdb.base.file.FileException ;
 
@@ -49,7 +50,7 @@ public class ObjectFileStorage implement
     
     // Two-step write - alloc, write
     private boolean inAllocWrite = true ;
-    private ByteBuffer allocByteBuffer = null ;
+    private Block allocBlock = null ;
     private long allocLocation = -1 ;
 
     public ObjectFileStorage(BufferChannel file)
@@ -68,6 +69,7 @@ public class ObjectFileStorage implement
     @Override
     public long write(ByteBuffer bb)
     {
+        inAllocWrite = false ;
         int len = bb.limit() - bb.position() ;
         
         if ( writeBuffer.limit()+len > writeBuffer.capacity() )
@@ -95,7 +97,7 @@ public class ObjectFileStorage implement
     }
     
     @Override
-    public ByteBuffer allocWrite(int maxBytes)
+    public Block allocWrite(int maxBytes)
     {
         // Include space for length.
         int spaceRequired = maxBytes + SizeOfInt ;
@@ -105,11 +107,12 @@ public class ObjectFileStorage implement
         
         if ( spaceRequired > writeBuffer.remaining() )
         {
-            // Too big.
+            // Too big. have flushed buffering.
             inAllocWrite = true ;
-            allocByteBuffer = ByteBuffer.allocate(spaceRequired) ;
+            ByteBuffer bb = ByteBuffer.allocate(spaceRequired) ;
+            allocBlock = new Block(filesize, bb) ;  
             allocLocation = -1 ;
-            return allocByteBuffer ;  
+            return allocBlock ;
         }
         
         // Will fit.
@@ -123,21 +126,26 @@ public class ObjectFileStorage implement
         writeBuffer.limit(start+spaceRequired) ;
         ByteBuffer bb = writeBuffer.slice() ; 
 
-        allocByteBuffer = bb ;
-        return bb ;
+        allocBlock = new Block(allocLocation, bb) ;
+        return allocBlock ;
     }
 
     @Override
-    public long completeWrite(ByteBuffer buffer)
+    public void completeWrite(Block block)
     {
         if ( ! inAllocWrite )
             throw new FileException("Not in the process of an allocated write operation pair")
;
-        if ( allocByteBuffer != buffer )
+        if ( allocBlock != block )
             throw new FileException("Wrong byte buffer in an allocated write operation pair")
;
 
+        ByteBuffer buffer = block.getByteBuffer() ;
+        
         if ( allocLocation == -1 )
+        {
             // It was too big to use the buffering.
-            return rawWrite(buffer) ;
+            rawWrite(buffer) ;
+            return ;
+        }
         
         int actualLength = buffer.limit()-buffer.position() ;
         // Insert object length
@@ -145,11 +153,10 @@ public class ObjectFileStorage implement
         writeBuffer.putInt(idx, actualLength) ;
         // And bytes to idx+actualLength+4 are used
         inAllocWrite = false;
-        allocByteBuffer = null ;
+        allocBlock = null ;
         int newLen = idx+actualLength+4 ;
         writeBuffer.position(newLen);
         writeBuffer.limit(writeBuffer.capacity()) ;
-        return allocLocation ;
     }
 
     private void flushOutputBuffer()
@@ -165,6 +172,7 @@ public class ObjectFileStorage implement
     @Override
     public ByteBuffer read(long loc)
     {
+        inAllocWrite = false ;
         if ( loc < 0 )
             throw new IllegalArgumentException("ObjectFile.read: Bad read: "+loc) ;
         

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileWrapper.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileWrapper.java?rev=1127984&r1=1127983&r2=1127984&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileWrapper.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileWrapper.java
Thu May 26 16:20:30 2011
@@ -9,6 +9,8 @@ package com.hp.hpl.jena.tdb.base.objectf
 import java.nio.ByteBuffer ;
 import java.util.Iterator ;
 
+import com.hp.hpl.jena.tdb.base.block.Block ;
+
 import org.openjena.atlas.lib.Pair ;
 
 /** 
@@ -23,10 +25,10 @@ public class ObjectFileWrapper implement
     public ObjectFileWrapper(ObjectFile other)      { this.other = other ; }
     
     @Override
-    public ByteBuffer allocWrite(int maxBytes)      { return other.allocWrite(maxBytes) ;
}
+    public Block allocWrite(int maxBytes)           { return other.allocWrite(maxBytes) ;
}
 
     @Override
-    public long completeWrite(ByteBuffer buffer)    { return other.completeWrite(buffer)
; }
+    public void completeWrite(Block buffer)         { other.completeWrite(buffer) ; }
 
     @Override
     public long write(ByteBuffer buffer)            { return other.write(buffer) ; }

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/StringFile.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/StringFile.java?rev=1127984&r1=1127983&r2=1127984&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/StringFile.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/StringFile.java
Thu May 26 16:20:30 2011
@@ -13,6 +13,7 @@ import org.openjena.atlas.lib.Closeable 
 import org.openjena.atlas.lib.Sync ;
 
 
+import com.hp.hpl.jena.tdb.base.block.Block ;
 import com.hp.hpl.jena.tdb.lib.StringAbbrev ;
 
 /** Wrap a {@link ObjectFile} with a string encoder/decoder.  
@@ -36,16 +37,10 @@ public class StringFile implements Sync,
     public long write(String str)
     { 
         str = compress(str) ;
-        ByteBuffer bb = file.allocWrite(4*str.length()) ;
-        int len = Bytes.toByteBuffer(str, bb) ;
-        bb.flip() ;
-        return file.completeWrite(bb) ;
-        
-        
-//        ByteBuffer bb = ByteBuffer.allocate(4*str.length()) ;   // Worst case
-//        int len = Bytes.toByteBuffer(str, bb) ;
-//        bb.flip() ;
-//        return file.write(bb) ;
+        Block block = file.allocWrite(4*str.length()) ;
+        int len = Bytes.toByteBuffer(str, block.getByteBuffer()) ;
+        file.completeWrite(block) ;
+        return block.getId() ;
     }
     
     public String read(long id)

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/lib/NodeLib.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/lib/NodeLib.java?rev=1127984&r1=1127983&r2=1127984&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/lib/NodeLib.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/lib/NodeLib.java
Thu May 26 16:20:30 2011
@@ -24,8 +24,8 @@ import org.openjena.atlas.logging.Log ;
 
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.tdb.TDBException ;
+import com.hp.hpl.jena.tdb.base.block.Block ;
 import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
-import com.hp.hpl.jena.tdb.base.objectfile.StringFile ;
 import com.hp.hpl.jena.tdb.base.record.Record ;
 import com.hp.hpl.jena.tdb.nodetable.NodeTable ;
 import com.hp.hpl.jena.tdb.nodetable.Nodec ;
@@ -42,16 +42,6 @@ public class NodeLib
     final private static char MarkerChar = '_' ;
     final private static char[] invalidIRIChars = { MarkerChar , ' ' } ; 
     
-    public static long encodeStore(Node node, StringFile file)
-    {
-        return encodeStore(node, file.getByteBufferFile()) ;
-    }
-
-    public static Node fetchDecode(long id, StringFile file)
-    {
-        return fetchDecode(id, file.getByteBufferFile()) ;
-    }
-
     public static long encodeStore(Node node, ObjectFile file)
     {
         // Buffer pool?
@@ -59,10 +49,10 @@ public class NodeLib
         // Nodes can be writtern during reads.
         // Make sure this operation is sync'ed. 
         int maxSize = nodec.maxSize(node) ;
-        ByteBuffer bb = file.allocWrite(maxSize) ;
-        int len = nodec.encode(node, bb, null) ;
-        long x = file.completeWrite(bb) ;
-        return x ;
+        Block block = file.allocWrite(maxSize) ;
+        int len = nodec.encode(node, block.getByteBuffer(), null) ;
+        file.completeWrite(block) ;
+        return block.getId() ;
     }
     
     public static Node fetchDecode(long id, ObjectFile file)



Mime
View raw message