乐观并发控制和写入偏斜
Optimistic concurrency control and write skew
我觉得问这个问题有点蠢,但为了把事情弄清楚,有时必须问一些愚蠢的问题:)
因此,我们可以像 Martin Kleppmann 在他的演讲中所做的那样定义写入偏斜:
Write skew pattern:
1. read something
2. make a decision
3. write decision
By the time the write(3) is committed, the premise(1) of the decision(2) is no longer true
有一种悲观的做法,当我们基本上说"only one subject can use shared resource in a given moment, others should wait before the subject finishes"。
还有一种乐观的方法,其阶段如维基百科中所定义:
I. Begin: Record a timestamp marking the transaction's beginning.
II. Modify: Read database values, and tentatively write changes.
III. Validate: Check whether other transactions have modified data that this transaction has used (read or written). This includes transactions that completed after this transaction's start time, and optionally, transactions that are still active at validation time.
IV. Commit/Rollback: If there is no conflict, make all changes take effect. If there is a conflict, resolve it, typically by aborting the transaction, although other resolution schemes are possible.
我的问题是,我们有什么保证在验证 (III) 发生时不会写入新的 "knowledge",从而满足上面给出的写入偏斜的定义?
基本上,第三阶段的验证模块必须保留一些内部分类帐并以串行方式处理它们,以便在交易 1 写入事件之前不会发生交易 2 的检查过程。
我们是否刚刚将整个写倾斜问题下移了一个级别?所以我们在低层次上有一个可序列化的悲观方法,以便能够在更高层次上有一个乐观的方法?我弄错了什么吗?
如有任何说明,我将不胜感激。
要使乐观锁定工作,'III. Validate' 和 'IV. Commit/Rollback' 需要是单个原子操作。所以从这个意义上来说,是的"we just moved this whole problem of write skew one level down"。
但是,'II. Modify' 是数据库控制之外的用户操作,可能需要很长时间才能完成,并且无法通过数据库实现进行优化。 'III. Validate' 和 'IV. Commit/Rollback' OTOH 是由数据库实现的操作,可以通过数据库实现优化为快速。
我觉得问这个问题有点蠢,但为了把事情弄清楚,有时必须问一些愚蠢的问题:)
因此,我们可以像 Martin Kleppmann 在他的演讲中所做的那样定义写入偏斜:
Write skew pattern:
1. read something
2. make a decision
3. write decision
By the time the write(3) is committed, the premise(1) of the decision(2) is no longer true
有一种悲观的做法,当我们基本上说"only one subject can use shared resource in a given moment, others should wait before the subject finishes"。
还有一种乐观的方法,其阶段如维基百科中所定义:
I. Begin: Record a timestamp marking the transaction's beginning.
II. Modify: Read database values, and tentatively write changes.
III. Validate: Check whether other transactions have modified data that this transaction has used (read or written). This includes transactions that completed after this transaction's start time, and optionally, transactions that are still active at validation time.
IV. Commit/Rollback: If there is no conflict, make all changes take effect. If there is a conflict, resolve it, typically by aborting the transaction, although other resolution schemes are possible.
我的问题是,我们有什么保证在验证 (III) 发生时不会写入新的 "knowledge",从而满足上面给出的写入偏斜的定义?
基本上,第三阶段的验证模块必须保留一些内部分类帐并以串行方式处理它们,以便在交易 1 写入事件之前不会发生交易 2 的检查过程。
我们是否刚刚将整个写倾斜问题下移了一个级别?所以我们在低层次上有一个可序列化的悲观方法,以便能够在更高层次上有一个乐观的方法?我弄错了什么吗?
如有任何说明,我将不胜感激。
要使乐观锁定工作,'III. Validate' 和 'IV. Commit/Rollback' 需要是单个原子操作。所以从这个意义上来说,是的"we just moved this whole problem of write skew one level down"。
但是,'II. Modify' 是数据库控制之外的用户操作,可能需要很长时间才能完成,并且无法通过数据库实现进行优化。 'III. Validate' 和 'IV. Commit/Rollback' OTOH 是由数据库实现的操作,可以通过数据库实现优化为快速。