3

We have a transaction that is modifying a record. The transaction must call a web service, rolling back the transaction if the service fails (so it can't commit it before hand). Because the record is modified, the client app has a lock on it. However, the web service must retrieve that record to get information from it as part of it's processing. Bam, deadlock.

We use websphere, which, for reasons that boggle my mind, defaults to repeatable read isolation level. We knocked it down to read_committed, thinking that this would retrieve the row without seeking a lock. In our dev environment, it seemed to work, but in staging we're getting deadlocks.

I'm not asking why it behaved differently, we probably made a mistake somewhere. Nor am I asking about the specifics of the web service example above, because obviously this same thing could happen elsewhere.

But based on reading the docs, it seems like read_committed DOES acquire a shared lock during read, and as a result will wait for an exclusive lock held by another transaction (in this case the client app). But I don't want to go to read_uncommitted isolation level because I don't want dirty reads. Is there a less extreme solution? I need some middle ground where I can perform reads without any lock-waiting, and retrieve only committed data.

Is there such a goldilocks solution? Not too deadlock-y, not too dirty-read-y? If not in siolation level, maybe some modifier I can tack onto my SQL? Anything?

4

2 回答 2

1

我假设您说的是 jdbc 隔离级别,而不是 db2。read_committed(db2 中的游标稳定性)和 repeatable_read(读稳定性)之间的区别在于共享锁的保留时间。repeatable_read 保留满足谓词的每个锁,而 read_committed 只保留锁,直到找到与谓词匹配的另一行。

你比较过计划吗?如果计划不同,您最终可能会有不同的行为。

是否有任何升级发生?

您是否尝试过 CURRENTLY_COMMITTED(假设您使用的是 9.7+)?

Precurrent_committed 那里有以下设置,DB2_SKIPINSERTED、DB2_EVALUNCOMMITTED 和 DB2_SKIPDELETED

于 2014-06-09T03:36:46.137 回答
0

读取已提交行的最低隔离级别是已提交的。

通常,您会像这样处理 DB2 数据库中的行:

  1. 读取没有读取锁的数据库行(具有读取提交的普通 SELECT)。
  2. 处理数据,以便您拥有更改值的行。
  3. 使用读锁再次读取数据库行。(选择更新)
  4. 检查以查看 1 中的数据库行。与 3 中的数据库行匹配。
  5. 如果行匹配,则更新数据库行。
  6. 如果行不匹配,则释放更新锁并返回 2。
于 2014-06-08T21:10:38.173 回答