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/10/08 21:54:44 UTC
svn commit: r1180477 - in
/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb:
index/TupleTable.java nodetable/NodeTableNative.java
store/bulkloader/BulkLoader.java
Author: andy
Date: Sat Oct 8 19:54:44 2011
New Revision: 1180477
URL: http://svn.apache.org/viewvc?rev=1180477&view=rev
Log:
Bug fix: The Java bulk loader was not syncing underlying files (node table) because higher levels taht had been bypassed did not know chnages had been made. Fix makes the bulk loader directly sync() the underlying tables before exit.
Modified:
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodeTableNative.java
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/store/bulkloader/BulkLoader.java
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java?rev=1180477&r1=1180476&r2=1180477&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java Sat Oct 8 19:54:44 2011
@@ -37,7 +37,9 @@ public class TupleTable implements Sync,
private static Logger log = LoggerFactory.getLogger(TupleTable.class) ;
private final TupleIndex[] indexes ;
- private final int tupleLen ;
+ private final int tupleLen ;
+ private boolean syncNeeded = false ;
+
public TupleTable(int tupleLen, TupleIndex[] indexes)
{
@@ -58,7 +60,7 @@ public class TupleTable implements Sync,
/** Insert a tuple - return true if it was really added, false if it was a duplicate */
public boolean add(Tuple<NodeId> t)
- {
+ {
if ( tupleLen != t.size() )
throw new TDBException(format("Mismatch: inserting tuple of length %d into a table of tuples of length %d", t.size(), tupleLen)) ;
@@ -76,7 +78,7 @@ public class TupleTable implements Sync,
unexpectedDuplicate(t, i) ;
throw new TDBException(format("Secondary index duplicate: %s -> %s",indexes[i].getLabel(), t)) ;
}
-
+ syncNeeded = true ;
}
return true ;
}
@@ -116,7 +118,9 @@ public class TupleTable implements Sync,
{
if ( indexes[i] == null ) continue ;
// Use return boolean
- rc = indexes[i].delete(t) ;
+ rc = indexes[i].delete(t) ;
+ if ( rc )
+ syncNeeded = true ;
}
return rc ;
@@ -192,11 +196,15 @@ public class TupleTable implements Sync,
@Override
public void sync()
- {
- for ( TupleIndex idx : indexes )
+ {
+ if ( syncNeeded )
{
- if ( idx != null )
- idx.sync() ;
+ for ( TupleIndex idx : indexes )
+ {
+ if ( idx != null )
+ idx.sync() ;
+ }
+ syncNeeded = false ;
}
}
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodeTableNative.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodeTableNative.java?rev=1180477&r1=1180476&r2=1180477&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodeTableNative.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodeTableNative.java Sat Oct 8 19:54:44 2011
@@ -43,7 +43,8 @@ public class NodeTableNative implements
// this to be overriden for a direct use of BDB.
protected ObjectFile objects ;
- protected Index nodeHashToId ; // hash -> int
+ protected Index nodeHashToId ; // hash -> int
+ private boolean syncNeeded = false ;
// Delayed construction - must call init explicitly.
protected NodeTableNative() {}
@@ -151,15 +152,15 @@ public class NodeTableNative implements
}
}
- // -------- NodeId<->Node
- // Assumes NodeId inlining and caching has been handled.
- // Assumes synchronized (the caches will be updated consistently)
-
+ // -------- NodeId<->Node
+ // Synchronization:
+ // write: in accessIndex
+ // read: synchronized here.
// Only places for accessing the StringFile.
- //
private final NodeId writeNodeToTable(Node node)
- {
+ {
+ syncNeeded = true ;
// Synchroized in accessIndex
long x = NodeLib.encodeStore(node, getObjects()) ;
return NodeId.create(x);
@@ -179,7 +180,7 @@ public class NodeTableNative implements
@Override
public synchronized void close()
- {
+ {
// Close once. This may be shared (e.g. triples table and quads table).
if ( nodeHashToId != null )
{
@@ -239,11 +240,15 @@ public class NodeTableNative implements
@Override
public void sync()
- {
- if ( nodeHashToId != null )
- nodeHashToId.sync() ;
- if ( getObjects() != null )
- getObjects().sync() ;
+ {
+ if ( syncNeeded )
+ {
+ if ( nodeHashToId != null )
+ nodeHashToId.sync() ;
+ if ( getObjects() != null )
+ getObjects().sync() ;
+ syncNeeded = false ;
+ }
}
public ObjectFile getObjects()
Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/store/bulkloader/BulkLoader.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/store/bulkloader/BulkLoader.java?rev=1180477&r1=1180476&r2=1180477&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/store/bulkloader/BulkLoader.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/store/bulkloader/BulkLoader.java Sat Oct 8 19:54:44 2011
@@ -238,7 +238,7 @@ public class BulkLoader
Stats.write(filename, stats) ;
}
- dsg.sync();
+ forceSync(dsg) ;
}
} ;
return sink ;
@@ -308,8 +308,8 @@ public class BulkLoader
{
String filename = dsg.getLocation().getPath(Names.optStats) ;
Stats.write(filename, stats) ;
- }
- dsg.sync() ;
+ }
+ forceSync(dsg) ;
}
@Override
@@ -318,5 +318,19 @@ public class BulkLoader
final public void close() { }
} ;
return sink ;
+ }
+
+ static void forceSync(DatasetGraphTDB dsg)
+ {
+ // Force sync - we have been bypassing DSG tables.
+ // THIS DOES NOT WORK IF modules check for SYNC necessity.
+ dsg.getTripleTable().getNodeTupleTable().getNodeTable().sync();
+ dsg.getQuadTable().getNodeTupleTable().getNodeTable().sync();
+ dsg.getQuadTable().getNodeTupleTable().getNodeTable().sync();
+ dsg.getPrefixes().getNodeTupleTable().getNodeTable().sync();
+
+ // This is not enough -- modules whether sync needed.
+ dsg.sync() ;
+
}
}