天天看点

数据库并行访问控制之互斥显示Netkiller MySQL 手札

中国广东省深圳市龙华新区民治街道溪山美地

518131

+86 13113668890

+86 755 29812080

文档始创于2010-11-18

版权 © 2011, 2012, 2013 netkiller(neo chan). all rights reserved.

<a></a>

版权声明

转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。

数据库并行访问控制之互斥显示Netkiller MySQL 手札

文档出处:

<a href="http://netkiller.github.io/" target="_top">http://netkiller.github.io</a>

<a href="http://netkiller.sourceforge.net/" target="_top">http://netkiller.sourceforge.net</a>

$date: 2013-04-10 15:03:49 +0800 (wed, 10 apr 2013) $

我的系列文档

<a href="http://netkiller.github.io/architect/index.html" target="_top">netkiller architect 手札</a>

<a href="http://netkiller.github.io/developer/index.html" target="_top">netkiller developer 手札</a>

<a href="http://netkiller.github.io/php/index.html" target="_top">netkiller php 手札</a>

<a href="http://netkiller.github.io/python/index.html" target="_top">netkiller python 手札</a>

<a href="http://netkiller.github.io/testing/index.html" target="_top">netkiller testing 手札</a>

<a href="http://netkiller.github.io/cryptography/index.html" target="_top">netkiller cryptography 手札</a>

<a href="http://netkiller.github.io/linux/index.html" target="_top">netkiller linux 手札</a>

<a href="http://netkiller.github.io/centos/index.html" target="_top">netkiller centos 手札</a>

<a href="http://netkiller.github.io/freebsd/index.html" target="_top">netkiller freebsd 手札</a>

<a href="http://netkiller.github.io/security/index.html" target="_top">netkiller security 手札</a>

<a href="http://netkiller.github.io/version/index.html" target="_top">netkiller version 手札</a>

<a href="http://netkiller.github.io/www/index.html" target="_top">netkiller web 手札</a>

<a href="http://netkiller.github.io/monitoring/index.html" target="_top">netkiller monitoring 手札</a>

<a href="http://netkiller.github.io/storage/index.html" target="_top">netkiller storage 手札</a>

<a href="http://netkiller.github.io/mail/index.html" target="_top">netkiller mail 手札</a>

<a href="http://netkiller.github.io/shell/index.html" target="_top">netkiller shell 手札</a>

<a href="http://netkiller.github.io/network/index.html" target="_top">netkiller network 手札</a>

<a href="http://netkiller.github.io/database/index.html" target="_top">netkiller database 手札</a>

<a href="http://netkiller.github.io/postgresql/index.html" target="_top">netkiller postgresql 手札</a>

<a href="http://netkiller.github.io/mysql/index.html" target="_top">netkiller mysql 手札</a>

<a href="http://netkiller.github.io/nosql/index.html" target="_top">netkiller nosql 手札</a>

<a href="http://netkiller.github.io/ldap/index.html" target="_top">netkiller ldap 手札</a>

<a href="http://netkiller.github.io/cisco/index.html" target="_top">netkiller cisco ios 手札</a>

<a href="http://netkiller.github.io/h3c/index.html" target="_top">netkiller h3c 手札</a>

<a href="http://netkiller.github.io/multimedia/index.html" target="_top">netkiller multimedia 手札</a>

<a href="http://netkiller.github.io/docbook/index.html" target="_top">netkiller docbook 手札</a>

<a href="http://netkiller.github.io/oss/index.html" target="_top">netkiller 开源软件 手札</a>

目录

<a href="http://192.168.6.2/architect/database/parallel.html#show">9.1. 防止并行显示</a>

背景

我们有一个order订单表,工作流如下

有多个岗位,每个岗位上有多个工作人员。需要实现相同岗位上的工作人员看到的订单不能重复,防止多人同时操作一个订单。

正常情况只要是多人一起打开订单页面就会显示上面的订单,并且每个人显示的内容都相同。

表 9.1. 工作流模拟

操作 订单审核员 a 订单审核员 b

显示未处理订单,这里模拟两个人同时点开页面的情景

首先查询出数据库中的前五条记录,然后更新为pending状态,防止他人抢占订单。

select的时候会被行级所挂起,直到被commit后才能查询出新数据,这是显示的数据是剩下的后5条

处理订单,模拟两个人点击审批通过按钮是的情景

更新状态pending到processing

处理成功与失败的情况

处理pending状态的订单,可能产生冲突,不用担心有行锁,防止重复处理。

有一种情况,用户查看了列表并未及时处理订单,就会有很多pending状态的订单,这是需要有人处理这些订单,但查询pending时,可能同一时刻有人在审批订单,我们通过排他锁避免重复处理。