You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Hugi Thordarson <hu...@karlmenn.is> on 2016/03/02 13:22:58 UTC

MariaDB: "Table was not locked with LOCK TABLES" (mutithreaded code)

Hi all,
when I’m running multithreaded code (at least I think that’s the trigger, since this seems to mostly happen when I have a long running background task talking to the DB in a different thread) I tend to get these errors:

Table ‘…' was not locked with LOCK TABLES.

I just wanted to check if anyone else has encountered this issue, before I start digging in. Google has some suggestions for how to fix this when writing plain SQL, but I’m not sure how to handle locking when using Cayenne.

Here’s a stack trace:

Exception in thread "pool-1-thread-1" org.apache.cayenne.CayenneRuntimeException: [v.4.0.M3-SNAPSHOT Oct 12 2015 13:17:37] Commit Exception
	at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:776)
	at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:693)
	at strimillinn.core.dictionary.DictionaryListener.handleEntryChange(DictionaryListener.java:129)
	at strimillinn.core.dictionary.DictionaryPopulator.lambda$null$4(DictionaryPopulator.java:55)
	at strimillinn.core.dictionary.DictionaryPopulator$$Lambda$8/21061839.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.BatchUpdateException: Table 'fd_commit' was not locked with LOCK TABLES
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1819)
	at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1281)
	at org.apache.cayenne.access.jdbc.BatchAction.runAsBatch(BatchAction.java:125)
	at org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:90)
	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:97)
	at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:306)
	at org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:234)
	at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:155)
	at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:643)
	at org.apache.cayenne.access.DataDomain$2.perform(DataDomain.java:608)
	at org.apache.cayenne.access.DataDomain$2.perform(DataDomain.java:605)
	at org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:45)
	at org.apache.cayenne.access.DataDomain.onSyncNoFilters(DataDomain.java:605)
	at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:760)
	at org.apache.cayenne.lifecycle.postcommit.PostCommitFilter.onSync(PostCommitFilter.java:87)
	at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:760)
	at org.apache.cayenne.lifecycle.postcommit.PostCommitFilter.onSync(PostCommitFilter.java:87)
	at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:760)
	at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:586)
	at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:744)
	at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:693)
	at strimillinn.core.db.listeners.CommitListener.onPostCommit(CommitListener.java:43)
	at org.apache.cayenne.lifecycle.postcommit.PostCommitFilter.notifyListeners(PostCommitFilter.java:114)
	at org.apache.cayenne.lifecycle.postcommit.PostCommitFilter.onSync(PostCommitFilter.java:89)
	at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:760)
	at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:586)
	at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:744)
	... 7 more
Caused by: java.sql.SQLException: Table 'fd_commit' was not locked with LOCK TABLES
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2535)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1911)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2145)
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1777)

Cheers,
- hugi


Re: MariaDB: "Table was not locked with LOCK TABLES" (mutithreaded code)

Posted by Andrus Adamchik <an...@objectstyle.org>.
Haven't seen it. If you find the cause (especially if it points to Cayenne), please share.

Andrus

> On Mar 2, 2016, at 3:22 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
> 
> Hi all,
> when I’m running multithreaded code (at least I think that’s the trigger, since this seems to mostly happen when I have a long running background task talking to the DB in a different thread) I tend to get these errors:
> 
> Table ‘…' was not locked with LOCK TABLES.
> 
> I just wanted to check if anyone else has encountered this issue, before I start digging in. Google has some suggestions for how to fix this when writing plain SQL, but I’m not sure how to handle locking when using Cayenne.
> 
> Here’s a stack trace:
> 
> Exception in thread "pool-1-thread-1" org.apache.cayenne.CayenneRuntimeException: [v.4.0.M3-SNAPSHOT Oct 12 2015 13:17:37] Commit Exception
> 	at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:776)
> 	at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:693)
> 	at strimillinn.core.dictionary.DictionaryListener.handleEntryChange(DictionaryListener.java:129)
> 	at strimillinn.core.dictionary.DictionaryPopulator.lambda$null$4(DictionaryPopulator.java:55)
> 	at strimillinn.core.dictionary.DictionaryPopulator$$Lambda$8/21061839.run(Unknown Source)
> 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> 	at java.lang.Thread.run(Thread.java:745)
> Caused by: java.sql.BatchUpdateException: Table 'fd_commit' was not locked with LOCK TABLES
> 	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1819)
> 	at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1281)
> 	at org.apache.cayenne.access.jdbc.BatchAction.runAsBatch(BatchAction.java:125)
> 	at org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:90)
> 	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:97)
> 	at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:306)
> 	at org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:234)
> 	at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:155)
> 	at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:643)
> 	at org.apache.cayenne.access.DataDomain$2.perform(DataDomain.java:608)
> 	at org.apache.cayenne.access.DataDomain$2.perform(DataDomain.java:605)
> 	at org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:45)
> 	at org.apache.cayenne.access.DataDomain.onSyncNoFilters(DataDomain.java:605)
> 	at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:760)
> 	at org.apache.cayenne.lifecycle.postcommit.PostCommitFilter.onSync(PostCommitFilter.java:87)
> 	at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:760)
> 	at org.apache.cayenne.lifecycle.postcommit.PostCommitFilter.onSync(PostCommitFilter.java:87)
> 	at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:760)
> 	at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:586)
> 	at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:744)
> 	at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:693)
> 	at strimillinn.core.db.listeners.CommitListener.onPostCommit(CommitListener.java:43)
> 	at org.apache.cayenne.lifecycle.postcommit.PostCommitFilter.notifyListeners(PostCommitFilter.java:114)
> 	at org.apache.cayenne.lifecycle.postcommit.PostCommitFilter.onSync(PostCommitFilter.java:89)
> 	at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:760)
> 	at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:586)
> 	at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:744)
> 	... 7 more
> Caused by: java.sql.SQLException: Table 'fd_commit' was not locked with LOCK TABLES
> 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
> 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835)
> 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771)
> 	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
> 	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
> 	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2535)
> 	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1911)
> 	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2145)
> 	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1777)
> 
> Cheers,
> - hugi
>