jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1169786 - in /incubator/jena/Experimental/TxTDB/trunk: src-dev/tx/ src/main/java/com/hp/hpl/jena/tdb/setup/ src/main/java/com/hp/hpl/jena/tdb/store/ src/main/java/com/hp/hpl/jena/tdb/sys/ src/main/java/com/hp/hpl/jena/tdb/transaction/
Date Mon, 12 Sep 2011 14:59:23 GMT
Author: andy
Date: Mon Sep 12 14:59:23 2011
New Revision: 1169786

URL: http://svn.apache.org/viewvc?rev=1169786&view=rev
Log: (empty)

Modified:
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TransBlob.java
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TxMain.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/store/StoreConfig.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/sys/SetupTDB.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java

Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TransBlob.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TransBlob.java?rev=1169786&r1=1169785&r2=1169786&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TransBlob.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TransBlob.java Mon Sep 12 14:59:23
2011
@@ -20,7 +20,7 @@ package tx;
 
 import java.nio.ByteBuffer ;
 
-import com.hp.hpl.jena.tdb.base.file.BlockAccess ;
+import com.hp.hpl.jena.tdb.base.file.BufferChannel ;
 import com.hp.hpl.jena.tdb.sys.FileRef ;
 import com.hp.hpl.jena.tdb.transaction.Journal ;
 import com.hp.hpl.jena.tdb.transaction.JournalEntryType ;
@@ -32,21 +32,25 @@ public class TransBlob implements Transa
 {
     // And need a block mgr
     
+    private boolean changed ; 
     private ByteBuffer bytes ;
     private final FileRef file ;
-    private final BlockAccess access ;
+    private final BufferChannel data ;
 
-    public TransBlob(BlockAccess blockAccess, FileRef file)
+    public TransBlob(BufferChannel data, FileRef file, ByteBuffer initialBytes)
     {
-        this.access = blockAccess ;
+        this.data = data ;
         // BlockMgrFileAccess.
         this.file = file ;
+        this.bytes = initialBytes ;
+        this.changed = false ;
     }
     
     public void setValue(ByteBuffer bytes)
     {
         // Copy for safety?
-        this.bytes= bytes ;
+        this.bytes = bytes ;
+        this.changed = true ;
     }
 
     public ByteBuffer getValue()
@@ -56,8 +60,7 @@ public class TransBlob implements Transa
     
     @Override
     public void begin(Transaction txn)
-    {
-    }
+    { }
 
     @Override
     public void abort(Transaction txn)
@@ -69,20 +72,24 @@ public class TransBlob implements Transa
         Journal journal = txn.getJournal() ;
         //Block blk = new Block(0, bytes) ;
         //JournalEntry entry = new JournalEntry(file, blk) ;
-
-        // And reply?
         journal.writeJournal(JournalEntryType.Buffer, file, bytes) ;
-        
-       // replay : fileref -> remembered BlockMgr = BlockMgrFileAccess
-        
     }
 
     @Override
     public void commitEnact(Transaction txn)
-    {}
+    { 
+        data.sync() ;
+    }
 
     @Override
     public void commitClearup(Transaction txn)
-    {}
+    {
+        clearup() ;
+    }
+    
+    private void clearup()
+    {
+        bytes = null ;
+    }
 }
 

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=1169786&r1=1169785&r2=1169786&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TxMain.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TxMain.java Mon Sep 12 14:59:23 2011
@@ -6,10 +6,13 @@
 
 package tx;
 
+import java.nio.ByteBuffer ;
+
 import org.openjena.atlas.lib.Bytes ;
 import org.openjena.atlas.lib.FileOps ;
 import org.openjena.atlas.lib.Sink ;
 import org.openjena.atlas.lib.SinkWrapper ;
+import org.openjena.atlas.lib.StrUtils ;
 import org.openjena.atlas.logging.Log ;
 import org.openjena.riot.RiotReader ;
 import org.openjena.riot.RiotWriter ;
@@ -30,11 +33,20 @@ import com.hp.hpl.jena.sparql.util.Query
 import com.hp.hpl.jena.tdb.DatasetGraphTxn ;
 import com.hp.hpl.jena.tdb.ReadWrite ;
 import com.hp.hpl.jena.tdb.StoreConnection ;
+import com.hp.hpl.jena.tdb.base.file.BufferChannel ;
+import com.hp.hpl.jena.tdb.base.file.BufferChannelFile ;
+import com.hp.hpl.jena.tdb.base.file.FileSet ;
 import com.hp.hpl.jena.tdb.base.file.Location ;
 import com.hp.hpl.jena.tdb.base.record.Record ;
 import com.hp.hpl.jena.tdb.base.record.RecordFactory ;
 import com.hp.hpl.jena.tdb.setup.DatasetBuilderStd ;
 import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
