English 中文(简体)
更新账户余额与我的账面
原标题:Updating account balances with mysql

I have a field on a User table that holds the account balance for the user. Users can perform a lot of actions with my service that will result in rapid changes to their balance.

I m trying to use mysql s serializable isolation level to make sure that multiple user actions will not update the value incorrectly. (Action A and action B simultaneously want to deduct 1 dollar from the balance.) However, I m getting a lot of deadlock errors.

我如何在不打破所有这些僵局的情况下正确这样做,并且仍然保持平衡。

simple schema: user has an id and a balance.

im using doctrine, so i m doing something like the following:

$con->beginTransaction();
$tx = $con->transaction;
$tx->setIsolation( SERIALIZABLE );

$user = UserTable::getInstance()->find($userId);
$user->setBalance($user->getBalance() + $change);
$user->save();
$con->commit();
问题回答

首先试图在您的交易中使用可序列的孤立程度,是一个好的想法。 这意味着你们至少知道什么是移植,孤立程度是最大的问题之一。

注:序列可查实际上不是真正的可核实性。 https://stackoverflow.com/questions/6269471/does-mysql-innodb-implement-true-serializable-isolation/8112871#8112871"。

但最重要的部分是,你应认为,由于无法连续经营而自动收回你的交易是正常的事实,这样做的正确之处在于你提出申请,以便交易能够失败,并且应当重新加以考虑。

一种简单的解决办法,对于像这种简单的解决办法一样,因为我们可以预测所有事实,没有证据,因此,一种解决办法是履行<>固定钟>。 这不是一种微薄和低劣的解决方案,没有锁定增长水平,只是简单的大桌锁(总是按同一顺序排列)。 之后,你可以发挥单一角色的作用,然后释放茶叶。 表各行各行各行各业的用户并不多,下行各行各庭均无故障(见以前的链接)。 这必然会减慢你的书写工作,但如果每个人都按同样顺序坐在桌上,那么你就只能停下时间,不陷入僵局,不出现无法驾车的退步。

<><>Edit>/strong>

缩略语 我不敢肯定你可以确定交易孤立程度 > 开始。 您应启动MySQL的查询记录,然后检查由CMS管理的其他交易仍然处于可序列的水平。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...