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/09 19:00:27 UTC
svn commit: r1348456 - in /jena/trunk/jena-tdb/src:
main/java/com/hp/hpl/jena/tdb/index/ main/java/com/hp/hpl/jena/tdb/nodetable/
main/java/com/hp/hpl/jena/tdb/store/
main/java/com/hp/hpl/jena/tdb/transaction/
test/java/com/hp/hpl/jena/tdb/assembler/ t...
Author: andy
Date: Sat Jun 9 17:00:27 2012
New Revision: 1348456
URL: http://svn.apache.org/viewvc?rev=1348456&view=rev
Log:
Systematically handled "sync needed" management.
Make test cases work where sensitive to the StoreConnection cache - clear this when clearign directories.
Modified:
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodeTableNative.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetPrefixesTDB.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/QuadTable.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/TableBase.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/TripleTable.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetGraphTransaction.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/TransactionManager.java
jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/assembler/TestTDBAssembler.java
jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/graph/TestPrefixMappingTDB.java
jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestDatasetTDBPersist.java
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java?rev=1348456&r1=1348455&r2=1348456&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java Sat Jun 9 17:00:27 2012
@@ -39,7 +39,6 @@ public class TupleTable implements Sync,
private final TupleIndex[] indexes ;
private final int tupleLen ;
private boolean syncNeeded = false ;
-
public TupleTable(int tupleLen, TupleIndex[] indexes)
{
@@ -217,6 +216,7 @@ public class TupleTable implements Sync,
if ( idx != null )
idx.clear() ;
}
+ syncNeeded = true ;
}
public long size()
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodeTableNative.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodeTableNative.java?rev=1348456&r1=1348455&r2=1348456&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodeTableNative.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/nodetable/NodeTableNative.java Sat Jun 9 17:00:27 2012
@@ -39,6 +39,9 @@ import com.hp.hpl.jena.tdb.store.NodeId
/** A concrete NodeTable based on native storage (string file and an index) */
public class NodeTableNative implements NodeTable
{
+ // TODO Split intio a general accessor (get and put (node,NodeId) pairs)
+ // Abstracts the getAllocateNodeId requirements.
+
// Assumes an StringFile and an Indexer, which may be an Index but allows
// this to be overriden for a direct use of BDB.
@@ -137,7 +140,6 @@ public class NodeTableNative implements
// Not found.
if ( ! create )
return NodeId.NodeDoesNotExist ;
-
// Write the node, which allocates an id for it.
NodeId id = writeNodeToTable(node) ;
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetPrefixesTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetPrefixesTDB.java?rev=1348456&r1=1348455&r2=1348456&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetPrefixesTDB.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetPrefixesTDB.java Sat Jun 9 17:00:27 2012
@@ -52,14 +52,12 @@ public class DatasetPrefixesTDB implemen
// Index on GPU and a nodetable.
// The nodetable is itself an index and a data file.
+ static final ColumnMap colMap = new ColumnMap(Names.primaryIndexPrefix, Names.primaryIndexPrefix) ;
+ static final RecordFactory factory = new RecordFactory(3*NodeId.SIZE, 0) ;
static final String unamedGraphURI = "" ; //Quad.defaultGraphNode.getURI() ;
// Use NodeTupleTableView?
private final NodeTupleTable nodeTupleTable ;
- static final ColumnMap colMap = new ColumnMap(Names.primaryIndexPrefix, Names.primaryIndexPrefix) ;
-
- public static final RecordFactory factory = new RecordFactory(3*NodeId.SIZE, 0) ;
-
@Deprecated
public static DatasetPrefixesTDB create(Location location, DatasetControl policy) { return create(IndexBuilder.get(), location, policy) ; }
@@ -232,5 +230,8 @@ public class DatasetPrefixesTDB implemen
}
@Override
- public void sync() { nodeTupleTable.sync() ; }
+ public void sync()
+ {
+ nodeTupleTable.sync() ;
+ }
}
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/QuadTable.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/QuadTable.java?rev=1348456&r1=1348455&r2=1348456&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/QuadTable.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/QuadTable.java Sat Jun 9 17:00:27 2012
@@ -62,7 +62,6 @@ public class QuadTable extends TableBase
/** Add a quad - return true if it was added, false if it already existed */
public boolean add(Node g, Node s, Node p, Node o)
{
- syncNeeded = true ;
return table.addRow(g,s,p,o) ;
}
@@ -83,7 +82,6 @@ public class QuadTable extends TableBase
/** Delete a quad - return true if it was deleted, false if it didn't exist */
public boolean delete(Node g, Node s, Node p, Node o)
{
- syncNeeded = true ;
return table.deleteRow(g, s, p, o) ;
}
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/TableBase.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/TableBase.java?rev=1348456&r1=1348455&r2=1348456&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/TableBase.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/TableBase.java Sat Jun 9 17:00:27 2012
@@ -30,7 +30,6 @@ import com.hp.hpl.jena.tdb.sys.DatasetCo
public class TableBase implements Sync, Closeable
{
final protected NodeTupleTable table ;
- protected boolean syncNeeded = false ;
protected TableBase(int N, TupleIndex[] indexes, NodeTable nodeTable, DatasetControl policy)
{
@@ -50,9 +49,7 @@ public class TableBase implements Sync,
@Override
public void sync()
{
- if ( syncNeeded )
- table.sync() ;
- syncNeeded = false ;
+ table.sync() ;
}
@Override
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/TripleTable.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/TripleTable.java?rev=1348456&r1=1348455&r2=1348456&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/TripleTable.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/TripleTable.java Sat Jun 9 17:00:27 2012
@@ -56,7 +56,6 @@ public class TripleTable extends TableBa
public boolean add(Node s, Node p, Node o)
{
- syncNeeded = true ;
return table.addRow(s, p, o) ;
}
@@ -70,7 +69,6 @@ public class TripleTable extends TableBa
/** Delete a triple - return true if it was deleted, false if it didn't exist */
public boolean delete(Node s, Node p, Node o)
{
- syncNeeded = true ;
return table.deleteRow(s, p, o) ;
}
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetGraphTransaction.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetGraphTransaction.java?rev=1348456&r1=1348455&r2=1348456&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetGraphTransaction.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetGraphTransaction.java Sat Jun 9 17:00:27 2012
@@ -44,15 +44,7 @@ public class DatasetGraphTransaction ext
return null ;
}
}
-
- static class ThreadLocalBoolean extends ThreadLocal<Boolean>
- {
- // This is the default implementation - but nice to give it a name and to set it clearly.
- @Override protected Boolean initialValue() {
- return Boolean.FALSE ;
- }
- }
-
+
@Override
protected void finalize() throws Throwable
{
@@ -63,9 +55,7 @@ public class DatasetGraphTransaction ext
// Transaction per thread.
private ThreadLocalTxn txn = new ThreadLocalTxn() ;
- private ThreadLocalBoolean inTransaction = new ThreadLocalBoolean() ;
- private boolean haveUsedInTransaction = false ;
private final StoreConnection sConn ;
public DatasetGraphTransaction(Location location)
@@ -96,7 +86,7 @@ public class DatasetGraphTransaction ext
return dsgTxn ;
}
- if ( haveUsedInTransaction )
+ if ( sConn.haveUsedInTransaction() )
throw new TDBTransactionException("Not in a transaction") ;
// Never used in a transaction - return underlying database for old style (non-transactional) usage.
@@ -106,62 +96,52 @@ public class DatasetGraphTransaction ext
@Override
protected void checkActive()
{
- if ( haveUsedInTransaction && ! isInTransaction() )
+ if ( sConn.haveUsedInTransaction() && ! isInTransaction() )
throw new JenaTransactionException("Not in a transaction ("+getLocation()+")") ;
}
@Override
protected void checkNotActive()
{
- if ( haveUsedInTransaction && isInTransaction() )
+ if ( sConn.haveUsedInTransaction() && isInTransaction() )
throw new JenaTransactionException("Currently in a transaction ("+getLocation()+")") ;
}
@Override
public boolean isInTransaction()
- { return inTransaction.get() ; }
+ { return txn.get() != null ; }
- /** This method sync the dataset if it has only ever been used non-transactionally.
- * Otherwise it silently does nothing.
- */
- public void syncIfNotTransactional()
- {
- if ( ! haveUsedInTransaction )
- getBaseDatasetGraph().sync() ;
+
+ public void syncIfNotTransactional()
+ {
+ if ( ! sConn.haveUsedInTransaction() )
+ sConn.getBaseDataset().sync() ;
}
+
@Override
protected void _begin(ReadWrite readWrite)
{
- synchronized(sConn)
- {
- syncIfNotTransactional() ;
- haveUsedInTransaction = true ;
- DatasetGraphTxn dsgTxn = sConn.begin(readWrite) ;
- txn.set(dsgTxn) ;
- inTransaction.set(true) ;
- }
+ DatasetGraphTxn dsgTxn = sConn.begin(readWrite) ;
+ txn.set(dsgTxn) ;
}
@Override
protected void _commit()
{
txn.get().commit() ;
- inTransaction.set(false) ;
}
@Override
protected void _abort()
{
txn.get().abort() ;
- inTransaction.set(false) ;
}
@Override
protected void _end()
{
txn.get().end() ;
- inTransaction.set(false) ;
txn.set(null) ;
}
@@ -171,6 +151,7 @@ public class DatasetGraphTransaction ext
try {
// Risky ...
return get().toString() ;
+ // Hence ...
} catch (Throwable th) { return "DatasetGraphTransactional" ; }
}
@@ -178,10 +159,12 @@ public class DatasetGraphTransaction ext
@Override
protected void _close()
{
- if ( ! haveUsedInTransaction && get() != null )
- get().sync() ;
- // Don't close the base dataset.
-// if (get() != null)
-// get().close() ;
+ if ( ! sConn.haveUsedInTransaction() && get() != null )
+ {
+ // Non-transactional behaviour.
+ DatasetGraphTDB dsg = get() ;
+ dsg.sync() ;
+ dsg.close() ;
+ }
}
}
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/TransactionManager.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/TransactionManager.java?rev=1348456&r1=1348455&r2=1348456&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/TransactionManager.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/TransactionManager.java Sat Jun 9 17:00:27 2012
@@ -340,12 +340,11 @@ public class TransactionManager
case WRITE : System.out.print("w") ; break ;
}
- // Even flush queue here.
-
DatasetGraphTDB dsg = baseDataset ;
// *** But, if there are pending, committed transactions, use latest.
if ( ! commitedAwaitingFlush.isEmpty() )
- { if ( DEBUG ) System.out.print(commitedAwaitingFlush.size()) ;
+ {
+ if ( DEBUG ) System.out.print(commitedAwaitingFlush.size()) ;
dsg = commitedAwaitingFlush.get(commitedAwaitingFlush.size()-1).getActiveDataset() ;
}
else
Modified: jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/assembler/TestTDBAssembler.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/assembler/TestTDBAssembler.java?rev=1348456&r1=1348455&r2=1348456&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/assembler/TestTDBAssembler.java (original)
+++ jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/assembler/TestTDBAssembler.java Sat Jun 9 17:00:27 2012
@@ -51,6 +51,7 @@ public class TestTDBAssembler extends Ba
@Before public void before()
{
+ StoreConnection.reset() ;
FileOps.clearDirectory(dirDB) ;
}
Modified: jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/graph/TestPrefixMappingTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/graph/TestPrefixMappingTDB.java?rev=1348456&r1=1348455&r2=1348456&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/graph/TestPrefixMappingTDB.java (original)
+++ jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/graph/TestPrefixMappingTDB.java Sat Jun 9 17:00:27 2012
@@ -20,15 +20,14 @@ package com.hp.hpl.jena.tdb.graph;
import java.util.Map ;
-import org.junit.AfterClass ;
-import org.junit.BeforeClass ;
-import org.junit.Test ;
+import org.junit.* ;
import org.openjena.atlas.lib.FileOps ;
import com.hp.hpl.jena.graph.Graph ;
import com.hp.hpl.jena.shared.PrefixMapping ;
import com.hp.hpl.jena.sparql.graph.AbstractTestPrefixMapping2 ;
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.TDBFactory ;
import com.hp.hpl.jena.tdb.base.file.Location ;
@@ -41,7 +40,11 @@ public class TestPrefixMappingTDB extend
static DatasetPrefixesTDB last = null ;
@BeforeClass public static void beforeClass() {}
- @AfterClass public static void afterClass() { ConfigTest.deleteTestingDir() ; }
+ @AfterClass public static void afterClass() { StoreConnection.reset() ; ConfigTest.deleteTestingDir() ; }
+
+ @Before public void before() { StoreConnection.reset() ; }
+ @After public void after() { }
+
@Override
protected PrefixMapping create()
Modified: jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestDatasetTDBPersist.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestDatasetTDBPersist.java?rev=1348456&r1=1348455&r2=1348456&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestDatasetTDBPersist.java (original)
+++ jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestDatasetTDBPersist.java Sat Jun 9 17:00:27 2012
@@ -23,6 +23,7 @@ import java.util.Arrays ;
import java.util.List ;
import org.junit.After ;
+import org.junit.AfterClass ;
import org.junit.Before ;
import org.junit.Test ;
import org.openjena.atlas.iterator.Iter ;
@@ -36,6 +37,7 @@ import com.hp.hpl.jena.query.Dataset ;
import com.hp.hpl.jena.sparql.sse.SSE ;
import com.hp.hpl.jena.sparql.util.NodeFactory ;
import com.hp.hpl.jena.tdb.ConfigTest ;
+import com.hp.hpl.jena.tdb.StoreConnection ;
import com.hp.hpl.jena.tdb.base.file.Location ;
import com.hp.hpl.jena.tdb.junit.GraphLocation ;
import com.hp.hpl.jena.tdb.sys.SystemTDB ;
@@ -58,6 +60,7 @@ public class TestDatasetTDBPersist exten
@Before public void before()
{
String dirname = nonDeleteableMMapFiles ? ConfigTest.getTestingDirUnique() : ConfigTest.getTestingDir() ;
+ StoreConnection.reset() ;
FileOps.ensureDir(dirname) ;
FileOps.clearDirectory(dirname) ;
graphLocation = new GraphLocation(new Location(dirname)) ;
@@ -72,6 +75,8 @@ public class TestDatasetTDBPersist exten
graphLocation.clearDirectory() ; // Does not have the desired effect on Windows.
}
+ @AfterClass public static void afterClass() { StoreConnection.reset() ; }
+
@Test public void dataset1()
{
Dataset ds = graphLocation.getDataset() ;