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/09/13 19:05:29 UTC
svn commit: r1170242 - in /incubator/jena/Experimental/TxTDB/trunk/src:
main/java/com/hp/hpl/jena/tdb/transaction/
test/java/com/hp/hpl/jena/tdb/transaction/
Author: andy
Date: Tue Sep 13 17:05:29 2011
New Revision: 1170242
URL: http://svn.apache.org/viewvc?rev=1170242&view=rev
Log:
Adding handling of "buffers" -- variable sizes blobs, not handled by the usual BlockMgrs (partial support).
Modified:
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/BlockMgrJournal.java
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/Journal.java
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalEntry.java
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/Transaction.java
incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestJournal.java
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/BlockMgrJournal.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/BlockMgrJournal.java?rev=1170242&r1=1170241&r2=1170242&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/BlockMgrJournal.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/BlockMgrJournal.java Tue Sep 13 17:05:29 2011
@@ -267,7 +267,7 @@ public class BlockMgrJournal implements
private void writeJournalEntry(Block blk)
{
blk.getByteBuffer().rewind() ;
- transaction.getJournal().writeJournal(fileRef, blk) ;
+ transaction.getJournal().write(JournalEntryType.Block, fileRef, blk) ;
}
private void logState()
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/Journal.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/Journal.java?rev=1170242&r1=1170241&r2=1170242&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/Journal.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/Journal.java Tue Sep 13 17:05:29 2011
@@ -7,7 +7,6 @@
package com.hp.hpl.jena.tdb.transaction;
import static com.hp.hpl.jena.tdb.sys.SystemTDB.SizeOfInt ;
-import static com.hp.hpl.jena.tdb.transaction.JournalEntryType.Block ;
import java.nio.ByteBuffer ;
import java.util.Iterator ;
@@ -93,7 +92,7 @@ class Journal implements Iterable<Journa
synchronized
public long writeJournal(JournalEntry entry)
{
- long posn = _write(entry.getType(), entry.getFileRef(), entry.getByteBuffer(), entry.getBlock()) ;
+ long posn = write(entry.getType(), entry.getFileRef(), entry.getBlock()) ;
if ( entry.getPosition() < 0 )
{
entry.setPosition(posn) ;
@@ -101,31 +100,25 @@ class Journal implements Iterable<Journa
}
return posn ;
}
-
- synchronized
- public long writeJournal(JournalEntryType type, FileRef fileRef, ByteBuffer buffer)
- {
- return _write(type, fileRef, buffer, null) ;
- }
-
- synchronized
- public long writeJournal(FileRef fileRef, Block block)
- {
- return _write(Block, fileRef, null, block) ;
- }
+//
+//// synchronized
+//// public long writeJournal(JournalEntryType type, FileRef fileRef, ByteBuffer buffer)
+//// {
+//// return _write(type, fileRef, buffer, null) ;
+//// }
+////
+// synchronized
+// public long writeJournal(FileRef fileRef, Block block)
+// {
+// return _write(Block, fileRef, null, block) ;
+// }
synchronized
- private long _write(JournalEntryType type, FileRef fileRef, ByteBuffer buffer, Block block)
+ public long write(JournalEntryType type, FileRef fileRef, Block block)
{
//log.info("@"+position()+" -- "+type+","+fileRef+", "+buffer+", "+block) ;
-
- if ( buffer != null && block != null )
- throw new TDBTransactionException("Buffer and block to write") ;
- if ( block != null )
- buffer = block.getByteBuffer() ;
- if ( block != null && type != Block )
- throw new TDBTransactionException("Block to write but not block type") ;
+ ByteBuffer buffer = (block == null) ? null : block.getByteBuffer() ;
long posn = position ;
int bufferCapacity = 0 ;
@@ -229,18 +222,9 @@ class Journal implements Iterable<Journa
JournalEntryType type = JournalEntryType.type(typeId) ;
FileRef fileRef = FileRef.get(ref) ;
ByteBuffer bb = ByteBuffer.allocate(len) ;
- Block block = null ;
lenRead = channel.read(bb) ;
adler.update(bb.array()) ;
bb.rewind() ;
- if ( type == Block )
- {
- block = new Block(blockId, bb) ;
- bb = null ;
- }
- else
- blockId = NoId ;
-
// checksum
crcTrailer.clear() ;
lenRead = channel.read(crcTrailer) ;
@@ -250,7 +234,8 @@ class Journal implements Iterable<Journa
if ( checksum != (int)adler.getValue() )
throw new TDBTransactionException("Checksum error reading from the Journal.") ;
- return new JournalEntry(type, fileRef, bb, block) ;
+ Block block = new Block(blockId, bb) ;
+ return new JournalEntry(type, fileRef, block) ;
}
/** Iterator of entries from current point in Journal, going forward. Must be JournalEntry aligned at start. */
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalEntry.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalEntry.java?rev=1170242&r1=1170241&r2=1170242&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalEntry.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalEntry.java Tue Sep 13 17:05:29 2011
@@ -20,32 +20,34 @@ public class JournalEntry
private long position = -1 ; // Location in the Journal (if known).
private long endPosition = -1 ; // End location in the Journal: offset of next entry start.
+
private final JournalEntryType type ;
- private final ByteBuffer byteBuffer ; // One or other must be null - or both.
private final Block block ;
private final FileRef fileRef ;
private JournalEntry(JournalEntryType type)
{
- this(type, null, null, null) ;
+ this(type, null, (Block)null) ;
}
- public JournalEntry(JournalEntryType type, FileRef fileRef, ByteBuffer bytes)
+// public JournalEntry(JournalEntryType type, FileRef fileRef, ByteBuffer bytes)
+// {
+// this(type, fileRef, bytes, null) ;
+// }
+//
+// public JournalEntry(FileRef fileRef, Block block)
+// {
+// this(JournalEntryType.Block, fileRef, null, block) ;
+// }
+
+ JournalEntry(JournalEntryType type, FileRef fileRef, ByteBuffer bytes)
{
- this(type, fileRef, bytes, null) ;
+ this(type, fileRef, new Block(0, bytes)) ;
}
- public JournalEntry(FileRef fileRef, Block block)
- {
- this(JournalEntryType.Block, fileRef, null, block) ;
- }
-
- JournalEntry(JournalEntryType type, FileRef fileRef, ByteBuffer bytes, Block block)
+ JournalEntry(JournalEntryType type, FileRef fileRef, Block block)
{
- if ( bytes != null && block != null )
- throw new TDBTransactionException("buffer != null and block != null") ;
this.type = type ;
- this.byteBuffer = bytes ;
this.block = block ;
this.fileRef = fileRef ;
}
@@ -57,7 +59,7 @@ public class JournalEntry
long getEndPosition() { return endPosition ; }
public JournalEntryType getType() { return type ; }
- public ByteBuffer getByteBuffer() { return byteBuffer ; }
+ public ByteBuffer getByteBuffer() { return block.getByteBuffer() ; }
public Block getBlock() { return block ; }
public FileRef getFileRef() { return fileRef ; }
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/Transaction.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/Transaction.java?rev=1170242&r1=1170241&r2=1170242&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/Transaction.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/Transaction.java Tue Sep 13 17:05:29 2011
@@ -75,8 +75,7 @@ public class Transaction
if ( state != TxnState.ACTIVE )
throw new TDBTransactionException("Transaction has already committed or aborted") ;
prepare() ;
- JournalEntry entry = new JournalEntry(JournalEntryType.Commit, FileRef.Journal, null) ;
- journal.writeJournal(entry) ;
+ journal.write(JournalEntryType.Commit, FileRef.Journal, null) ;
journal.sync() ; // Commit point.
}
Modified: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestJournal.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestJournal.java?rev=1170242&r1=1170241&r2=1170242&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestJournal.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestJournal.java Tue Sep 13 17:05:29 2011
@@ -130,8 +130,8 @@ public class TestJournal extends BaseTes
@Test public void journal_06()
{
- JournalEntry entry1 = new JournalEntry(testRef, blk1) ;
- JournalEntry entry2 = new JournalEntry(testRef, blk2) ;
+ JournalEntry entry1 = new JournalEntry(JournalEntryType.Block, testRef, blk1) ;
+ JournalEntry entry2 = new JournalEntry(JournalEntryType.Block, testRef, blk2) ;
long x1 = journal.writeJournal(entry1) ;
bb1.clear();