+import com.hp.hpl.jena.tdb.sys.FileRef ;
+import com.hp.hpl.jena.tdb.transaction.Journal ;
+import com.hp.hpl.jena.tdb.transaction.JournalControl ;
+import com.hp.hpl.jena.tdb.transaction.JournalEntry ;
+import com.hp.hpl.jena.tdb.transaction.JournalEntryType ;
+import com.hp.hpl.jena.tdb.transaction.Transaction ;
 import com.hp.hpl.jena.update.UpdateAction ;
 import com.hp.hpl.jena.update.UpdateFactory ;
 import com.hp.hpl.jena.update.UpdateRequest ;
@@ -58,16 +70,60 @@ public class TxMain
     }
     
     static public String DBdir = "DB" ;
+    static public Location LOC = new Location(DBdir) ;
     
     public static void main(String... args)
     {
-        //initFS() ;
+        initFS() ;
         
         //String DATA = "/home/afs/Datasets/MusicBrainz/tracks.nt.gz" ;
         String DATA = "/home/afs/Datasets/MusicBrainz/tracks-10k.nt" ;
         
-        StoreConnection sConn = StoreConnection.make(Location.mem()) ;
-        DatasetGraphTxn dsg = sConn.begin(ReadWrite.WRITE) ;  
+        StoreConnection sConn = StoreConnection.make(LOC) ;
+        DatasetGraphTxn dsg = sConn.begin(ReadWrite.WRITE) ;
+        Transaction txn = dsg.getTransaction() ;
+        Journal journal = txn.getJournal() ;
+        
+        String blobFileBase = "BLOB" ;
+        String blobExt = "blob" ;
+        
+        FileSet fs = new FileSet(LOC, blobFileBase) ;
+        FileRef ref = FileRef.create(fs, blobExt) ;
+        String blobfilename = fs.filename(blobExt) ;
+        
+        BufferChannel data = new BufferChannelFile(blobfilename) ;
+        System.out.println(ref.getFilename()) ;
+        
+        dsg.getConfig().bufferChannels.put(ref, data) ;
+
+        TransBlob blob = new TransBlob(data, ref, null) ;
+        
+        blob.begin(txn) ;
+        blob.setValue(ByteBuffer.wrap(StrUtils.asUTF8bytes("Stringdata"))) ;
+        blob.commitPrepare(txn) ;
+        
+        // Journal commit.
+        JournalEntry entry = new JournalEntry(JournalEntryType.Commit, FileRef.Journal, null)
;
+        journal.writeJournal(entry) ;
+        journal.sync() ;        // Commit point.
+        
+        JournalControl.replay(journal, dsg) ;
+        
+        blob.commitEnact(txn) ;
+        blob.commitClearup(txn) ;
+        
+        ByteBuffer bb2 = ByteBuffer.allocate(1024) ; 
+        BufferChannel data2 = new BufferChannelFile(blobfilename) ;
+        
+        int x = data2.read(bb2) ;
+        byte b[] = new byte[x] ;
+        bb2.position(0) ;
+        bb2.get(b, 0, x) ;
+        String str = StrUtils.fromUTF8bytes(b) ;
+        System.out.println(str) ;
+        
+        exit(0) ;
+        
         Sink<Triple> sink = new SinkTriplesToGraph(dsg.getDefaultGraph()) ;
         RiotReader.parseTriples(DATA, sink) ;
         System.out.println(dsg.getDefaultGraph().size()) ;
@@ -94,8 +150,10 @@ public class TxMain
 
     private static void initFS()
     {
-        FileOps.ensureDir(DBdir) ;
-        FileOps.clearDirectory(DBdir) ;
+        if ( LOC.isMem() )
+            return ;
+        FileOps.ensureDir(LOC.getDirectoryPath()) ;
+        FileOps.clearDirectory(LOC.getDirectoryPath()) ;
     }
     
     private static DatasetGraphTDB build()

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=1169786&r1=1169785&r2=1169786&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
Mon Sep 12 14:59:23 2011
@@ -18,6 +18,7 @@ import com.hp.hpl.jena.sparql.engine.opt
 import com.hp.hpl.jena.tdb.TDB ;
 import com.hp.hpl.jena.tdb.TDBException ;
 import com.hp.hpl.jena.tdb.base.block.BlockMgr ;
+import com.hp.hpl.jena.tdb.base.file.BufferChannel ;
 import com.hp.hpl.jena.tdb.base.file.FileSet ;
 import com.hp.hpl.jena.tdb.base.file.Location ;
 import com.hp.hpl.jena.tdb.base.file.MetaFile ;
@@ -56,6 +57,7 @@ public class DatasetBuilderStd implement
     private Properties config ;
     
     private Map<FileRef, BlockMgr> blockMgrs = new HashMap<FileRef, BlockMgr>()
;
+    private Map<FileRef, BufferChannel> bufferChannels = new HashMap<FileRef, BufferChannel>()
;
     private Map<FileRef, NodeTable> nodeTables = new HashMap<FileRef, NodeTable>()
;
 
     public static DatasetGraphTDB build(Location location)
@@ -176,7 +178,7 @@ public class DatasetBuilderStd implement
         DatasetPrefixesTDB prefixes = makePrefixTable(location, policy) ;
         ReorderTransformation transform  = chooseReorderTransformation(location) ;
         
-        StoreConfig storeConfig = new StoreConfig(location, config, blockMgrs, nodeTables)
;
+        StoreConfig storeConfig = new StoreConfig(location, config, blockMgrs, bufferChannels,
nodeTables) ;
         DatasetGraphTDB dsg = new DatasetGraphTDB(tripleTable, quadTable, prefixes, transform,
storeConfig) ;
         return dsg ;
     }

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/store/StoreConfig.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/store/StoreConfig.java?rev=1169786&r1=1169785&r2=1169786&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/store/StoreConfig.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/store/StoreConfig.java
Mon Sep 12 14:59:23 2011
@@ -22,6 +22,7 @@ import java.util.Map ;
 import java.util.Properties ;
 
 import com.hp.hpl.jena.tdb.base.block.BlockMgr ;
