交易&锁问题
在 do 事务中,我定义了一个标签,在这个标签中我正在访问带有独占锁的表。在标签末尾我已经完成了该表中的所有更改。 bt 现在我在交易块中。 现在,我尝试在另一个会话中访问同一个表。然后它显示错误,表已被另一个用户使用。那么我们是否可以在事务中释放该表,以便其他用户可以访问它。
例如:
会话 1)
DO TRANSACTION:
---
---
loopb:
REPEAT:
--
--
---------------------> control is here right now.
END. /*repeat*/
--
--
END. /*do transaction*/
会话 2)
我尝试访问同一个表,但它显示错误,该表被另一个用户锁定。
with in do transaction, i defined a label and in this label i am accessing a table with exclusive-lock.and at the end of label i have done all the changes in that table. bt now i am with in transaction block.
Now, i tried to access that same table in another session.then it show an error, Table used by another user. So is it possible that, can we release teh table with in transaction,so another user can access it.
For example:
Session 1)
DO TRANSACTION:
---
---
loopb:
REPEAT:
--
--
---------------------> control is here right now.
END. /*repeat*/
--
--
END. /*do transaction*/
Session 2)
I tried to access same table, but it show an error, that table locked by another user.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
TRANSACTION
完成之前,您在循环中使用EXCLUSIVE-LOCK
触及的所有记录将无法被其他用户锁定。这是无法回避的。如果第二个进程需要锁定这些记录,那么您所能做的就是减少第一个进程中的TRANSACTION
范围。这是一项安全功能,因此,如果稍后在TRANSACTION
中发生错误,所有在TRANSACTION
期间所做的更改都将回滚。另一种看待它的方法是,如果您可以在TRANSACTION
期间释放一些记录锁,您将失去作为TRANSACTION< 定义的一部分的原子性(全有或全无) /代码>。
应该注意的是,如果您并不真正需要在第二个进程中锁定这些记录,而只是需要查看它们的更新值,那么这是可能的。一旦更新的记录不再存在于记录缓冲区中(或者在
TRANSACTION
中记录锁定状态降级为NO-LOCK
),它们将变成 Limbo Lock,您将被锁定。可以使用NO-LOCK
查看其更新值。要使循环中的最后一条记录成为临时锁,如果您不再需要访问记录缓冲区,您可以这样做或这样做:
All those records you touched in the loop using
EXCLUSIVE-LOCK
will not be available to be locked by another user until theTRANSACTION
is complete. There is no getting around this. If the second process needs to lock those records, then all you can do is decrease yourTRANSACTION
scope in the first process. This is a safety feature so that if an error happens later on in theTRANSACTION
, all the changes made during theTRANSACTION
will be rolled back. Another way to look at it is if you could release some record locks during aTRANSACTION
, you would lose the atomicity (all-or-nothingness) that is part of the definition of aTRANSACTION
.It should be noted that if you don't really need to lock those records in the second process but just need to see their updated value, that is possible. Once the updated records are no longer in the record buffer (or the record lock status is downgraded to a
NO-LOCK
in theTRANSACTION
), they will become limbo locks and you can view their updated values using aNO-LOCK
. To make the last record in the loop become a limbo lock, you can either do thisOr this, if you do not need to access the record buffer any longer:
其他会话可以使用NO-LOCK 对记录进行“脏读”。但在提交(或回滚)事务之前,他们将无法锁定或更新它。在重复块迭代或您离开它之前,这种情况不会发生。
Other sessions can do a "dirty read" of the record using NO-LOCK. But they will not be able to lock it or update it until the transaction is committed (or rolled back). And that won't happen until the repeat block iterates or you leave it.