交易&锁问题

发布于 2024-09-04 20:54:21 字数 456 浏览 6 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一城柳絮吹成雪 2024-09-11 20:54:21

TRANSACTION 完成之前,您在循环中使用 EXCLUSIVE-LOCK 触及的所有记录将无法被其他用户锁定。这是无法回避的。如果第二个进程需要锁定这些记录,那么您所能做的就是减少第一个进程中的 TRANSACTION 范围。这是一项安全功能,因此,如果稍后在 TRANSACTION 中发生错误,所有TRANSACTION 期间所做的更改都将回滚。另一种看待它的方法是,如果您可以在 TRANSACTION 期间释放一些记录锁,您将失去作为 TRANSACTION< 定义的一部分的原子性(全有或全无) /代码>。

应该注意的是,如果您并不真正需要在第二个进程中锁定这些记录,而只是需要查看它们的更新值,那么这是可能的。一旦更新的记录不再存在于记录缓冲区中(或者在 TRANSACTION 中记录锁定状态降级为 NO-LOCK),它们将变成 Limbo Lock,您将被锁定。可以使用NO-LOCK查看其更新值。要使循环中的最后一条记录成为临时锁,

FIND CURRENT tablerecord NO-LOCK.

如果您不再需要访问记录缓冲区,您可以这样做或这样做:

RELEASE tablerecord.

All those records you touched in the loop using EXCLUSIVE-LOCK will not be available to be locked by another user until the TRANSACTION is complete. There is no getting around this. If the second process needs to lock those records, then all you can do is decrease your TRANSACTION scope in the first process. This is a safety feature so that if an error happens later on in the TRANSACTION, all the changes made during the TRANSACTION will be rolled back. Another way to look at it is if you could release some record locks during a TRANSACTION, you would lose the atomicity (all-or-nothingness) that is part of the definition of a TRANSACTION.

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 the TRANSACTION), they will become limbo locks and you can view their updated values using a NO-LOCK. To make the last record in the loop become a limbo lock, you can either do this

FIND CURRENT tablerecord NO-LOCK.

Or this, if you do not need to access the record buffer any longer:

RELEASE tablerecord.
伴梦长久 2024-09-11 20:54:21

其他会话可以使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文