天天看點

資料庫并行通路控制之互斥顯示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時,可能同一時刻有人在審批訂單,我們通過排他鎖避免重複處理。