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/08/21 23:53:01 UTC

svn commit: r1375815 - in /jena/trunk/jena-tdb/src: main/java/com/hp/hpl/jena/tdb/ main/java/com/hp/hpl/jena/tdb/base/file/ main/java/com/hp/hpl/jena/tdb/graph/ main/java/com/hp/hpl/jena/tdb/transaction/ test/java/com/hp/hpl/jena/tdb/extra/

Author: andy
Date: Tue Aug 21 21:53:00 2012
New Revision: 1375815

URL: http://svn.apache.org/viewvc?rev=1375815&view=rev
Log:
Intermediate fix for JENA-301 -- a fix, but inefficient.
Further consideration necessary to see if redesign is needed.

Modified:
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/StoreConnection.java
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/file/ChannelManager.java
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/BulkUpdateHandlerTDB.java
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/Journal.java
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java
    jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/extra/T_TDBWriteTransaction.java

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/StoreConnection.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/StoreConnection.java?rev=1375815&r1=1375814&r2=1375815&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/StoreConnection.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/StoreConnection.java Tue Aug 21 21:53:00 2012
@@ -127,7 +127,7 @@ public class StoreConnection
         return baseDSG ;
     }
     
-    /** Flush the delayed write queue to th ebase storage.
+    /** Flush the delayed write queue to the base storage.
      *  This can only be done if there are no active transactions.
      *  If there are active transactions, nothing is done but this is safe to call. 
      */ 
@@ -154,6 +154,12 @@ public class StoreConnection
         JournalControl.recoverFromJournal(getBaseDataset(), transactionManager.getJournal()) ;
     }
 
+    /** Highly risky! */
+    public void printJournal()
+    {
+        JournalControl.print(transactionManager.getJournal()) ;
+    }
+    
     private static Map<Location, StoreConnection> cache = new HashMap<Location, StoreConnection>() ;
 
     // ---- statics managing the cache.
@@ -225,10 +231,20 @@ public class StoreConnection
         if (sConn == null)
         {
             sConn = new StoreConnection(dsg) ;
-            JournalControl.recoverFromJournal(dsg, sConn.transactionManager.getJournal()) ;
+            boolean actionTaken = JournalControl.recoverFromJournal(dsg, sConn.transactionManager.getJournal()) ;
+            
+            if ( actionTaken )
+            {
+                // Clunky!  Complete reset.
+                sConn.transactionManager.closedown() ;
+                sConn.baseDSG.close() ;
+                dsg = DatasetBuilderStd.build(location) ;
+                sConn = new StoreConnection(dsg) ;
+            }
+            
             if (!location.isMemUnique())
-            // Don't cache use-once in-memory datasets.
-            cache.put(location, sConn) ;
+                // Don't cache use-once in-memory datasets.
+                cache.put(location, sConn) ;
             String NS = TDB.PATH ;
             TransactionInfo txInfo = new TransactionInfo(sConn.transactionManager) ;
             ARQMgt.register(NS + ".system:type=Transactions", txInfo) ;

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/file/ChannelManager.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/file/ChannelManager.java?rev=1375815&r1=1375814&r2=1375815&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/file/ChannelManager.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/file/ChannelManager.java Tue Aug 21 21:53:00 2012
@@ -92,6 +92,11 @@ public class ChannelManager
             name2channel.remove(name) ;
     }
     
