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 2011/05/29 23:10:11 UTC
svn commit: r1128954 - in /incubator/jena/Experimental/TxTDB/trunk:
src-dev/tx/DevTx.java
src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileMem.java
src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
Author: andy
Date: Sun May 29 21:10:11 2011
New Revision: 1128954
URL: http://svn.apache.org/viewvc?rev=1128954&view=rev
Log: (empty)
Modified:
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.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/ObjectFileStorage.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=1128954&r1=1128953&r2=1128954&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java Sun May 29 21:10:11 2011
@@ -3,9 +3,6 @@ package tx;
public class DevTx
{
- // Sort out alloc/complete in storage. Does not have to adjacent pairs.
- // ** ObjectFileStorage does not include a length.
-
// check test cases.
// ObjectFile
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=1128954&r1=1128953&r2=1128954&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 Sun May 29 21:10:11 2011
@@ -80,13 +80,16 @@ public class ObjectFileMem implements Ob
buffers.set((int)id, bb2) ;
}
+ private Block allocBlock = null ;
@Override
public Block allocWrite(int bytesSpace)
{
long id = buffers.size() ;
buffers.add(null) ;
- return new Block(id, ByteBuffer.allocate(bytesSpace)) ;
+ Block b = new Block(id, ByteBuffer.allocate(bytesSpace)) ;
+ allocBlock = b ;
+ return b ;
}
@Override
@@ -94,12 +97,17 @@ public class ObjectFileMem implements Ob
{
if ( block.getId() != buffers.size()-1 )
throw new StorageException() ;
+ if ( block != allocBlock )
+ throw new StorageException() ;
+ allocBlock = null ;
write(block.getId(), block.getByteBuffer()) ;
}
@Override
public void reposition(long id)
{
+ if ( allocBlock != null )
+ throw new StorageException("In the middle of an alloc-write") ;
int newSize = (int)id ;
if ( newSize < 0 || newSize >= buffers.size() )
throw new StorageException() ;
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=1128954&r1=1128953&r2=1128954&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 Sun May 29 21:10:11 2011
@@ -14,6 +14,7 @@ import java.util.Iterator ;
import org.openjena.atlas.lib.Bytes ;
import org.openjena.atlas.lib.Pair ;
+import org.openjena.atlas.logging.Log ;
import com.hp.hpl.jena.tdb.base.block.Block ;
import com.hp.hpl.jena.tdb.base.file.BufferChannel ;
@@ -49,7 +50,7 @@ public class ObjectFileStorage implement
private long filesize ; // Size of on-disk.
// Two-step write - alloc, write
- private boolean inAllocWrite = true ;
+ private boolean inAllocWrite = false ;
private Block allocBlock = null ;
private long allocLocation = -1 ;
@@ -69,6 +70,8 @@ public class ObjectFileStorage implement
@Override
public long write(ByteBuffer bb)
{
+ if ( inAllocWrite )
+ Log.fatal(this, "In the middle of an alloc-write") ;
inAllocWrite = false ;
int len = bb.limit() - bb.position() ;
int spaceNeeded = len + SizeOfInt ;
@@ -105,6 +108,9 @@ public class ObjectFileStorage implement
@Override
public Block allocWrite(int bytesSpace)
{
+ if ( inAllocWrite )
+ Log.fatal(this, "In the middle of an alloc-write") ;
+
// Include space for length.
int spaceRequired = bytesSpace + SizeOfInt ;
// Find space.
@@ -145,6 +151,8 @@ public class ObjectFileStorage implement
if ( allocBlock != block )
throw new FileException("Wrong byte buffer in an allocated write operation pair") ;
+ inAllocWrite = false ;
+
ByteBuffer buffer = block.getByteBuffer() ;
if ( allocLocation == -1 )
@@ -159,7 +167,6 @@ public class ObjectFileStorage implement
int idx = (int)(allocLocation-filesize) ;
writeBuffer.putInt(idx, actualLength) ;
// And bytes to idx+actualLength+4 are used
- inAllocWrite = false;
allocBlock = null ;
int newLen = idx+actualLength+4 ;
writeBuffer.position(newLen);
@@ -168,8 +175,7 @@ public class ObjectFileStorage implement
private void flushOutputBuffer()
{
- //if ( writeBuffer.position() == 0 ) return ;
-
+ if ( writeBuffer.position() == 0 ) return ;
long location = filesize ;
writeBuffer.flip();
int x = file.write(writeBuffer) ;
@@ -180,6 +186,8 @@ public class ObjectFileStorage implement
@Override
public void reposition(long id)
{
+ if ( inAllocWrite )
+ throw new FileException("In the middle of an alloc-write") ;
if ( id < 0 || id > filesize )
throw new IllegalArgumentException("reposition: Bad location: "+id) ;
flushOutputBuffer() ;
@@ -190,7 +198,8 @@ public class ObjectFileStorage implement
@Override
public ByteBuffer read(long loc)
{
- inAllocWrite = false ;
+ if ( inAllocWrite )
+ throw new FileException("In the middle of an alloc-write") ;
if ( loc < 0 )
throw new IllegalArgumentException("ObjectFile.read: Bad read: "+loc) ;