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/06/30 18:10:44 UTC
svn commit: r1141598 - in /incubator/jena/Experimental/TxTDB/trunk:
src-dev/tx/ src/main/java/com/hp/hpl/jena/tdb/base/objectfile/
src/main/java/com/hp/hpl/jena/tdb/index/
src/main/java/com/hp/hpl/jena/tdb/lib/
src/main/java/com/hp/hpl/jena/tdb/setup/ ...
Author: andy
Date: Thu Jun 30 16:10:43 2011
New Revision: 1141598
URL: http://svn.apache.org/viewvc?rev=1141598&view=rev
Log: (empty)
Added:
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/IndexMap.java (with props)
incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/TestIndexMem.java (with props)
Modified:
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/AbstractTestNodeTableTrans.java
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/NodeTableTrans.java
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestNodeTableTrans.java
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TxMain.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/lib/NodeLib.java
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/setup/DatasetBuilderStd.java
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetBuilderTxn.java
incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/TestIndex.java
incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/ext/TestExtHash.java
Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/AbstractTestNodeTableTrans.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/AbstractTestNodeTableTrans.java?rev=1141598&r1=1141597&r2=1141598&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/AbstractTestNodeTableTrans.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/AbstractTestNodeTableTrans.java Thu Jun 30 16:10:43 2011
@@ -18,22 +18,82 @@
package tx;
+import org.junit.Test ;
+import org.openjena.atlas.junit.BaseTest ;
+
import com.hp.hpl.jena.graph.Node ;
import com.hp.hpl.jena.sparql.util.NodeFactory ;
+import com.hp.hpl.jena.tdb.junit.Base_TS ;
+import com.hp.hpl.jena.tdb.nodetable.NodeTable ;
+import com.hp.hpl.jena.tdb.store.NodeId ;
+import com.hp.hpl.jena.tdb.transaction.Transaction ;
-import org.junit.Test ;
-
-public abstract class AbstractTestNodeTableTrans
+public abstract class AbstractTestNodeTableTrans extends BaseTest
{
- abstract protected NodeTableTrans getEmpty() ;
+ abstract protected NodeTableTrans create(Node... nodes) ;
protected static Node node1 = NodeFactory.parseNode("<x>") ;
protected static Node node2 = NodeFactory.parseNode("<y>") ;
+
+ static void contains(NodeTable nt, Node...nodes)
+ {
+ for ( Node n : nodes)
+ {
+ NodeId nodeId = nt.getNodeIdForNode(n) ;
+ assertFalse(NodeId.doesNotExist(nodeId)) ;
+ }
+ }
- @Test public void test()
+ @Test public void nodetrans_01()
{
-
+ NodeTableTrans ntt = create() ;
+ Transaction txn = new Transaction(11, null) ;
+ ntt.begin(txn) ;
+ ntt.abort(txn) ;
}
+
+ @Test public void nodetrans_02()
+ {
+ NodeTableTrans ntt = create() ;
+ NodeTable nt0 = ntt.getBaseNodeTable() ;
+
+ Transaction txn = new Transaction(11, null) ;
+ ntt.begin(txn) ;
+ // Add a node
+ NodeId nodeId = ntt.getAllocateNodeId(node1) ;
+ // Check not in the base.
+ assertNull(nt0.getNodeForNodeId(nodeId)) ;
+ // Check is in the transaction node table.
+ assertEquals(NodeId.NodeDoesNotExist, nt0.getNodeIdForNode(node1)) ;
+ assertEquals(node1, ntt.getNodeForNodeId(nodeId)) ;
+
+ ntt.commit(txn) ;
+ // Check it is now in the base.
+ assertEquals(node1, nt0.getNodeForNodeId(nodeId)) ;
+ assertEquals(nodeId, nt0.getNodeIdForNode(node1)) ;
+ }
+
+ @Test public void nodetrans_03()
+ {
+ NodeTableTrans ntt = create() ;
+ NodeTable nt0 = ntt.getBaseNodeTable() ;
+
+ Transaction txn = new Transaction(11, null) ;
+ ntt.begin(txn) ;
+ // Add a node
+ NodeId nodeId = ntt.getAllocateNodeId(node1) ;
+ // Check not in the base.
+ assertEquals(NodeId.NodeDoesNotExist, nt0.getNodeIdForNode(node1)) ;
+ assertNull(nt0.getNodeForNodeId(nodeId)) ;
+ // Check is in the transaction node table.
+ assertEquals(node1, ntt.getNodeForNodeId(nodeId)) ;
+
+ ntt.abort(txn) ;
+ // Check it is not in the base.
+ assertEquals(NodeId.NodeDoesNotExist, nt0.getNodeIdForNode(node1)) ;
+ assertNull(nt0.getNodeForNodeId(nodeId)) ;
+ }
+
}
Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/NodeTableTrans.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/NodeTableTrans.java?rev=1141598&r1=1141597&r2=1141598&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/NodeTableTrans.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/NodeTableTrans.java Thu Jun 30 16:10:43 2011
@@ -29,35 +29,40 @@ import com.hp.hpl.jena.tdb.base.objectfi
import com.hp.hpl.jena.tdb.index.Index ;
import com.hp.hpl.jena.tdb.nodetable.NodeTable ;
import com.hp.hpl.jena.tdb.nodetable.NodeTableCache ;
+import com.hp.hpl.jena.tdb.nodetable.NodeTableInline ;
import com.hp.hpl.jena.tdb.nodetable.NodeTableNative ;
import com.hp.hpl.jena.tdb.store.NodeId ;
+import com.hp.hpl.jena.tdb.transaction.TDBTransactionException ;
import com.hp.hpl.jena.tdb.transaction.Transaction ;
import com.hp.hpl.jena.tdb.transaction.Transactional ;
public class NodeTableTrans implements NodeTable, Transactional
{
private final NodeTable base ;
- private final long offset ;
- private final ObjectFile journal ;
+ private long offset ;
private NodeTable nodeTableJournal ;
private static int CacheSize = 10000 ;
private boolean passthrough = false ;
+ private boolean inTransaction = false ;
+
+ private final Index nodeIndex ;
+ private final ObjectFile journal ;
- public NodeTableTrans(Transaction txn, NodeTable sub, long offset, Index tmpIndex, ObjectFile journal)
+ public NodeTableTrans(Transaction txn, NodeTable sub, Index nodeIndex, ObjectFile journal)
{
this.base = sub ;
- this.offset = offset ;
+
+ this.nodeIndex = nodeIndex ;
this.journal = journal ;
- // This is a temporary file, and does not itself need to be transactional.
- // It's used to scale the transactional node table.
- // We need direct access to the ObjectFile for reply after crash.
-
- this.nodeTableJournal = new NodeTableNative(tmpIndex, journal) ;
- this.nodeTableJournal = NodeTableCache.create(nodeTableJournal, CacheSize, CacheSize) ;
+// this.nodeTableJournal = new NodeTableNative(tmpIndex, journal) ;
+// this.nodeTableJournal = NodeTableCache.create(nodeTableJournal, CacheSize, CacheSize) ;
+// // Do not add the inline NodeTable here - don't convert it's values by the offset!
}
- public void setPassthrough(boolean v) { passthrough = v ; }
+ public void setPassthrough(boolean v) { passthrough = v ; }
+ public NodeTable getBaseNodeTable() { return base ; }
+ public NodeTable getJournalTable() { return nodeTableJournal ; }
@Override
public NodeId getAllocateNodeId(Node node)
@@ -118,7 +123,18 @@ public class NodeTableTrans implements N
public void begin(Transaction txn)
{
passthrough = false ;
-// inTransaction = true ;
+ inTransaction = true ;
+ offset = (int)base.allocOffset().getId() ;
+ // Fast-ish clearing of the file.
+ nodeIndex.clear() ;
+ journal.reposition(0) ;
+
+ this.nodeTableJournal = new NodeTableNative(nodeIndex, journal) ;
+ this.nodeTableJournal = NodeTableCache.create(nodeTableJournal, CacheSize, CacheSize) ;
+ // Do not add the inline NodeTable here - don't convert it's values by the offset!
+
+
+ // Setup.
// journal.position(0) ;
// this.otherAllocOffset = journal.length() ;
}
@@ -142,12 +158,12 @@ public class NodeTableTrans implements N
@Override
public void commit(Transaction txn)
{
-// if ( ! inTransaction )
-// throw new TDBTransactionException("Not in a transaction for a commit to happen") ;
-// append() ;
-// base.sync() ;
-// other.reposition(0) ;
-// passthrough = true ;
+ if ( ! inTransaction )
+ throw new TDBTransactionException("Not in a transaction for a commit to happen") ;
+ append() ;
+ base.sync() ;
+ //other.reposition(0) ;
+ passthrough = true ;
}
@Override
Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestNodeTableTrans.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestNodeTableTrans.java?rev=1141598&r1=1141597&r2=1141598&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestNodeTableTrans.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestNodeTableTrans.java Thu Jun 30 16:10:43 2011
@@ -18,14 +18,34 @@
package tx;
+import com.hp.hpl.jena.graph.Node ;
+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 ;
+import com.hp.hpl.jena.tdb.base.record.RecordFactory ;
+import com.hp.hpl.jena.tdb.index.Index ;
+import com.hp.hpl.jena.tdb.index.IndexMap ;
+import com.hp.hpl.jena.tdb.nodetable.NodeTable ;
+import com.hp.hpl.jena.tdb.nodetable.NodeTableNative ;
+import com.hp.hpl.jena.tdb.sys.SystemTDB ;
+
public class TestNodeTableTrans extends AbstractTestNodeTableTrans
{
@Override
- protected NodeTableTrans getEmpty()
+ protected NodeTableTrans create(Node...nodes)
{
- return null ;
- }
+ RecordFactory recordFactory = new RecordFactory(SystemTDB.LenNodeHash, SystemTDB.SizeOfNodeId) ;
+
+ NodeTable base = new NodeTableNative(new IndexMap(recordFactory), new ObjectFileMem()) ;
+ for ( Node n : nodes )
+ base.getAllocateNodeId(n) ;
+ // Set up the transaction table.
+ Index idx = new IndexMap(recordFactory) ;
+ ObjectFile objectFile = FileFactory.createObjectFileMem() ;
+ NodeTableTrans ntt = new NodeTableTrans(null, base, idx, objectFile) ;
+ return ntt ;
+ }
}
Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TxMain.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TxMain.java?rev=1141598&r1=1141597&r2=1141598&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TxMain.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TxMain.java Thu Jun 30 16:10:43 2011
@@ -18,7 +18,6 @@ import com.hp.hpl.jena.query.QueryExecut
import com.hp.hpl.jena.query.QueryExecutionFactory ;
import com.hp.hpl.jena.query.QueryFactory ;
import com.hp.hpl.jena.query.Syntax ;
-import com.hp.hpl.jena.query.larq.IndexBuilder ;
import com.hp.hpl.jena.rdf.model.Model ;
import com.hp.hpl.jena.rdf.model.ModelFactory ;
import com.hp.hpl.jena.sparql.core.DatasetGraph ;
@@ -34,6 +33,7 @@ import com.hp.hpl.jena.tdb.base.objectfi
import com.hp.hpl.jena.tdb.base.record.Record ;
import com.hp.hpl.jena.tdb.base.record.RecordFactory ;
import com.hp.hpl.jena.tdb.index.Index ;
+import com.hp.hpl.jena.tdb.index.IndexMap ;
import com.hp.hpl.jena.tdb.index.TupleIndex ;
import com.hp.hpl.jena.tdb.index.bplustree.BPlusTree ;
import com.hp.hpl.jena.tdb.nodetable.NodeTable ;
@@ -42,7 +42,6 @@ import com.hp.hpl.jena.tdb.nodetable.Nod
import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
import com.hp.hpl.jena.tdb.store.DatasetPrefixesTDB ;
import com.hp.hpl.jena.tdb.store.NodeId ;
-import com.hp.hpl.jena.tdb.sys.Names ;
import com.hp.hpl.jena.tdb.sys.SystemTDB ;
import com.hp.hpl.jena.tdb.transaction.DatasetGraphTxnTDB ;
import com.hp.hpl.jena.tdb.transaction.TransactionManager ;
@@ -75,9 +74,8 @@ public class TxMain
{
execNT() ; exit(0) ;
-
-
- if ( false ) SystemTDB.setFileMode(FileMode.direct) ;
+ if ( false )
+ SystemTDB.setFileMode(FileMode.direct) ;
initFS() ;
DatasetGraphTDB dsg0 = build() ;
@@ -125,9 +123,12 @@ public class TxMain
FileOps.clearDirectory(dir) ;
DatasetGraphTDB dsg = TDBFactory.createDatasetGraph(dir) ;
- BPlusTree index = BPlusTree.makeMem(20, 20, SystemTDB.LenNodeHash, SystemTDB.SizeOfNodeId) ;
+
+// BPlusTree index = BPlusTree.makeMem(20, 20, SystemTDB.LenNodeHash, SystemTDB.SizeOfNodeId) ;
RecordFactory recordFactory = new RecordFactory(SystemTDB.LenNodeHash, SystemTDB.SizeOfNodeId) ;
- Index idx = index ;
+// Index idx = index ;
+ Index idx = new IndexMap(recordFactory) ;
+
//ObjectFile objectFile = FileFactory.createObjectFileMem() ;
ObjectFile objectFile = FileFactory.createObjectFileDisk("DB/N.jrnl") ;
NodeTable nt0 = dsg.getTripleTable().getNodeTupleTable().getNodeTable() ;
@@ -137,16 +138,18 @@ public class TxMain
NodeId id_1 = nt0.getAllocateNodeId(node1) ;
// Set up the trans table.
- int offset = (int)nt0.allocOffset().getId() ;
- System.out.println("Offset = "+offset) ;
- NodeTableTrans ntt = new NodeTableTrans(null, nt0, offset, idx, objectFile) ;
+ NodeTableTrans ntt = new NodeTableTrans(null, nt0, idx, objectFile) ;
NodeTable nt = NodeTableInline.create(ntt) ;
+ ntt.begin(null) ;
+
Node node2 = NodeFactory.parseNode("<y>") ;
NodeId id_2 = nt.getAllocateNodeId(node2) ;
System.out.println("==> "+id_2) ;
Node node3 = NodeFactory.parseNode("123") ;
+// n = nt.getNodeForNodeId(id_2) ;
+// System.out.println("2: ==> "+n) ;
NodeId id_3 = nt.getAllocateNodeId(node3) ;
System.out.println("==> "+id_3) ;
@@ -160,12 +163,25 @@ public class TxMain
NodeId x = nt.getNodeIdForNode(node2) ;
System.out.println("==> "+x) ;
+ System.out.println("---- Txn") ;
+ System.out.println("Base: "+nt0.getNodeIdForNode(node1)) ;
+ System.out.println("Trans: "+nt.getNodeIdForNode(node1)) ;
+ System.out.println("Base: "+nt0.getNodeIdForNode(node2)) ;
+ System.out.println("Trans: "+nt.getNodeIdForNode(node2)) ;
+ System.out.println("Base: "+nt0.getNodeIdForNode(node3)) ;
+ System.out.println("Trans: "+nt.getNodeIdForNode(node3)) ;
+
+ ntt.commit(null) ;
+
+ System.out.println("---- Commit") ;
System.out.println("Base: "+nt0.getNodeIdForNode(node1)) ;
System.out.println("Trans: "+nt.getNodeIdForNode(node1)) ;
System.out.println("Base: "+nt0.getNodeIdForNode(node2)) ;
System.out.println("Trans: "+nt.getNodeIdForNode(node2)) ;
System.out.println("Base: "+nt0.getNodeIdForNode(node3)) ;
System.out.println("Trans: "+nt.getNodeIdForNode(node3)) ;
+
+
}
private static void deconstruct(DatasetGraphTDB dsg)
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=1141598&r1=1141597&r2=1141598&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 Thu Jun 30 16:10:43 2011
@@ -54,7 +54,7 @@ public class ObjectFileMem implements Ob
public ByteBuffer read(long id)
{
if ( id < 0 || id >= buffers.size() )
- throw new IllegalArgumentException("Id "+id+" not in range [0, "+buffers.size()+"]") ;
+ return null ;
if ( closed )
throw new IllegalStateException("Closed") ;
Added: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/IndexMap.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/IndexMap.java?rev=1141598&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/IndexMap.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/IndexMap.java Thu Jun 30 16:10:43 2011
@@ -0,0 +1,173 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.hp.hpl.jena.tdb.index;
+
+import java.util.Arrays ;
+import java.util.HashMap ;
+import java.util.Iterator ;
+import java.util.Map ;
+
+import org.openjena.atlas.lib.Bytes ;
+
+import com.hp.hpl.jena.tdb.base.record.Record ;
+import com.hp.hpl.jena.tdb.base.record.RecordFactory ;
+
+public class IndexMap implements Index
+{
+ private final Map<ByteArray, ByteArray> index = new HashMap<ByteArray, ByteArray>() ;
+ private final RecordFactory recordFactory ;
+
+ public IndexMap(RecordFactory recordFactory)
+ {
+ this.recordFactory = recordFactory ;
+ }
+
+ @Override
+ public Record find(Record record)
+ {
+ ByteArray k = wrap(record.getKey()) ;
+ ByteArray v = index.get(k) ;
+ if ( v == null )
+ return null ;
+ return record(k, v) ;
+ }
+
+ @Override
+ public boolean contains(Record record)
+ {
+ Record r = find(record) ;
+ if ( r == null )
+ return false ;
+ if ( ! recordFactory.hasValue() )
+ return true ;
+ return Bytes.compare(record.getValue(), r.getValue()) == 0 ;
+ }
+
+ @Override
+ public boolean add(Record record)
+ {
+ Record r = find(record) ;
+ if ( r != null && r.equals(record) )
+ return false ;
+ index.put(wrap(record.getKey()), wrap(record.getValue())) ;
+ return true ;
+ }
+
+ @Override
+ public boolean delete(Record record)
+ {
+ ByteArray x = index.remove(wrap(record.getKey())) ;
+ if ( x == null )
+ return false ;
+ return true ;
+ }
+
+ @Override
+ public Iterator<Record> iterator()
+ {
+ return new Iterator<Record>() {
+
+ Iterator<Map.Entry<ByteArray, ByteArray>> iter = index.entrySet().iterator() ;
+
+ @Override
+ public boolean hasNext()
+ {
+ return iter.hasNext() ;
+ }
+
+ @Override
+ public Record next()
+ {
+ Map.Entry<ByteArray, ByteArray> e = iter.next() ;
+ return record(e.getKey(), e.getValue()) ;
+ }
+
+ @Override
+ public void remove()
+ { throw new UnsupportedOperationException() ;}
+ } ;
+
+ }
+
+ @Override
+ public RecordFactory getRecordFactory()
+ {
+ return recordFactory ;
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ return index.isEmpty() ;
+ }
+
+ @Override
+ public void clear()
+ {
+ index.clear() ;
+ }
+
+ @Override
+ public void check()
+ {}
+
+ @Override
+ public long size()
+ {
+ return index.size() ;
+ }
+
+ @Override
+ public void sync()
+ {}
+
+ @Override
+ public void close()
+ {}
+
+ private static ByteArray wrap(byte[] b) { return new ByteArray(b) ; }
+ private Record record(ByteArray k, ByteArray v) { return recordFactory.create(k.bytes, v.bytes) ; }
+
+ private static class ByteArray
+ {
+ byte[] bytes ;
+ ByteArray(byte[] bytes) { this.bytes = bytes ; }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31 ;
+ int result = 1 ;
+ result = prime * result + Arrays.hashCode(bytes) ;
+ return result ;
+ }
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj) return true ;
+ if (obj == null) return false ;
+ if (getClass() != obj.getClass()) return false ;
+ ByteArray other = (ByteArray)obj ;
+ if (!Arrays.equals(bytes, other.bytes)) return false ;
+ return true ;
+ }
+ }
+
+}
+
Propchange: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/IndexMap.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/lib/NodeLib.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/lib/NodeLib.java?rev=1141598&r1=1141597&r2=1141598&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/lib/NodeLib.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/lib/NodeLib.java Thu Jun 30 16:10:43 2011
@@ -58,6 +58,8 @@ public class NodeLib
public static Node fetchDecode(long id, ObjectFile file)
{
ByteBuffer bb = file.read(id) ;
+ if ( bb == null )
+ return null ;
return decode(bb) ;
}
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/setup/DatasetBuilderStd.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/setup/DatasetBuilderStd.java?rev=1141598&r1=1141597&r2=1141598&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/setup/DatasetBuilderStd.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/setup/DatasetBuilderStd.java Thu Jun 30 16:10:43 2011
@@ -6,7 +6,6 @@
package com.hp.hpl.jena.tdb.setup;
-
import java.util.Properties ;
import org.openjena.atlas.lib.ColumnMap ;
@@ -23,8 +22,6 @@ import com.hp.hpl.jena.tdb.base.file.Met
import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
import com.hp.hpl.jena.tdb.index.TupleIndex ;
import com.hp.hpl.jena.tdb.nodetable.NodeTable ;
-import com.hp.hpl.jena.tdb.nodetable.NodeTupleTable ;
-import com.hp.hpl.jena.tdb.nodetable.NodeTupleTableConcrete ;
import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
import com.hp.hpl.jena.tdb.store.DatasetPrefixesTDB ;
import com.hp.hpl.jena.tdb.store.NodeId ;
@@ -250,16 +247,16 @@ public class DatasetBuilderStd implement
// ======== Components level
- // This is not actually used in main dataset builder because it's done inside TripleTable/QuadTable.
- protected NodeTupleTable makeNodeTupleTable(Location location, String primary, String[] indexes, NodeTable nodeTable, ConcurrencyPolicy policy)
- {
- int N = indexes.length ;
- TupleIndex tripleIndexes[] = makeTupleIndexes(location, primary, indexes) ;
- if ( tripleIndexes.length != indexes.length )
- error(log, "Wrong number of node table tuples indexes: expected="+N+" : actual="+tripleIndexes.length) ;
- NodeTupleTable ntt = new NodeTupleTableConcrete(N, tripleIndexes, nodeTable, policy) ;
- return ntt ;
- }
+// // This is not actually used in main dataset builder because it's done inside TripleTable/QuadTable.
+// protected NodeTupleTable makeNodeTupleTable(Location location, String primary, String[] indexes, NodeTable nodeTable, ConcurrencyPolicy policy)
+// {
+// int N = indexes.length ;
+// TupleIndex tripleIndexes[] = makeTupleIndexes(location, primary, indexes) ;
+// if ( tripleIndexes.length != indexes.length )
+// error(log, "Wrong number of node table tuples indexes: expected="+N+" : actual="+tripleIndexes.length) ;
+// NodeTupleTable ntt = new NodeTupleTableConcrete(N, tripleIndexes, nodeTable, policy) ;
+// return ntt ;
+// }
private TupleIndex[] makeTupleIndexes(Location location, String primary, String[] indexNames)
{
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetBuilderTxn.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetBuilderTxn.java?rev=1141598&r1=1141597&r2=1141598&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetBuilderTxn.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetBuilderTxn.java Thu Jun 30 16:10:43 2011
@@ -12,6 +12,7 @@ import java.util.Properties ;
import org.openjena.atlas.lib.FileOps ;
import org.openjena.atlas.logging.Log ;
+import tx.NodeTableTrans ;
import com.hp.hpl.jena.sparql.core.DatasetPrefixStorage ;
import com.hp.hpl.jena.tdb.base.block.BlockMgr ;
@@ -24,6 +25,9 @@ import com.hp.hpl.jena.tdb.base.file.Fil
import com.hp.hpl.jena.tdb.base.file.Location ;
import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
import com.hp.hpl.jena.tdb.base.objectfile.ObjectFileLogger ;
+import com.hp.hpl.jena.tdb.base.record.RecordFactory ;
+import com.hp.hpl.jena.tdb.index.Index ;
+import com.hp.hpl.jena.tdb.index.IndexMap ;
import com.hp.hpl.jena.tdb.nodetable.NodeTable ;
import com.hp.hpl.jena.tdb.nodetable.NodeTableLogger ;
import com.hp.hpl.jena.tdb.setup.BlockMgrBuilder ;
@@ -38,6 +42,7 @@ import com.hp.hpl.jena.tdb.store.Dataset
import com.hp.hpl.jena.tdb.store.DatasetPrefixStorageLogger ;
import com.hp.hpl.jena.tdb.sys.ConcurrencyPolicy ;
import com.hp.hpl.jena.tdb.sys.FileRef ;
+import com.hp.hpl.jena.tdb.sys.SystemTDB ;
public class DatasetBuilderTxn extends DatasetBuilderStd
{
@@ -75,7 +80,6 @@ public class DatasetBuilderTxn extends D
ObjectFileBuilder objectFileBuilder = new ObjectFileBuilderTx() ;
BlockMgrBuilder blockMgrBuilder = new BlockMgrBuilderTx() ;
- // Add track(...) to log.
IndexBuilder indexBuilder = new Builder.IndexBuilderStd(blockMgrBuilder, blockMgrBuilder) ;
// Add logging to a BlockMgrBuilder (here, just the records par of the B+Tree
@@ -128,19 +132,36 @@ public class DatasetBuilderTxn extends D
return new DatasetGraphTxnTDB(dsg, txn) ;
}
+ // To SystemTDB
public static final String journalExt = "jrnl" ;
public static final String journalFilename = "journal" ;
+ public static final String nodeJournalFilename = "nodes" ;
private TransactionManager txnMgr ;
private Journal journal ;
private Transaction txn ;
private Location location ;
private Map<FileRef, BlockMgr> blockMgrs = new HashMap<FileRef, BlockMgr>() ;
-
-
- // *** TODO NodTbale has cachign over this ==> broken.
private Map<FileRef, ObjectFile> objectFile = new HashMap<FileRef, ObjectFile>() ;
+
+ @Override
+ protected NodeTable makeNodeTable(Location location, String indexNode2Id, String indexId2Node,
+ int sizeNode2NodeIdCache, int sizeNodeId2NodeCache)
+ {
+ // GET FROM DATASET
+ NodeTable nt = super.makeNodeTable(location, indexNode2Id, indexId2Node, sizeNode2NodeIdCache, sizeNodeId2NodeCache) ;
+
+ RecordFactory recordFactory = new RecordFactory(SystemTDB.LenNodeHash, SystemTDB.SizeOfNodeId) ;
+ Index idx = new IndexMap(recordFactory) ; // In-memory
+ ObjectFile objFile = FileFactory.createObjectFileDisk(location.absolute(nodeJournalFilename, journalExt)) ;
+ NodeTable nt0 = nt ;
+ NodeTableTrans ntt = new NodeTableTrans(null, nt0, idx, objFile) ;
+ // Remember ntt.
+ return nt ;
+
+ }
+
class ObjectFileBuilderTx implements ObjectFileBuilder
{
ObjectFileBuilder base = new Builder.ObjectFileBuilderStd() ;
Modified: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/TestIndex.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/TestIndex.java?rev=1141598&r1=1141597&r2=1141598&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/TestIndex.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/TestIndex.java Thu Jun 30 16:10:43 2011
@@ -30,7 +30,7 @@ public abstract class TestIndex extends
}
// ---- Overridable maker
- protected abstract Index makeIndex() ;
+ protected abstract Index makeIndex(int kLen, int vLen) ;
@Test public void index_ins_0()
{
@@ -95,7 +95,6 @@ public abstract class TestIndex extends
assertNull(r) ;
}
-
@Test public void index_del_1()
{
int[] keys1 = {0, 1, 2};
@@ -122,7 +121,7 @@ public abstract class TestIndex extends
private Index test(int[] insKeys, int[] delKeys, int[] expected)
{
- index = makeIndex() ;
+ index = makeIndex(4,0) ;
testInsert(index, insKeys) ;
long x = index.size() ;
if ( x >= 0 )
Added: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/TestIndexMem.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/TestIndexMem.java?rev=1141598&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/TestIndexMem.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/TestIndexMem.java Thu Jun 30 16:10:43 2011
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.hp.hpl.jena.tdb.index;
+
+import com.hp.hpl.jena.tdb.base.record.RecordFactory ;
+
+public class TestIndexMem extends TestIndex
+{
+ @Override
+ protected Index makeIndex(int kLen, int vLen)
+ {
+ RecordFactory rf = new RecordFactory(kLen, vLen) ;
+ return new IndexMap(rf) ;
+ }
+
+}
+
Propchange: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/TestIndexMem.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/ext/TestExtHash.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/ext/TestExtHash.java?rev=1141598&r1=1141597&r2=1141598&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/ext/TestExtHash.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/index/ext/TestExtHash.java Thu Jun 30 16:10:43 2011
@@ -1,5 +1,6 @@
/*
* (c) Copyright 2008, 2009 Hewlett-Packard Development Company, LP
+ * (c) Copyright 2011 Epimorphics Ltd.
* All rights reserved.
* [See end of file]
*/
@@ -38,9 +39,9 @@ public class TestExtHash extends TestInd
}
@Override
- protected Index makeIndex()
+ protected Index makeIndex(int kLen, int vLen)
{
- RecordFactory factory = new RecordFactory(4, 0) ;
+ RecordFactory factory = new RecordFactory(kLen, vLen) ;
BlockMgr mgr = BlockMgrFactory.createMem("EXT", 32) ;
ExtHash eHash = new ExtHash(new PlainFileMem(), factory, mgr) ;
return eHash ;
@@ -49,6 +50,7 @@ public class TestExtHash extends TestInd
/*
* (c) Copyright 2008, 2009 Hewlett-Packard Development Company, LP
+ * (c) Copyright 2011 Epimorphics Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without