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 2012/06/10 19:15:16 UTC
svn commit: r1348627 - in /jena/Scratch/AFS/Jena-Dev/trunk/src: dev/Run.java
tx/GraphTDBTransactionHandler.java tx/NodeTableTrans99.java
Author: andy
Date: Sun Jun 10 17:15:15 2012
New Revision: 1348627
URL: http://svn.apache.org/viewvc?rev=1348627&view=rev
Log: (empty)
Added:
jena/Scratch/AFS/Jena-Dev/trunk/src/tx/NodeTableTrans99.java
Removed:
jena/Scratch/AFS/Jena-Dev/trunk/src/tx/GraphTDBTransactionHandler.java
Modified:
jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java
Modified: jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java?rev=1348627&r1=1348626&r2=1348627&view=diff
==============================================================================
--- jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java (original)
+++ jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java Sun Jun 10 17:15:15 2012
@@ -21,30 +21,38 @@ package dev;
import java.io.File ;
import java.io.FileInputStream ;
import java.io.InputStream ;
-import java.nio.ByteBuffer ;
-import java.util.UUID ;
-import org.openjena.atlas.lib.Bytes ;
-import org.openjena.atlas.lib.FileOps ;
-import org.openjena.atlas.lib.Lib ;
import org.openjena.atlas.logging.Log ;
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.query.* ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.query.ReadWrite ;
import com.hp.hpl.jena.rdf.model.Model ;
import com.hp.hpl.jena.rdf.model.RDFReader ;
-import com.hp.hpl.jena.sparql.core.DatasetGraph ;
import com.hp.hpl.jena.sparql.core.Quad ;
-import com.hp.hpl.jena.sparql.mgt.Explain.InfoLevel ;
import com.hp.hpl.jena.sparql.sse.SSE ;
-import com.hp.hpl.jena.sparql.util.Timer ;
-import com.hp.hpl.jena.tdb.ConfigTest ;
import com.hp.hpl.jena.tdb.StoreConnection ;
-import com.hp.hpl.jena.tdb.TDB ;
+import com.hp.hpl.jena.tdb.TDBException ;
import com.hp.hpl.jena.tdb.TDBFactory ;
-import com.hp.hpl.jena.tdb.base.file.Location ;
+import com.hp.hpl.jena.tdb.base.file.FileFactory ;
+import com.hp.hpl.jena.tdb.base.file.FileSet ;
+import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
+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.NodeTableInline ;
+import com.hp.hpl.jena.tdb.nodetable.NodeTableWrapper ;
+import com.hp.hpl.jena.tdb.setup.NodeTableBuilder ;
+import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
+import com.hp.hpl.jena.tdb.store.NodeId ;
+import com.hp.hpl.jena.tdb.store.StoreConfig ;
+import com.hp.hpl.jena.tdb.sys.FileRef ;
+import com.hp.hpl.jena.tdb.sys.Names ;
+import com.hp.hpl.jena.tdb.sys.SystemTDB ;
import com.hp.hpl.jena.tdb.transaction.DatasetGraphTransaction ;
-import com.hp.hpl.jena.tdb.transaction.DatasetGraphTxn ;
+import com.hp.hpl.jena.tdb.transaction.NodeTableTrans ;
+import com.hp.hpl.jena.tdb.transaction.Transaction ;
public class Run extends RunBase
{
@@ -67,6 +75,18 @@ public class Run extends RunBase
// DatasetGraphTransaction ds = (DatasetGraphTransaction)TDBFactory.createDatasetGraph(DIR) ;
DatasetGraphTransaction ds = (DatasetGraphTransaction)TDBFactory.createDatasetGraph() ;
+ DatasetGraphTDB dsgTDB = ds.getBaseDatasetGraph() ;
+
+ StoreConfig config = dsgTDB.getConfig() ;
+ for ( FileRef fileRef : config.blockMgrs.keySet() )
+ System.out.println("BlkMgr -- "+fileRef) ;
+
+ for ( FileRef fileRef : config.nodeTables.keySet() )
+ System.out.println("nodetable -- "+fileRef) ;
+
+ System.exit(0) ;
+
+
ds.begin(ReadWrite.WRITE) ;
ds.add(q) ;
ds.commit() ;
@@ -91,5 +111,71 @@ public class Run extends RunBase
}
+
+ static class Outer
+ {
+ private DatasetGraphTDB dataset ;
+ private Transaction txn ;
+
+ Outer(DatasetGraphTDB dsg, Transaction txn) { dataset = dsg ; this.txn = txn ; }
+
+ class NodeTableBuilderTx implements NodeTableBuilder
+ {
+ @Override
+ public NodeTable buildNodeTable(FileSet fsIndex, FileSet fsObjectFile, int sizeNode2NodeIdCache,
+ int sizeNodeId2NodeCache, int sizeNodeMissCacheSize)
+ {
+ FileRef ref = FileRef.create(fsObjectFile.filename(Names.extNodeData)) ;
+
+ // ******* WRONG??? Should use:
+ //ObjectFileTrans
+ // +
+ //new Builder.NodeTableBuilderStd(IndexBuilder indexBuilder, ObjectFileBuilder objectFileBuilder) ;
+
+ //NodeTable ntBase = nodeTables.get(ref) ;
+ NodeTable ntBase = dataset.getConfig().nodeTables.get(ref) ;
+
+ if ( ntBase == null )
+ throw new TDBException("No NodeTable for "+ref) ;
+
+
+ RecordFactory recordFactory = new RecordFactory(SystemTDB.LenNodeHash, SystemTDB.SizeOfNodeId) ;
+ Index idx = new IndexMap(recordFactory) ;
+ String objFilename = fsObjectFile.filename(Names.extNodeData+"-"+Names.extJournal) ;
+ ObjectFile objectFile ;
+
+ if ( fsObjectFile.isMem() )
+ objectFile = FileFactory.createObjectFileMem(objFilename) ;
+ else
+ objectFile = FileFactory.createObjectFileDisk(objFilename) ;
+
+ NodeTableTrans ntt = new NodeTableTrans(txn ,fsObjectFile.getBasename(), ntBase, idx, objectFile) ;
+ txn.addComponent(ntt) ;
+
+ // Add inline wrapper.
+ NodeTable nt = NodeTableInline.create(ntt) ;
+ return nt ;
+ }
+ }
+ }
+
+ public static class NodeTableReadonly extends NodeTableWrapper
+ {
+ public NodeTableReadonly(NodeTable nodeTable)
+ {
+ super(nodeTable) ;
+ }
+
+ @Override
+ public NodeId getAllocateNodeId(Node node)
+ {
+ NodeId nodeId = getNodeIdForNode(node) ;
+ if ( NodeId.isDoesNotExist(nodeId) )
+ throw new TDBException("Allocation attempt on NodeTableReadonly") ;
+ return nodeId ;
+ }
+ }
+
+
}
Added: jena/Scratch/AFS/Jena-Dev/trunk/src/tx/NodeTableTrans99.java
URL: http://svn.apache.org/viewvc/jena/Scratch/AFS/Jena-Dev/trunk/src/tx/NodeTableTrans99.java?rev=1348627&view=auto
==============================================================================
--- jena/Scratch/AFS/Jena-Dev/trunk/src/tx/NodeTableTrans99.java (added)
+++ jena/Scratch/AFS/Jena-Dev/trunk/src/tx/NodeTableTrans99.java Sun Jun 10 17:15:15 2012
@@ -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 tx;
+
+import com.hp.hpl.jena.tdb.base.block.BlockMgr ;
+import com.hp.hpl.jena.tdb.base.file.FileSet ;
+import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
+import com.hp.hpl.jena.tdb.base.record.RecordFactory ;
+import com.hp.hpl.jena.tdb.index.Index ;
+import com.hp.hpl.jena.tdb.index.RangeIndex ;
+import com.hp.hpl.jena.tdb.index.bplustree.BPlusTree ;
+import com.hp.hpl.jena.tdb.index.bplustree.BPlusTreeParams ;
+import com.hp.hpl.jena.tdb.nodetable.NodeTable ;
+import com.hp.hpl.jena.tdb.nodetable.NodeTableNative ;
+import com.hp.hpl.jena.tdb.setup.BlockMgrBuilder ;
+import com.hp.hpl.jena.tdb.sys.FileRef ;
+import com.hp.hpl.jena.tdb.sys.Names ;
+import com.hp.hpl.jena.tdb.sys.SystemTDB ;
+import com.hp.hpl.jena.tdb.transaction.BlockMgrJournal ;
+import com.hp.hpl.jena.tdb.transaction.ObjectFileTrans ;
+import com.hp.hpl.jena.tdb.transaction.Transaction ;
+
+public class NodeTableTrans99 extends NodeTableNative
+{
+ /* The issue is the prepare step.
+ *
+ * ObjectFileTrans -- modify to have a read-only part from original NTT and an additional part.
+ * Index for new objects.
+ *
+ * Prepare
+ * Must do a transactional update of the base node table index file.
+ *
+ */
+
+ // Design :
+ // BlockMgr.getFileRef
+
+ // how to go from a BlockMgr to a BlockMgrTrans (Journal)?
+ // how to go from an ObjectFile to ObjectFileTrans?
+
+ static class BuilderTx
+ {
+ static BlockMgr buildBlockMgrTxn(Transaction txn, BlockMgr blockMgr)
+ {
+ FileRef ref = null ;
+ // ref for label.
+ BlockMgrJournal blkMgr = new BlockMgrJournal(txn, ref, blockMgr) ;
+ txn.addComponent(blkMgr) ;
+ return blkMgr ;
+ }
+
+ // Derived.
+
+
+ static Index buildIndexTxn(Transaction txn, Index index)
+ {
+ if ( ! ( index instanceof RangeIndex ) )
+ System.err.println("Not a range index") ;
+
+ return buildRangeIndexTxn(txn, (RangeIndex)index) ;
+ }
+
+ static RangeIndex buildRangeIndexTxn(Transaction txn, RangeIndex index)
+ {
+ if ( ! ( index instanceof BPlusTree ) )
+ System.err.println("Not a BPlusTree") ;
+
+ BPlusTree bpt = (BPlusTree)index ;
+
+ BlockMgr bmgr1 = bpt.getNodeManager().getBlockMgr() ;
+ BlockMgr bmgr2 = bpt.getRecordsMgr().getBlockMgr() ;
+
+ bmgr1 = buildBlockMgrTxn(txn, bmgr1) ;
+ bmgr2 = buildBlockMgrTxn(txn, bmgr1) ;
+
+ return BPlusTree.create(bpt.getParams(), bmgr1, bmgr2) ;
+ }
+
+
+ static BlockMgr buildBlockMgr(Transaction txn, BlockMgr blockMgr)
+ {
+ FileRef ref = null ;
+ // ref for label.
+ BlockMgrJournal blkMgr = new BlockMgrJournal(txn, ref, blockMgr) ;
+ txn.addComponent(blkMgr) ;
+ return blkMgr ;
+ }
+
+ }
+
+ public NodeTableTrans99(Transaction txn, String label, NodeTable sub, Index nodeIndex, ObjectFile objFile)
+ {
+ ObjectFileTrans objectsTrans = new ObjectFileTrans(txn,null/*From NodeTable*/, objFile) ;
+ BlockMgr blkMgr1 = null ;
+ BlockMgr blkMgr2 = null ;
+ Index idx = null ;
+
+ NodeTable nt = new NodeTableNative(nodeIndex, objectsTrans) ;
+
+ // Assume the NodeTable is transactional?
+ }
+
+ static class BlockMgrBuilderX implements BlockMgrBuilder
+ {
+ // TODO
+
+ @Override
+ public BlockMgr buildBlockMgr(FileSet fileSet, String ext, int blockSize)
+ {
+ return null ;
+ }
+
+ }
+
+ public RangeIndex buildRangeIndex(FileSet fileSet, RecordFactory recordFactory, BlockMgrBuilder bMgrNodes, BlockMgrBuilder bMgrRecords)
+ {
+ int blkSize = SystemTDB.BlockSize ;
+ int order = BPlusTreeParams.calcOrder(blkSize, recordFactory.recordLength()) ;
+ int readCacheSize = SystemTDB.BlockReadCacheSize ;
+ int writeCacheSize = SystemTDB.BlockWriteCacheSize ;
+ RangeIndex rIndex = createBPTree(fileSet, order, blkSize, readCacheSize, writeCacheSize, bMgrNodes, bMgrRecords, recordFactory) ;
+ return rIndex ;
+ }
+
+ /** Knowing all the parameters, create a B+Tree */
+ private RangeIndex createBPTree(FileSet fileset, int order,
+ int blockSize,
+ int readCacheSize, int writeCacheSize,
+ BlockMgrBuilder blockMgrBuilderNodes,
+ BlockMgrBuilder blockMgrBuilderRecords,
+ RecordFactory factory)
+ {
+ // ---- Checking
+ if (blockSize < 0 && order < 0) throw new IllegalArgumentException("Neither blocksize nor order specified") ;
+ if (blockSize >= 0 && order < 0) order = BPlusTreeParams.calcOrder(blockSize, factory.recordLength()) ;
+ if (blockSize >= 0 && order >= 0)
+ {
+ int order2 = BPlusTreeParams.calcOrder(blockSize, factory.recordLength()) ;
+ if (order != order2) throw new IllegalArgumentException("Wrong order (" + order + "), calculated = "
+ + order2) ;
+ }
+
+ // Iffy - does not allow for slop.
+ if (blockSize < 0 && order >= 0)
+ {
+ // Only in-memory.
+ blockSize = BPlusTreeParams.calcBlockSize(order, factory) ;
+ }
+
+ BPlusTreeParams params = new BPlusTreeParams(order, factory) ;
+
+ BlockMgr blkMgrNodes = blockMgrBuilderNodes.buildBlockMgr(fileset, Names.bptExtTree, blockSize) ;
+ BlockMgr blkMgrRecords = blockMgrBuilderRecords.buildBlockMgr(fileset, Names.bptExtRecords, blockSize) ;
+ return BPlusTree.create(params, blkMgrNodes, blkMgrRecords) ;
+ }
+}
+