Running the Handler below I am getting very odd results. The number stored should increment, and it does, but it "bounces" around as it increases. I ran this in Postman eight times in about 5-6 seconds and this was the results in the order received.
10010, 10011, 10012, 10013, 10011, 10012, 10014, 10015
I assume this is a side effect of multiple front ends caching and/or replication delays on whichever KVP/NoSQL data store you are back-ending PlayFab with.
I can work around this problem by basically doing what you guys did in your Union example for Usernames that are already taken after I get the NextDefaultId. Even if I do end up with a collision due to several new customers connecting at the same time and getting the same key, I should be able to resolve the collision with a minimal number of calls.
So my question(finally) is should I expect this behavior when calling directly to the various data stores from the client API or is this just a CloudScript Server issue? I ask because this will drastically change how I handle data that updates often.
// Account management handlers handlers.GetDefaultUsername = function(args) { var titleData = server.GetTitleData({ "Keys" : "Key_NextDefaultID" }); var next = parseInt(titleData.Data["Key_NextDefaultID"]) + 1; server.SetTitleData({ Key: "Key_NextDefaultID", Value: next }); return { nextDefaultId : titleData.Data["Key_NextDefaultID"] } }