MySQL race? (when a player takes anothers id while query is still running)
#1

Hello everyone,
I am following BlueGs example on using MySQL: https://github.com/pBlueG/SA-MP-MySQ...stem-cache.pwn

I can't wrap my head around the MySQL race solution he has to the problem:
(lines: 234-236)
player A connects -> SELECT query is fired -> this query takes very long
while the query is still processing, player A with playerid 2 disconnects
player B joins now with playerid 2 -> our laggy SELECT query is finally finished, but for the wrong player

He goes on to say the solution to this is:
(lines 239-242)
we create a connection count for each playerid and increase it everytime the playerid connects or disconnects
we also pass the current value of the connection count to our OnPlayerDataLoaded callback
then we check if current connection count is the same as connection count we passed to the callback
if yes, everything is okay, if not, we just kick the player

I don't understand how this is going to stop the problem (I know it is a solution, but I don't understand it.).
I would really appreciate it if someone could put this in other words.
Thanks in advance!
Reply
#2

Take a real example:

• Player_1 connects to the server.
• We increase mysql_race and it becomes 1.
• Query takes too long and Player_1 disconnects.
• We increase once again mysql_race and it becomes 2.
• Player_2 connects to the server.
• We increase mysql_race and it becomes 3.
• Finally the query is finished and it's the moment of truth.
mysql_race that was passed in mysql callback is 1 != mysql_race of current player which is 3 so the query was for Player_1 but disconnected and Player_2 connected but it is the wrong person.
Reply
#3

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
Take a real example:

• Player_1 connects to the server.
• We increase mysql_race and it becomes 1.
• Query takes too long and Player_1 disconnects.
• We increase once again mysql_race and it becomes 2.
• Player_2 connects to the server.
• We increase mysql_race and it becomes 3.
• Finally the query is finished and it's the moment of truth.
mysql_race that was passed in mysql callback is 1 != mysql_race of current player which is 3 so the query was for Player_1 but disconnected and Player_2 connected but it is the wrong person.
Thank you very much! I tried giving you reputation but it said to spread it more before i give it to you again. Thanks again!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)