Mysql locks for load and save in a turnbased rts?

Hi!
I am programming a turnbased andriod rts that is quite done and is working.
In the game you have some units and buildings on a gridmap and move them around and then you click send turn.
In the multiplayer screen you can your games and whos turn it is, you can load and view a game even if it is not your turn.

Now if you load the game what happens is that the webbserver will perfom a lot of select where clauses on different database tables ( like troop, building_type1 etc etc), merge these and send back an array. And if the player whos turn it is send his game then the webbserver will perform a lot of insert statements on these tables. These tables all relate to a game table which stores the game. These are InnoDB tables so they have internal row lock. The webbserver is in php and uses a mysqli transaction with rollback if any insert fails.

Now i wonder if it can occur a deadlock if one player sends his turn, doing inserts, whilst the other player reads the game, doing select statements? What i have seen is that locks is only necessary if you read then write a value within the same transaction, but that is not really what i am doing. So i am unsure if i need to add locks, also all inserts are send in to the webbserver as seperate request, so i can modify and view the tables with tool programs, instead of sending in all units and have the webbserver perform a insert game transaction.

Most of the time, innoDB’ll take care of that for you.

The only thing you’ve to take care is about updating elements ONLY if it’s the correct player who send his commands (in case of a turn based)
If the other player read the game while updating, then innoDB’ll send the state whitout all modifications because these modifications are applyed only when you commit.

So you can’t get half update information, it’s atomic (all the info updated, or no info updated)

The only way to be sure that client get information only after update is to send to him when update is done, not the other way around (ie client is requesting data, no matter it was updated or not)
Look at pubnub (or other push services) on how you can push data to a specified client (or you can create your own server with node.js and socket.io for example)

I’ve a small library to get pubsub work with unity somewhere, maybe I can clean it and post it here…

Okay thanks, maybe i rework so that the client send all information in one single array and the webbserver makes one transaction. Right now the client code takes care that it will not be any updated if it is not that players turn.
Yes i initially wanted a push feature, but it seems to hard ( to much time to reasearch and implement a solution) for turnbased andriod untiy3d games where the responder might not have his game running. So i have a refresh button in the menu for seeing games.

The clients never stores the games on their drives, they request them from the database server via the webbserver.

On a side note i would want notification service for andriod when a turn is done, but haven’t found any of how to do this, more precisely i don’t know what contact info i should store in the database for the notification service seance the clients communicate with http post fields to the webbserver right now.

If you take care of the player turn only client side, personnaly I’ll hack it juste for the fun of it.

Checking important conditions only in an unsafe environnement can lead to catastrophic things like playing when you’re not allowed to (so playing as the other player to do what you want him to do)

Remember that all code that run on a machine you don’t own must be treated as unsafe, so allways recheck on server side!

For all your other questions, take a look at push services. If you prefer spending your time on solving problems that don’t have to exist instead of learning something about a real solution for your problem, it’s your choice, and nobody can learn something for you.