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/01/06 17:20:13 UTC

svn commit: r1228248 - in /incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base: buffer/RecordBuffer.java record/RecordFactory.java

Author: andy
Date: Fri Jan  6 16:20:12 2012
New Revision: 1228248

URL: http://svn.apache.org/viewvc?rev=1228248&view=rev
Log:
Notes on need for sync in accessing buffers to get records.

Modified:
    incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/buffer/RecordBuffer.java
    incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/record/RecordFactory.java

Modified: incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/buffer/RecordBuffer.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/buffer/RecordBuffer.java?rev=1228248&r1=1228247&r2=1228248&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/buffer/RecordBuffer.java (original)
+++ incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/buffer/RecordBuffer.java Fri Jan  6 16:20:12 2012
@@ -111,11 +111,6 @@ public class RecordBuffer extends Buffer
     void _set(int idx, Record rec)
     {
         factory.insertInto(rec, bb, idx) ;
-//        byte[] data = rec.getKey() ; 
-//        if ( data.length != slotLen )
-//            throw new RecordException(format("Wrong length: actual=%d, expected=%d", data.length, slotLen)) ;
-//        bb.position(idx*slotLen) ;
-//        bb.put(data, 0, slotLen) ;
     }
     
     // Linear search for testing.

Modified: incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/record/RecordFactory.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/record/RecordFactory.java?rev=1228248&r1=1228247&r2=1228248&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/record/RecordFactory.java (original)
+++ incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/record/RecordFactory.java Fri Jan  6 16:20:12 2012
@@ -100,7 +100,18 @@ public class RecordFactory
     {
         byte[] key = new byte[keyLength] ;
         byte[] value = (hasValue() ? new byte[valueLength] :null ) ;
+
+//        int posnKey = idx*slotLen ;
+//        // Avoid using position() so we can avoid needing synchronized.
+//        copyInto(key, bb, posnKey, keyLength) ;
+//        if ( value != null )
+//        {
+//            int posnValue = idx*slotLen+keyLength ;
+//            copyInto(value, bb, posnValue, valueLength) ;
+//        }
         
+        // Using bb.get(byte[],,) may be potentially faster but requires the synchronized
+        // There's no absolute version.
         synchronized(bb)
         {
             bb.position(idx*slotLen) ;
@@ -111,6 +122,16 @@ public class RecordFactory
         return create(key, value) ;
     }
     
+    private final void copyInto(byte[] dst, ByteBuffer src, int start, int length)
+    {
+        // Thread safe.
+        for ( int i = 0 ; i < length ; i++ )
+            dst[i] = src.get(start+i) ;
+        // Would otherwise be ...
+//        src.position(start) ;
+//        src.get(dst, 0, length) ;
+    }
+    
     public boolean hasValue()   { return valueLength > 0 ; }
 
     public int recordLength()   { return keyLength + valueLength ; }