I recently described a game scenario where a game is initiated by a player and then the first other player who subscribes to the game will play it.
The structure is basic : nodes for games and players, and a
player predicate from a game to a player.
I don’t know how to use upserts in that scenario, as it only applies to indexes on literals, and it could generate a lot of aborted transactions as there will be (hopefully) a lot of game creations and subscriptions.
My current solution is to add a nano-timestamp as a facet to each
player predicate and then only keep the N firsts to subscribe based on the timestamp.
But I can imagine a scenario where it fails, I’m just not sure it can happen.
Here is such a scenario with games allowing maximum 2 players:
- Player A creates game G
- Player B finds game G available
- Player C finds game G available
- Player B generates a timestamp T1
- Player C generates a timestamp T2 (greater than T1)
- Player C updates the game with his
playerpredicate and the T2 timestamp
- Player C queries the game to check if he’s the first to subscribe
- Player C seems to be the first, the game start
- Player B updates the game with his
playerpredicate and the T1 timestamp
- Player B queries the game to check if he’s the first to subscribe
- Player B find himself and player C as subscribers, but as his timestamp T1 is lesser than T2, he thinks he is the first so he also plays the game
Does this can happen?