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/27 17:07:59 UTC
svn commit: r1128348 - in /incubator/jena:
Experimental/TxTDB/trunk/src-dev/tx/
Experimental/TxTDB/trunk/src-dev/tx/journal/
Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/block/
Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/t...
Author: andy
Date: Fri May 27 15:07:58 2011
New Revision: 1128348
URL: http://svn.apache.org/viewvc?rev=1128348&view=rev
Log: (empty)
Added:
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/NodeTableJournal.java (with props)
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Replay.java (with props)
Modified:
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/Journal.java
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/block/Block.java
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/tokens/Token.java
Added: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/NodeTableJournal.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/NodeTableJournal.java?rev=1128348&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/NodeTableJournal.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/NodeTableJournal.java Fri May 27 15:07:58 2011
@@ -0,0 +1,115 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package tx;
+
+import java.util.HashMap ;
+import java.util.Iterator ;
+import java.util.Map ;
+import java.util.Map.Entry ;
+
+import org.openjena.atlas.iterator.Iter ;
+import org.openjena.atlas.iterator.IteratorConcat ;
+import org.openjena.atlas.iterator.Transform ;
+import org.openjena.atlas.lib.Pair ;
+import tx.journal.Journal ;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.tdb.nodetable.NodeTable ;
+import com.hp.hpl.jena.tdb.store.NodeId ;
+
+public class NodeTableJournal implements NodeTable
+{
+ private final Journal journal ;
+ private final NodeTable other ;
+
+ // Node we have.
+ private Map<NodeId, Node> nodeId2Node = new HashMap<NodeId, Node>() ;
+ private Map<Node, NodeId> node2NodeId = new HashMap<Node, NodeId>() ;
+
+ public NodeTableJournal(Journal journal, NodeTable sub)
+ {
+ this.journal = journal ;
+ this.other = sub ;
+ }
+
+ // Low level interface for "pre allocation"
+ // Life would be easier if ids were increments.
+
+ // OR do everything but write - return (id,bytes) that would be written (sans length)
+
+ @Override
+ public NodeId getAllocateNodeId(Node node)
+ {
+ return null ;
+ }
+
+ @Override
+ public NodeId getNodeIdForNode(Node node)
+ {
+ NodeId nodeId = node2NodeId.get(node) ;
+ if ( nodeId != null )
+ return nodeId ;
+ return other.getNodeIdForNode(node) ;
+ }
+
+ @Override
+ public Node getNodeForNodeId(NodeId id)
+ {
+ Node node = nodeId2Node.get(id) ;
+ if ( node != null )
+ return node ;
+ return other.getNodeForNodeId(id) ;
+ }
+
+ @Override
+ public Iterator<Pair<NodeId, Node>> all()
+ {
+ Iterator<Pair<NodeId, Node>> iter1 =
+ Iter.map(nodeId2Node.entrySet().iterator(), new Transform<Map.Entry<NodeId, Node>,Pair<NodeId, Node>>(){
+ @Override
+ public Pair<NodeId, Node> convert(Entry<NodeId, Node> item)
+ {
+ return new Pair<NodeId, Node>(item.getKey(), item.getValue()) ;
+ }}) ;
+ return IteratorConcat.concat(iter1, other.all()) ;
+ }
+
+ // Read-only with repect to the underlying NodeTable
+
+ @Override
+ public void sync() { }
+
+ @Override
+ public void close() { }
+}
+
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
\ No newline at end of file
Propchange: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/NodeTableJournal.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Replay.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Replay.java?rev=1128348&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Replay.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Replay.java Fri May 27 15:07:58 2011
@@ -0,0 +1,70 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package tx;
+//import static tx.journal.JournalEntryType.* ;
+
+import java.nio.ByteBuffer ;
+
+import tx.journal.Journal ;
+import tx.journal.JournalEntry ;
+
+public class Replay
+{
+ public static void reply(Journal journal)
+ {
+ for ( JournalEntry e : journal )
+ {
+ ByteBuffer bb = e.getByteBuffer() ;
+ switch (e.getType())
+ {
+ case Block:
+ // Get block ref.
+ // Find block mgr
+ // do it.
+ break ;
+ case Object:
+ // Get id
+ // get bytes
+ // dispatch to NodeTable.
+ // ?? Node rebuilding?
+ // Check ids.
+ break ;
+ case Commit:
+ break ;
+ case Checkpoint:
+ //default:
+ }
+ }
+ }
+}
+
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
\ No newline at end of file
Propchange: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Replay.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/Journal.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/Journal.java?rev=1128348&r1=1128347&r2=1128348&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/Journal.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/Journal.java Fri May 27 15:07:58 2011
@@ -24,7 +24,6 @@ class Journal implements Iterable<Journa
{
// Version 1 : issue might be excessive copying
// [TxTDB:TODO] Caching
- // [TxTDB:TODO] Assumes we're writing blocks (fileId, blockId)
// Why synchronized?
// Object handling - avoid length twice.
@@ -55,16 +54,15 @@ class Journal implements Iterable<Journa
public long writeJournal(JournalEntryType type, ByteBuffer buffer)
{
long posn = position ;
- // (type, length), bytes [0,limit())
// [TxDEV:TODO] CRC
- buffer.rewind() ;
- int len = buffer.limit() ;
+ // ?? buffer.position(0) ;
+ int len = buffer.remaining() ;
header.clear() ;
header.putInt(type.id) ;
header.putInt(len) ;
- header.rewind() ;
+ header.flip() ;
// switch (type)
// {
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/block/Block.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/block/Block.java?rev=1128348&r1=1128347&r2=1128348&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/block/Block.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/block/Block.java Fri May 27 15:07:58 2011
@@ -21,29 +21,33 @@ public final class Block
// Blocks for objects are addressed by long - this is file offset so 2G is not enough.
private final Long id ; // Keep as object. It's the cache key.
- private final boolean readOnly ;
- private final BlockRef blockRef ;
+ private BlockRef blockRef ;
+
+
+ // Information carrying these are not enforced.
+ private boolean readOnly = false ;
private boolean modified = false ;
private final ByteBuffer byteBuffer ;
-// private BlockType type ;
+ // If the byteBuffer is, say, a slice of another one,
+ // this can be used to carry a ref to the real ByteBuffer.
+ private ByteBuffer underlyingByteBuffer ;
public Block(long id, ByteBuffer byteBuffer)
{
this(Long.valueOf(id), byteBuffer) ;
}
-
public Block(Long id, ByteBuffer byteBuffer)
{
// ByteBuffer is whole disk space from byte 0 for this disk unit.
this.id = id ;
this.byteBuffer = byteBuffer ;
- //this.type = BlockType.UNDEF ;
this.blockRef = null ;
+
this.readOnly = false ;
- // Initially a block is not modified.
this.modified = false ;
+ this.underlyingByteBuffer = null ;
}
@@ -61,15 +65,15 @@ public final class Block
return byteBuffer ;
}
- public boolean isReadOnly()
- {
- return readOnly ;
- }
-
- public boolean isModified()
+ public boolean isReadOnly() { return readOnly ; }
+ public void setReadOnly(boolean readonly)
{
- return modified ;
+ if ( readonly && modified )
+ throw new BlockException("Attempt to mark a modified block as read-only") ;
+ this.readOnly = readonly ;
}
+
+ public boolean isModified() { return modified ; }
public void setModified(boolean modified)
{
@@ -78,20 +82,14 @@ public final class Block
this.modified = modified ;
}
- public BlockRef getFileRef()
- {
- return blockRef ;
- }
+ public BlockRef getBlockRef() { return blockRef ; }
+
+ public ByteBuffer getUnderlyingByteBuffer()
+ { return underlyingByteBuffer ; }
+
-// public void setType(BlockType blockType)
-// {
-// type = blockType ;
-// }
-//
-// public BlockType getType()
-// {
-// return type ;
-// }
+ public void setUnderlyingByteBuffer(ByteBuffer underlyingByteBuffer)
+ { this.underlyingByteBuffer = underlyingByteBuffer ; }
@Override
public String toString()
@@ -100,10 +98,14 @@ public final class Block
return String.format("Block: %d : (posn=%d, limit=%d, cap=%d)", id, bb.position(), bb.limit(), bb.capacity()) ;
}
+ /** Deep copy, including ByteBuffer contents. */
public Block replicate()
{
ByteBuffer dstBuffer = replicate(getByteBuffer()) ;
Block b = new Block(getId(), dstBuffer) ;
+ b.modified = modified ;
+ b.readOnly = readOnly ;
+ b.blockRef = null ;
return b ;
}
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=1128348&r1=1128347&r2=1128348&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 Fri May 27 15:07:58 2011
@@ -124,7 +124,7 @@ public class ObjectFileStorage implement
// Slice it.
writeBuffer.position(start + SizeOfInt) ;
writeBuffer.limit(start+spaceRequired) ;
- ByteBuffer bb = writeBuffer.slice() ;
+ ByteBuffer bb = writeBuffer.slice() ;
allocBlock = new Block(allocLocation, bb) ;
return allocBlock ;
Modified: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/tokens/Token.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/tokens/Token.java?rev=1128348&r1=1128347&r2=1128348&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/tokens/Token.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/tokens/Token.java Fri May 27 15:07:58 2011
@@ -62,13 +62,13 @@ public final class Token
public final int getCntrlCode() { return cntrlCode ; }
public final Token getSubToken() { return subToken ; }
- public final Token setType(TokenType tokenType) { this.tokenType = tokenType ; return this ; }
- public final Token setImage(String tokenImage) { this.tokenImage = tokenImage ; return this ; }
- public final Token setImage(char tokenImage) { this.tokenImage = String.valueOf(tokenImage) ; return this ; }
+ public final Token setType(TokenType tokenType) { this.tokenType = tokenType ; return this ; }
+ public final Token setImage(String tokenImage) { this.tokenImage = tokenImage ; return this ; }
+ public final Token setImage(char tokenImage) { this.tokenImage = String.valueOf(tokenImage) ; return this ; }
//public final Token setImage1(String tokenImage1) { this.tokenImage1 = tokenImage1 ; return this ; }
- public final Token setImage2(String tokenImage2) { this.tokenImage2 = tokenImage2 ; return this ; }
- public final Token setCntrlCode(int cntrlCode) { this.cntrlCode = cntrlCode ; return this ; }
- public final Token setSubToken(Token subToken) { this.subToken = subToken ; return this ; }
+ public final Token setImage2(String tokenImage2) { this.tokenImage2 = tokenImage2 ; return this ; }
+ public final Token setCntrlCode(int cntrlCode) { this.cntrlCode = cntrlCode ; return this ; }
+ public final Token setSubToken(Token subToken) { this.subToken = subToken ; return this ; }
static Token create(String s)
{