Race Condition
Posted by:
zso cii
Date: October 28, 2008 08:32AM
Hi there.
Admitting to be a newbie here, just started with MySQL and need help.
I have the following SP:
CREATE DEFINER=`root`@`localhost` PROCEDURE `LoginUser`(PLoginName VARCHAR(10),PPassWord VARCHAR(10), PInternalID INT)
BEGIN
SELECT Name, DBId, Country, UserType, InternalId, FlagIndex, Image FROM Users
WHERE LoginName = PLoginName and Password = PPassWord FOR UPDATE;
UPDATE Users SET InternalId = PInternalId, LastLogin = Now()
WHERE LoginName = PLoginName and Password = PPassWord;
COMMIT;
END
Initially the InternalId Fields are set to -1.
I call this SP from 10+ threads at the "same" time with same PLoginName and PPasword but different PInternalId parameters.
Sometimes the InternalId field in resultsets I am getting back contains the same value. E.g. two times I am getting back the same InternalId, however all results shall have different InternalId, as no duplicates happens in the parameter.
It seems I need to lock the table, but this is not efficient in my case. Is there a exclusive rowlock clause for the select statement that would solve this challenge within a transaction?
Thanks in advance,
regards
Zsocii
Edited 1 time(s). Last edit at 10/29/2008 03:12AM by zso cii.
Subject
Views
Written By
Posted
Race Condition
2179
October 28, 2008 08:32AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.