On 12 May 2011, at 15:27, P.Kremen wrote:
> Dear all,
Hi there,
> In a web app we are using SDB 1.3.4 with Hash layout backed by MySQL server
> ver. 5.1.49. For historical reasons, we are currently using only one DB
> connection (provided by commons-dbcp 1.4 BasicDataSource) that is wrapped to
> the Store object which is in turn shared and synchronized. Thus I believe,
> that the following code snippet initializes and uses SDB correctly (although
> I am aware that this setup is definitely not optimal - if there is time in
> future we would like to make a more sensible refactoring with a connection
> pool, etc.) - am I right ?
Without seeing getDataSource() it's not complete, but I don't see any obvious
issues. As you indicate, using only one connection may not be ideal.
> private static final StoreDesc storeDesc = new
> StoreDesc(LayoutType.LayoutTripleNodesHash,
> DatabaseType.MySQL);
> private final static Store store;
>
> static {
> JDBC.loadDriverMySQL();
> try {
> store = SDBFactory.connectStore(new
> SDBConnection(getDataSource()),storeDesc);
> if (!StoreUtils.isFormatted(store)) {
> store.getTableFormatter().create();
> }
> } catch (SQLException ex) {
> System.err.println("Exception occured when formatting a new
> store: " + ex.getMessage());
> throw new RuntimeException(ex);
> }
> }
>
> private Model getOntModel(String modelName) {
> synchronized (store) {
> return SDBFactory.connectNamedModel(store, modelName);
> }
> }
>
> The problem is that in a very non-deterministic manner
Uh-oh.
> we get
>
> com.hp.hpl.jena.sdb.SDBException: Exception flushing
>
> com.hp.hpl.jena.sdb.layout2.TupleLoaderBase.flush(TupleLoaderBase.java:220)
>
> com.hp.hpl.jena.sdb.layout2.TupleLoaderBase.finish(TupleLoaderBase.java:155)
>
> com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes.commitTuples(LoaderTuplesNodes.java:283)
>
> com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes.access$100(LoaderTuplesNodes.java:31)
>
> com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes$Commiter.run(LoaderTuplesNodes.java:318)
> java.lang.Thread.run(Thread.java:662)
> root cause
>
> java.sql.BatchUpdateException: Table 'tie.NNodeQuads' doesn't exist
>
> com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2020)
>
> com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1451)
>
> org.apache.commons.dbcp.DelegatingPreparedStatement.executeBatch(DelegatingPreparedStatement.java:205)
>
> com.hp.hpl.jena.sdb.layout2.TupleLoaderBase.flush(TupleLoaderBase.java:200)
>
> com.hp.hpl.jena.sdb.layout2.TupleLoaderBase.finish(TupleLoaderBase.java:155)
>
> com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes.commitTuples(LoaderTuplesNodes.java:283)
>
> com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes.access$100(LoaderTuplesNodes.java:31)
>
> com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes$Commiter.run(LoaderTuplesNodes.java:318)
> java.lang.Thread.run(Thread.java:662)
>
> What I understand from the source of TupleLoaderBase, the NNodeQuads table is
> only a temporary one. Thus it might be a race problem on the underlying mysql
> connection within SDB ?
What does your loading code look like?
Obvious question: you aren't closing the store anywhere, are you?
Next obvious question: could more than one thread be accessing the store at the
same time?
I see nothing wrong with what you're doing here, but it isn't a complete
example. Issues with mysql jdbc drivers isn't unheard off.
Damian