+import com.hp.hpl.jena.tdb.base.file.BufferChannel ;
 import com.hp.hpl.jena.tdb.base.file.Location ;
 import com.hp.hpl.jena.tdb.nodetable.NodeTable ;
 import com.hp.hpl.jena.tdb.sys.FileRef ;
@@ -30,14 +31,19 @@ public class StoreConfig
 {
     public Properties properties ;
     public Map<FileRef, BlockMgr> blockMgrs ;
+    public Map<FileRef, BufferChannel> bufferChannels ;
     public Map<FileRef, NodeTable> nodeTables ;
     public Location location ; 
 
-    public StoreConfig(Location location, Properties properties, Map<FileRef, BlockMgr>
blockMgrs, Map<FileRef, NodeTable> nodeTables)
+    public StoreConfig(Location location, Properties properties, 
+                       Map<FileRef, BlockMgr> blockMgrs, 
+                       Map<FileRef, BufferChannel> bufferChannels,
+                       Map<FileRef, NodeTable> nodeTables)
     {
         this.location = location ;
         this.properties = properties ;
         this.blockMgrs = blockMgrs ;
+        this.bufferChannels = bufferChannels ;
         this.nodeTables = nodeTables ;
     }
     

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/sys/SetupTDB.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/sys/SetupTDB.java?rev=1169786&r1=1169785&r2=1169786&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/sys/SetupTDB.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/sys/SetupTDB.java
Mon Sep 12 14:59:23 2011
@@ -259,7 +259,7 @@ public class SetupTDB
         DatasetPrefixesTDB prefixes = makePrefixes(location, config, policy) ;
 
         // ---- Create the DatasetGraph object
-        StoreConfig storeConfig = new StoreConfig(location, config, null, null) ;
+        StoreConfig storeConfig = new StoreConfig(location, config, null, null, null) ;
         DatasetGraphTDB dsg = new DatasetGraphTDB(tripleTable, quadTable, prefixes, chooseOptimizer(location),
storeConfig) ;
 
         // Finalize

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java?rev=1169786&r1=1169785&r2=1169786&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java
Mon Sep 12 14:59:23 2011
@@ -11,6 +11,7 @@ import static com.hp.hpl.jena.tdb.sys.Sy
 import static java.lang.String.format ;
 
 import java.io.File ;
+import java.nio.ByteBuffer ;
 import java.util.Iterator ;
 import java.util.Map ;
 
@@ -23,6 +24,7 @@ import com.hp.hpl.jena.shared.Lock ;
 import com.hp.hpl.jena.tdb.DatasetGraphTxn ;
 import com.hp.hpl.jena.tdb.base.block.Block ;
 import com.hp.hpl.jena.tdb.base.block.BlockMgr ;
+import com.hp.hpl.jena.tdb.base.file.BufferChannel ;
 import com.hp.hpl.jena.tdb.base.file.FileFactory ;
 import com.hp.hpl.jena.tdb.base.file.Location ;
 import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
@@ -256,6 +258,7 @@ public class JournalControl
         switch (e.getType())
         {
             case Block:
+            {
                 // All-purpose, works for direct and mapped mode, copy of a block.
                 // [TxTDB:PATCH-UP]
                 // Direct: blkMgr.write(e.getBlock()) would work.
@@ -272,10 +275,19 @@ public class JournalControl
 //                blk.getByteBuffer().put(e.getBlock().getByteBuffer()) ;
 //                blkMgr.write(e.getBlock()) ; 
                 return true ;
+            }   
+            case Buffer:
+            {
+                BufferChannel chan = dsg.getConfig().bufferChannels.get(e.getFileRef()) ;
+                ByteBuffer bb = e.getByteBuffer() ;
+                log.debug("Replay: {} {}",e.getFileRef(), bb) ;
+                chan.write(bb, 0) ; // YUK!
+                return true ;
+            }
+                
             case Commit:
                 return false ;
             case Abort:
-            case Buffer:
             case Object:
             case Checkpoint:
                 errlog.warn("Unexpected block type: "+e.getType()) ;



Mime
View raw message