+    public static void reset()
+    {
+        shutdown(null) ;
+    }
+    
     /** Shutdown all the files matching the prefix (typically a directory) */  
     public static void shutdown(String prefix)
     {
@@ -99,7 +104,7 @@ public class ChannelManager
         List<FileChannel> x = new ArrayList<FileChannel>() ;
         for ( String fn : name2channel.keySet() )
         {
-            if ( fn.startsWith(prefix) )
+            if ( prefix == null || fn.startsWith(prefix) )
             {
                 x.add(name2channel.get(fn)) ;
                 // Don't call release here - potential CME problems.

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/BulkUpdateHandlerTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/BulkUpdateHandlerTDB.java?rev=1375815&r1=1375814&r2=1375815&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/BulkUpdateHandlerTDB.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/BulkUpdateHandlerTDB.java Tue Aug 21 21:53:00 2012
@@ -42,48 +42,6 @@ public class BulkUpdateHandlerTDB extend
         this.graphTDB = graph ;
     }
 
-//    @Override
-//    public void add(Triple[] triples)
-//    {}
-//
-//    @Override
-//    public void add(List triples)
-//    { }
-//
-//    @Override
-//    public void add(Iterator it)
-//    {}
-//
-//    @Override
-//    public void add(Graph g)
-//    {}
-//
-//    @Override
-//    public void add(Graph g, boolean withReifications)
-//    {}
-//
-//    @Override
-//    public void delete(Triple[] triples)
-//    {}
-//
-//    @Override
-//    public void delete(List triples)
-//    {}
-//
-//    @Override
-//    public void delete(Iterator it)
-//    {}
-//
-//    @Override
-//    public void delete(Graph g)
-//    {}
-//
-//    @Override
-//    public void delete(Graph g, boolean withReifications)
-//    {}
-//
-    
-    // Testcases needed
     @Override
     public void remove(Node s, Node p, Node o)
     {
@@ -133,15 +91,14 @@ public class BulkUpdateHandlerTDB extend
                 // Finished?
                 return ;
             
-            //Arrays.fill(array, null) ;
-            
-            // Get the first sliceSize
+            // Get a slice
             int len = 0 ;
             for ( ; len < sliceSize ; len++ )
             {
                 if ( !iter.hasNext() ) break ;
                 array[len] = iter.next() ;
             }
+            
             // Delete them.
             for ( int i = 0 ; i < len ; i++ )
             {

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/Journal.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/Journal.java?rev=1375815&r1=1375814&r2=1375815&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/Journal.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/Journal.java Tue Aug 21 21:53:00 2012
@@ -45,7 +45,7 @@ import com.hp.hpl.jena.tdb.sys.Names ;
  *  if the journal grows to the point where it needs to free up cache. 
  */
 public final
-class Journal implements Iterable<JournalEntry>, Sync, Closeable
+class Journal implements Sync, Closeable
 {
     private static Logger log = LoggerFactory.getLogger(Journal.class) ;
     
@@ -287,10 +287,6 @@ class Journal implements Iterable<Journa
     {
         return new IteratorEntries(startPosition) ;
     }
-    
-    /** Convenience method to iterate over the whole journal */ 
-    @Override
-    public Iterator<JournalEntry> iterator() { return entries() ; }
 
     @Override
     public void sync()  { channel.sync() ; }

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java?rev=1375815&r1=1375814&r2=1375815&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java Tue Aug 21 21:53:00 2012
@@ -55,12 +55,13 @@ public class JournalControl
     public static void print(Journal journal)
     {
         System.out.println("Size: "+journal.size()) ;
+        Iterator<JournalEntry> iter = journal.entries() ; 
         
-        for ( JournalEntry e : journal )
+        for (  ; iter.hasNext() ; )
         {
+            JournalEntry e = iter.next() ;
             System.out.println(JournalEntry.format(e)) ;
             System.out.println("Posn: "+journal.position()+" : ("+(journal.size()-journal.position())+")") ;
-            
         }
     }
 
@@ -105,11 +106,12 @@ public class JournalControl
     /** Recovery from a journal.
      *  Find if there is a commit record; if so, reply the journal to that point.
      *  Try to see if there is another commit record ...
+     *  Retirn true if a recovery was attempted; return false if we decided no work needed.
      */
-    public static void recoverFromJournal(DatasetGraphTDB dsg, Journal jrnl )
+    public static boolean recoverFromJournal(DatasetGraphTDB dsg, Journal jrnl )
     {
         if ( jrnl.isEmpty() )
-            return ;
+            return false ;
         
         long posn = 0 ;
         for ( ;; )
@@ -123,6 +125,7 @@ public class JournalControl
         // We have replayed the journals - clean up.
         jrnl.truncate(0) ;
         dsg.sync() ;
+        return true ;
     }
 
     /** Scan to a commit entry, starting at a given position in the journal.
@@ -253,12 +256,18 @@ public class JournalControl
         journal.position(0) ;
         dsg.getLock().enterCriticalSection(Lock.WRITE) ;
         try {
-            for ( JournalEntry e : journal )
+            Iterator<JournalEntry> iter = journal.entries() ; 
+
+            for (  ; iter.hasNext() ; )
+            {
+                JournalEntry e = iter.next() ;
                 replay(e, dsg) ;
-            // There is no point sync here.  
-            // No writes via the DSG have been done 
-            // so all internal flags "syncNeeded" are false.
-            //dsg.sync() ;
+
+                // There is no point sync here.  
+                // No writes via the DSG have been done. 
+                // so all internal flags "syncNeeded" are false.
+                //dsg.sync() ;
+            }
         } 
         catch (RuntimeException ex)
         { 

Modified: jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/extra/T_TDBWriteTransaction.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/extra/T_TDBWriteTransaction.java?rev=1375815&r1=1375814&r2=1375815&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/extra/T_TDBWriteTransaction.java (original)
+++ jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/extra/T_TDBWriteTransaction.java Tue Aug 21 21:53:00 2012
@@ -60,8 +60,10 @@ public class T_TDBWriteTransaction {
 	final static String INDEX_SIZE_PREDICATE = "http://test.net/xmlns/test/1.0/indexSize";
 
     public static void main(String[] args) {
+        if ( true )
+            SystemTDB.setFileMode(FileMode.direct) ;
 
-	    Log.setLog4j() ;
+        Log.setLog4j() ;
 	    TransactionManager.QueueBatchSize = 10;
 	    
 //		if (args.length == 0) {
@@ -74,12 +76,6 @@ public class T_TDBWriteTransaction {
 	    //FileOps.clearDirectory(location) ;
 	    bracketWithReader = false ;
 	    
-	    //Log.enable(JournalControl.class.getName()) ;
-	    
-	    //Submitted without .... 
-	    if ( true )
-	        SystemTDB.setFileMode(FileMode.direct) ;
-	    
 	    run(location) ;
 //	    StoreConnection.make(location).forceRecoverFromJournal() ;
 //	    run(location) ;