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/12/04 18:45:12 UTC
svn commit: r1210156 - in
/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb:
base/file/BlockAccessMapped.java transaction/NodeTableTrans.java
transaction/TransactionManager.java
Author: andy
Date: Sun Dec 4 17:45:12 2011
New Revision: 1210156
URL: http://svn.apache.org/viewvc?rev=1210156&view=rev
Log:
Tidy debug code
Modified:
incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/BlockAccessMapped.java
incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java
incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/TransactionManager.java
Modified: incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/BlockAccessMapped.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/BlockAccessMapped.java?rev=1210156&r1=1210155&r2=1210156&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/BlockAccessMapped.java (original)
+++ incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/BlockAccessMapped.java Sun Dec 4 17:45:12 2011
@@ -23,7 +23,7 @@ import static java.lang.String.format;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel;
+import static java.nio.channels.FileChannel.MapMode ;
import java.util.Arrays;
import com.hp.hpl.jena.tdb.base.block.Block ;
@@ -217,7 +217,7 @@ public class BlockAccessMapped extends B
if ( segBuffer == null )
{
try {
- segBuffer = channel.map(FileChannel.MapMode.READ_WRITE, offset, SegmentSize) ;
+ segBuffer = channel.map(MapMode.READ_WRITE, offset, SegmentSize) ;
if ( getLog().isDebugEnabled() )
getLog().debug(format("Segment: %d", seg)) ;
segments[seg] = segBuffer ;
Modified: incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java?rev=1210156&r1=1210155&r2=1210156&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java (original)
+++ incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/NodeTableTrans.java Sun Dec 4 17:45:12 2011
@@ -163,7 +163,8 @@ public class NodeTableTrans implements N
journalObjFileStartOffset = journalObjFile.length() ;
if ( journalObjFileStartOffset != 0 )
{
- System.err.printf("\njournalStartOffset not zero: %d/0x%02X\n",journalObjFileStartOffset, journalObjFileStartOffset) ;
+ System.out.flush() ;
+ System.err.printf("\n%s journalStartOffset not zero: %d/0x%02X\n",txn.getLabel(), journalObjFileStartOffset, journalObjFileStartOffset) ;
// repeat for debugging.
journalObjFile.length() ;
@@ -265,19 +266,19 @@ public class NodeTableTrans implements N
@Override
public void commitPrepare(Transaction txn)
{
- debug(">> commitPrepare: %s", label) ;
+ debug("%s >> commitPrepare: %s", txn.getLabel(), label) ;
// The node table is append-only so it can be written during prepare.
// The index isn't written (via the transaction journal) until enact.
if ( nodeTableJournal == null )
- throw new TDBTransactionException("Not in a transaction for a commit to happen") ;
+ throw new TDBTransactionException(txn.getLabel()+": Not in a transaction for a commit to happen") ;
writeNodeJournal() ;
if ( journalObjFile.length() != 0 )
{
long x = journalObjFile.length() ;
- throw new TDBTransactionException("journalObjFile not cleared ("+x+")") ;
+ throw new TDBTransactionException(txn.getLabel()+": journalObjFile not cleared ("+x+")") ;
}
- debug("<< commitPrepare: %s", label) ;
+ debug("%s << commitPrepare: %s", txn.getLabel(), label) ;
}
@Override
@@ -306,7 +307,7 @@ public class NodeTableTrans implements N
nodeIndex.clear() ;
// Fixes nodeTableJournal
journalObjFile.truncate(journalObjFileStartOffset) ;
- // No need to sync - it's going to be closed.
+ journalObjFile.sync() ;
base.sync() ;
offset = -99 ; // base.allocOffset().getId() ; // Will be invalid as we may write through to the base table later.
passthrough = true ;
@@ -315,7 +316,7 @@ public class NodeTableTrans implements N
@Override
public void commitClearup(Transaction txn)
{
- //debug("commitClearup") ;
+ debug("commitClearup") ;
finish() ;
}
@@ -323,11 +324,12 @@ public class NodeTableTrans implements N
public void abort(Transaction txn)
{
if ( nodeTableJournal == null )
- throw new TDBTransactionException("Not in a transaction for a commit to happen") ;
+ throw new TDBTransactionException(txn.getLabel()+": Not in a transaction for a commit to happen") ;
// Ensure the cache does not flush.
nodeTableJournal = null ;
// then make sure the journal file is empty.
journalObjFile.truncate(journalObjFileStartOffset) ;
+ journalObjFile.sync() ;
finish() ;
}
Modified: incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/TransactionManager.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/TransactionManager.java?rev=1210156&r1=1210155&r2=1210156&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/TransactionManager.java (original)
+++ incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/TransactionManager.java Sun Dec 4 17:45:12 2011
@@ -23,6 +23,7 @@ import static com.hp.hpl.jena.tdb.transa
import static com.hp.hpl.jena.tdb.transaction.TransactionManager.TxnPoint.CLOSE ;
import static java.lang.String.format ;
+import java.io.File ;
import java.util.ArrayList ;
import java.util.HashSet ;
import java.util.List ;
@@ -305,7 +306,7 @@ public class TransactionManager
return begin$(mode, label) ;
}
- public static boolean tmpDebugNoteActions = false ;
+ public static boolean DEBUG = false ;
synchronized
private DatasetGraphTxn begin$(ReadWrite mode, String label)
@@ -322,7 +323,7 @@ public class TransactionManager
if ( mode == ReadWrite.WRITE && activeWriters.get() > 0 ) // Guard
throw new TDBTransactionException("Existing active write transaction") ;
- if ( tmpDebugNoteActions )
+ if ( DEBUG )
switch ( mode )
{
case READ : System.out.print("r") ; break ;
@@ -334,12 +335,12 @@ public class TransactionManager
DatasetGraphTDB dsg = baseDataset ;
// *** But, if there are pending, committed transactions, use latest.
if ( ! commitedAwaitingFlush.isEmpty() )
- { if ( tmpDebugNoteActions ) System.out.print(commitedAwaitingFlush.size()) ;
+ { if ( DEBUG ) System.out.print(commitedAwaitingFlush.size()) ;
dsg = commitedAwaitingFlush.get(commitedAwaitingFlush.size()-1).getActiveDataset() ;
}
else
{
- if ( tmpDebugNoteActions ) System.out.print('_') ;
+ if ( DEBUG ) System.out.print('_') ;
}
Transaction txn = createTransaction(dsg, mode, label) ;
DatasetGraphTxn dsgTxn = (DatasetGraphTxn)new DatasetBuilderTxn(this).build(txn, mode, dsg) ;
@@ -413,13 +414,21 @@ public class TransactionManager
return ;
}
- if ( tmpDebugNoteActions && queue.size() > 0 )
- System.out.print("!"+queue.size()+"!") ;
+ if ( DEBUG )
+ {
+ if ( queue.size() > 0 )
+ System.out.print("!"+queue.size()+"!") ;
+
+ }
if ( log() )
- {
log("Start flush delayed commits", txn) ;
- }
+
+ if ( DEBUG ) checkNodesDatJrnl(txn) ;
+
+ if ( queue.size() == 0 && txn != null )
+ // Nothing to do - journal should be empty.
+ return ;
while ( queue.size() > 0 )
{
@@ -432,27 +441,46 @@ public class TransactionManager
if ( txn2.getMode() == ReadWrite.READ )
continue ;
if ( log() )
- log("Flush delayed commit of "+txn.getLabel(), txn) ;
- // This takes a Write lock on the DSG - this is where it blocks.
+ log("Flush delayed commit of "+txn2.getLabel(), txn) ;
+ if ( DEBUG ) checkNodesDatJrnl(txn) ;
checkReplaySafe() ;
enactTransaction(txn2) ;
commitedAwaitingFlush.remove(txn2) ;
-
- // Drain queue - in fact, everything is done by one "enactTransaction"
-
} catch (InterruptedException ex)
{ Log.fatal(this, "Interruped!", ex) ; }
}
+
checkReplaySafe() ;
+ if ( DEBUG ) checkNodesDatJrnl(txn) ;
// Whole journal to base database
JournalControl.replay(journal, baseDataset) ;
+
+ if ( DEBUG ) checkNodesDatJrnl(txn) ;
checkReplaySafe() ;
if ( log() )
log("End flush delayed commits", txn) ;
+
+
+
}
+ private static void checkNodesDatJrnl(Transaction txn)
+ {
+ if (txn != null)
+ {
+ String x = txn.getBaseDataset().getLocation().getPath("nodes.dat-jrnl") ;
+ long len = new File(x).length() ;
+ if (len != 0)
+ {
+ System.out.flush() ;
+ System.err.println("Not zero 1") ;
+ System.err.println("Not zero 2") ;
+ }
+ }
+ }
+
private void checkReplaySafe()
{
if ( ! checking ) return ;