Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure obtaining db row lock: Lock wait timeout exceeded; try restarting transaction #268

Closed
ariawanzero opened this issue Oct 18, 2018 · 5 comments

Comments

@ariawanzero
Copy link

I'm using quartz on my java project with version 2.2.3 and getting This Error

org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: Lock wait timeout exceeded; try restarting transaction

  | at org.quartz.impl.jdbcjobstore.StdRowLockSemaphore.executeSQL(StdRowLockSemaphore.java:157)
  | at org.quartz.impl.jdbcjobstore.DBSemaphore.obtainLock(DBSemaphore.java:113)
  | at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3796)
  | at org.quartz.impl.jdbcjobstore.JobStoreSupport.triggersFired(JobStoreSupport.java:2916)
  | at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:336)
  | Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
  | at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  | at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  | at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  | at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  | at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
  | at com.mysql.jdbc.Util.getInstance(Util.java:408)
  | at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:951)
  | at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
  | at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
  | at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
  | at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
  | at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2487)
  | at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
  | at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1966)
  | at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
  | at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
  | at org.quartz.impl.jdbcjobstore.StdRowLockSemaphore.executeSQL(StdRowLockSemaphore.java:96)
  | ... 4 common frames omitted

Anyone have solution for this?

@zemian
Copy link
Contributor

zemian commented Dec 18, 2018

Can you share your quartz.properties and is there any special DB configuration you used?

@ariawanzero
Copy link
Author

ariawanzero commented Jan 29, 2019

Sorry for late response @zemian because the problem appear again

private Properties getQuartzProperties() {
Properties props = new Properties();
props.put("org.quartz.scheduler.instanceName", "ClusteredScheduler");
props.put("org.quartz.scheduler.instanceId", "AUTO");
// props.put("org.quartz.jobStore.misfireThreshold", "1000");
props.put("org.quartz.jobStore.class", "com.btpn.common.util.quartz.CustomJobStore");
props.put("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.StdJDBCDelegate");
props.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
props.put("org.quartz.jobStore.isClustered", "true");
props.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
props.put("org.quartz.threadPool.threadCount", "25");
props.put("org.quartz.threadPool.threadPriority", "5");
props.put("org.quartz.scheduler.skipUpdateCheck", "true");
return props;
}

I'm using mysql 5.7 with standard configuration and it problem appear again do you have any solution

@zemian
Copy link
Contributor

zemian commented Feb 16, 2019

Hi @ariawanzero

This means your DB is not able to acquire the proper lock using the QRTZ_LOCKS table.
Can you try to enable DEBUG level on in your scheduler and check the output by org.quartz.impl.jdbcjobstore.StdRowLockSemaphore class logger? This would tell you which lock
name and how many times it retried and failed.

Also tell us the workload of your quartz scheduler (how many jobs do you have running, how long does each job run on avg etc.) when this problem occur.

@zemian
Copy link
Contributor

zemian commented Feb 16, 2019

I also noticed you have a custom jobStore class com.btpn.common.util.quartz.CustomJobStore. We won't able to debug what's in there. Please use a one quartz provided (eg: org.quartz.impl.jdbcjobstore.JobStoreTX) and reproduce the problem.

@zemian
Copy link
Contributor

zemian commented Feb 19, 2019

It seems like this failure error will occur only when the load is too heavy and the DB is not able to acquire the DB lock within the time allowed to handle the work. I have added a PR #363 as improvement that allow you to configure the maxRetry and retryTimeout (in millis) parameters to avoid this error message. To use it, you need to get latest code and add the following to quartz configuration:

org.quartz.jobStore.lockHandler.class=org.quartz.impl.jdbcjobstore.StdRowLockSemaphore
org.quartz.jobStore.lockHandler.maxRetry=7
org.quartz.jobStore.lockHandler.retryPeriod=3000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants