I'm trying to implement a concept of a shared server session resource that multiple clients can submit progress to in order to decrement a counter. I've seen some threads from years ago about how in other DB backends, you could use the builtin atomic increment and decrement operations for numbers, but not much about the GameDataService save this: https://support.gamesparks.net/support/discussions/topics/1000087787.
However, from this thread, I'm not sure if itemPersistor.withVersionCheck() is what I want, because it seems like the pattern there is to just have cloud code keep attempting to update and submit. I see in the documentation that there is a itemPersistor.withAtomicIncrements() method, but the wording around it is very ambiguous, as I don't want to update the record from "the original value", but rather the new value right at the time that I'm trying to perform my transaction.
Has anybody else had luck implementing atomic transactions in the new GameDataService?
Bump. 1 month and no response.
I also have a similar problem.
How can we do atomic operations with GameDataService?
Seems like we will be forced to stick with MongoDB since GDS does not support this.
I actually got a response from support directly and forgot to post here. It turns out the ItemPersistor.withAtomicIncrements() method works as follows: it records the state of the adjusted numerical property at the start of the operation and at the end and creates a diff between the two numbers. Then it applies that diff to the numeral property with a lock. So in essence, it does guarantee a degree of atomicity, it's just not very explicit about it.
IMO this is not the only place I've found the GameSparks documentation to be sorely lacking, but not much to be done there unless support wants to be more responsive or make a large scale documentation overhaul a primary initiative. It's frustrating to say the least.
I'm a little confusing though on your response, sorry.
what does " at the start of the operation" mean? at the start of which operation?
What do you mean by diff? Can you maybe give a simple example?
Thanks so much for your help.
Were you able to adopt the GameDataService over Mongo? What about querying limits of 100, did you get around that with a hack?
Sure, let me clarify.
From what I understand, let's say I have two players attacking a boss using the cloud code event "AttackBoss". Both players submit the network event at the same time, during which the HP is 100. Player 1 will see the HP at 100, decrement it to 90 in the cloud code, and persist the entry to the GDS. Player 2 will see similar numbers. On the GDS side, b/c we used "withAtomicIncrements", it won't see the health being set as 90, but instead see that a diff of -10 was applied in both operations, so it will apply -10 twice to the Boss health, resulting in 80.
Our project is not live yet, so I can't speak to whether or not we hit the query limit (nor am I able to tell from the docs over what timeframe that limit is imposed), but I can assume that for the live project that query limit will not exist. I can't say whether or not MongoDB or the GDS is better either because we actually started development after the GDS became the accepted solution. Sorry I can't give you any more help :(