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/08/31 14:40:41 UTC
svn commit: r1163606 - in /incubator/jena/Experimental/TxTDB/trunk:
src-dev/tx/ src/main/java/com/hp/hpl/jena/tdb/base/file/
src/main/java/com/hp/hpl/jena/tdb/base/objectfile/
src/main/java/com/hp/hpl/jena/tdb/transaction/
src/test/java/com/hp/hpl/jena...
Author: andy
Date: Wed Aug 31 12:40:41 2011
New Revision: 1163606
URL: http://svn.apache.org/viewvc?rev=1163606&view=rev
Log:
JENA-91: Return correct allocation offset in a stack of queued transactions. Must go to the root node table.
Modified:
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Report_JENA91a.java
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileFactory.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/transaction/NodeTableTrans.java
incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileMem.java
incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestObjectFileTransMem.java
incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSystem.java
Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Report_JENA91a.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Report_JENA91a.java?rev=1163606&r1=1163605&r2=1163606&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Report_JENA91a.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Report_JENA91a.java Wed Aug 31 12:40:41 2011
@@ -116,7 +116,7 @@ public class Report_JENA91a {
Iterator<Pair<NodeId, Node>> iter = nodeTable.all() ;
System.out.println("---------------[ " + label + " ]---------------") ;
while ( iter.hasNext() ) { System.out.println(iter.next()) ; }
- System.out.println("------------------------------------\n") ;
+ System.out.println("------------------------------------") ;
System.out.flush() ;
}
}
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileFactory.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileFactory.java?rev=1163606&r1=1163605&r2=1163606&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileFactory.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/FileFactory.java Wed Aug 31 12:40:41 2011
@@ -8,7 +8,6 @@
package com.hp.hpl.jena.tdb.base.file;
import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
-import com.hp.hpl.jena.tdb.base.objectfile.ObjectFileMem ;
import com.hp.hpl.jena.tdb.base.objectfile.ObjectFileStorage ;
import com.hp.hpl.jena.tdb.base.objectfile.StringFile ;
@@ -28,15 +27,11 @@ public class FileFactory
public static ObjectFile createObjectFileMem(String filename)
{
- if ( false )
- // Older code.
- return new ObjectFileMem(filename) ;
- else
- {
- // Newer way.
- BufferChannel file = BufferChannelMem.create(filename) ;
- return new ObjectFileStorage(file) ;
- }
+ // Old.
+ //return new com.hp.hpl.jena.tdb.base.objectfile.ObjectFileMem(filename) ;
+ // Newer way.
+ BufferChannel file = BufferChannelMem.create(filename) ;
+ return new ObjectFileStorage(file) ;
}
public static PlainFile createPlainFileDisk(String filename)
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=1163606&r1=1163605&r2=1163606&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 Wed Aug 31 12:40:41 2011
@@ -25,8 +25,9 @@ import org.openjena.atlas.lib.ByteBuffer
/** In-memory ByteBufferFile (for testing) - copies bytes in and out
* to ensure no implicit modification.
+ * @deprecated Use new ObjectFileStorage(BufferChannelMem.create(filename)) (see FileFcatory)
*/
-
+@Deprecated
public class ObjectFileMem implements ObjectFile
{
private List<ByteBuffer> buffers = new ArrayList<ByteBuffer>() ;
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java?rev=1163606&r1=1163605&r2=1163606&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java Wed Aug 31 12:40:41 2011
@@ -61,7 +61,7 @@ public class NodeTableTrans implements N
this.journal = journal ;
this.label = label ;
// Show the way tables are wired up
- debug("NTT[%s #%s] %s", label, Integer.toHexString(hashCode()), sub) ;
+ //debug("NTT[%s #%s] %s", label, Integer.toHexString(hashCode()), sub) ;
}
public void setPassthrough(boolean v) { passthrough = v ; }
@@ -93,10 +93,20 @@ public class NodeTableTrans implements N
}
/** Convert from a id to the id in the "journal" file */
- private NodeId mapToJournal(NodeId id) { return NodeId.create(id.getId()-offset) ; }
+ private NodeId mapToJournal(NodeId id)
+ {
+ if ( passthrough )
+ throw new TDBTransactionException("Not in an active transaction") ;
+ return NodeId.create(id.getId()-offset) ;
+ }
/** Convert from a id in other to an external id */
- private NodeId mapFromJournal(NodeId id) { return NodeId.create(id.getId()+offset) ; }
+ private NodeId mapFromJournal(NodeId id)
+ {
+ if ( passthrough )
+ throw new TDBTransactionException("Not in an active transaction") ;
+ return NodeId.create(id.getId()+offset) ;
+ }
@Override
public Node getNodeForNodeId(NodeId id)
@@ -120,9 +130,11 @@ public class NodeTableTrans implements N
@Override
public NodeId allocOffset()
{
+ if ( passthrough ) return base.allocOffset() ;
+ // If we have done the append stage, this is invalid as the base may change under our feet
+ // Would need to track base operations.
NodeId x1 = nodeTableJournal.allocOffset() ;
NodeId x2 = mapFromJournal(x1) ;
- debug("allocOffset: %s/%s %s -> %s [%d]", txn.getLabel(), label, x1, x2, offset) ;
return x2 ;
}
@@ -131,17 +143,15 @@ public class NodeTableTrans implements N
{
if ( this.txn.getTxnId() != txn.getTxnId() )
throw new TDBException(String.format("Different transactions: %s %s", this.txn.getLabel(), txn.getLabel())) ;
-
+ if ( passthrough )
+ throw new TDBException("Already active") ;
passthrough = false ;
offset = base.allocOffset().getId() ;
// Any outstanding transactions
long journalOffset = journal.length() ;
- debug("begin: %s %s", txn.getLabel(), label) ;
- debug("begin: base=%s offset=0x%X journalOffset=0x%X", base, offset, journalOffset) ;
-
-// base.allocOffset().getId() ; // DBG
-// journal.length() ; // DBG
+ //debug("begin: %s %s", txn.getLabel(), label) ;
+ //debug("begin: base=%s offset=0x%X journalOffset=0x%X", base, offset, journalOffset) ;
offset += journalOffset ;
this.nodeTableJournal = new NodeTableNative(nodeIndex, journal) ;
@@ -152,7 +162,7 @@ public class NodeTableTrans implements N
/** Copy from the journal file to the real file */
public /*temporary*/ void append()
{
- debug("append: %s",label) ;
+ //debug("append: %s",label) ;
// Assumes all() is in order from low to high.
Iterator<Pair<NodeId, Node>> iter = nodeTableJournal.all() ;
@@ -161,20 +171,18 @@ public class NodeTableTrans implements N
Pair<NodeId, Node> x = iter.next() ;
NodeId nodeId = x.getLeft() ;
Node node = x.getRight() ;
- debug("append: %s -> %s", x, mapFromJournal(nodeId)) ;
+ //debug("append: %s -> %s", x, mapFromJournal(nodeId)) ;
// This does the write.
NodeId nodeId2 = base.getAllocateNodeId(node) ;
if ( ! nodeId2.equals(mapFromJournal(nodeId)) )
throw new TDBException(String.format("Different ids for %s: allocated: expected %s, got %s", node, mapFromJournal(nodeId), nodeId2)) ;
}
- // Reset!
- offset = base.allocOffset().getId() ;
}
@Override
public void commitPrepare(Transaction txn)
{
- debug("commitPrepare: %s", label) ;
+ //debug("commitPrepare: %s", label) ;
// The node table is append-only so it can be written during prepare.
// It does not need to wait for "enact".
if ( nodeTableJournal == null )
@@ -188,7 +196,8 @@ public class NodeTableTrans implements N
// The work was done in commitPrepare, using the fact that node data file
// is append only. Until pointers to the extra data aren't available
// until the index is written.
- debug("commitEnact: %s", label) ;
+
+ //debug("commitEnact: %s", label) ;
//writeJournal() ;
}
@@ -197,26 +206,25 @@ public class NodeTableTrans implements N
if ( nodeTableJournal.isEmpty() )
return ;
- NodeId x1 = base.allocOffset() ;
+ //debug("writeNodeJournal: (base alloc before) %s", base.allocOffset()) ;
append() ;
- NodeId x2 = base.allocOffset() ;
-
- NodeId x3 = nodeTableJournal.allocOffset() ;
- debug("writeNodeJournal: (base alloc before) %s -> (base alloc after) %s -> (nodeTableJournal) %s", x1, x2, x3) ;
+ //debug("writeNodeJournal: (base alloc after) %s", base.allocOffset()) ;
+ //debug("writeNodeJournal: (nodeTableJournal) %s", nodeTableJournal.allocOffset()) ;
// Reset (in case we use this again)
nodeIndex.clear() ;
+ // Fixes nodeTableJournal
journal.truncate(journalStartOffset) ;
journal.sync() ;
base.sync() ;
- offset = base.allocOffset().getId() ;
+ offset = -99 ; // base.allocOffset().getId() ; // Wil be invalid as we may write through to the base table later.
passthrough = true ;
}
@Override
public void commitClearup(Transaction txn)
{
- debug("commitClearup") ;
+ //debug("commitClearup") ;
finish() ;
}
Modified: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileMem.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileMem.java?rev=1163606&r1=1163605&r2=1163606&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileMem.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileMem.java Wed Aug 31 12:40:41 2011
@@ -6,13 +6,15 @@
package com.hp.hpl.jena.tdb.base.objectfile;
+import com.hp.hpl.jena.tdb.base.file.FileFactory ;
+
public class TestObjectFileMem extends AbstractTestObjectFile
{
@Override
protected ObjectFile make()
{
- return new ObjectFileMem() ;
+ return FileFactory.createObjectFileMem("test") ;
}
}
Modified: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestObjectFileTransMem.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestObjectFileTransMem.java?rev=1163606&r1=1163605&r2=1163606&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestObjectFileTransMem.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestObjectFileTransMem.java Wed Aug 31 12:40:41 2011
@@ -6,15 +6,15 @@
package com.hp.hpl.jena.tdb.transaction;
+import com.hp.hpl.jena.tdb.base.file.FileFactory ;
import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
-import com.hp.hpl.jena.tdb.base.objectfile.ObjectFileMem ;
public class TestObjectFileTransMem extends AbstractTestObjectFileTrans
{
@Override
ObjectFile createFile(String basename)
{
- return new ObjectFileMem() ;
+ return FileFactory.createObjectFileMem("test") ;
}
@Override
Modified: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSystem.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSystem.java?rev=1163606&r1=1163605&r2=1163606&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSystem.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSystem.java Wed Aug 31 12:40:41 2011
@@ -52,7 +52,7 @@ public class TestTransSystem
static { org.openjena.atlas.logging.Log.setLog4j() ; }
private static Logger log = LoggerFactory.getLogger(TestTransSystem.class) ;
- static boolean MEM = false ;
+ static boolean MEM = true ;
static final Location LOC = MEM ? Location.mem() : new Location(ConfigTest.getTestingDirDB()) ;