简体   繁体   English

如何在应用程序级别处理行锁争用

[英]How to handle row lock contention at application level

I have 2 applications (Spring - Hibernate with Boot) using same oracle database (11g). 我有2个使用相同的Oracle数据库(11g)的应用程序(Spring-带启动的休眠模式)。 Both apps hit a specific table consistently and there are huge number of hits on this table. 这两个应用程序一致地命中特定表,并且此表中的命中次数很多。 we can see row lock contention exceptions in the DB logs and applications have to be restarted each time we get these or when it creates a deadlock like situation. 我们可以看到数据库日志中的行锁争用异常,并且每当我们获取到它们时或在类似死锁的情况下必须重新启动应用程序。

we are using JPA entitymanager for these applications. 我们正在针对这些应用程序使用JPA实体管理器。 need help for this issue 需要此问题的帮助

According to this link : http://www.dba-oracle.com/t_enq_tx_row_lock_contention.htm 根据此链接: http : //www.dba-oracle.com/t_enq_tx_row_lock_contention.htm

This error occurs because a transaction is waiting for another transaction to commit or roll back ... This behavior is correct from the database POV and if you think of Data consistency ..... But if availability / fulfillment is a concern for you... You might need to make some work around including : 发生此错误的原因是,一个事务正在等待另一个事务提交或回滚...从数据库POV来看,如果您认为数据一致性.....则此行为是正确的。但是,如果可用性/实现对您来说很重要。 ..您可能需要解决一些问题,包括:

1 make separate tables for each of the application then update the main table with data offline (but u will sacrifice data consistency) 1为每个应用程序创建单独的表,然后使用离线数据更新主表(但是您会牺牲数据的一致性)

2 make a separate thread to log and retry unsuccessful transactions 2制作一个单独的线程来记录并重试不成功的事务

3 bear the availability issue (latency) if consistency is a big concern 3如果一致性是一个大问题,则要承担可用性问题(延迟)

Also there are some general tips to consider : 也有一些一般性提示要考虑:

1 make the transaction minimal ... Think about every process included in the transaction. 1使事务最小化。考虑事务中包含的每个过程。 If it's mandatory or can be removed outside 如果是强制性的或可以在外部删除

2 tune transaction demarcation ... U might find transaction open for long with no reason but bad coding 2调整事务分界...您可能无缘无故地发现事务开放,但编码错误

3 don't make read operations inside transactions 3不要在事务内部进行读取操作

4 avoid extended persistence context (stateless) whenever possible 4尽可能避免扩展持久性上下文(无状态)

5 u might choose to use non jta transactional data source for reporting and reading queries 5您可能选择使用非JTA事务性数据源来报告和读取查询

6 check the lock types you are using and try to avoid -according to your case- any thing but OPTIMISTIC 6检查您使用的锁类型,并尝试避免-根据您的情况-OPTIMISTIC以外的任何东西

But finally you agree with me we shouldn't blame the database from blocking two transactions from modifying the same row. 但是最后您同意我的看法,我们不应责怪数据库阻止两个事务修改同一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM