Forum BigDB Race condition on creating record

Discussion and help relating to the PlayerIO database solution, BigDB.

Race condition on creating record

Postby robertflesch » February 22nd, 2017, 6:14 pm

When my game starts up, it checks for existing inventory.
If no inventory is found it adds two objects to the inventory
When the first object is added, a save is called, and since the databaseObject key is 0, create is called.
So now the app is continuing, and will handle a response from the database when it arrives.
Before the create responds, another object is added to the inventory, and a save is called on it.
The second save also sees a 0 database key, so it tries to create the object again.
Of course that results in a createFailure condition.

I see the the database object has a private member, isSaving, but I can't access it (and it does not seem to change after the create call is made).
I can imagine some ways around this, but none are pretty.
Suggestions?
robertflesch
Paid Member
 
Posts: 136
Joined: April 22nd, 2013, 9:18 pm

Re: Race condition on creating record

Postby Henrik » February 22nd, 2017, 10:15 pm

I'm not sure I completely understand your object structure, but I would use LoadKeysOrCreate to get a DatabaseObject, and use optimistic locking when saving it. That should completely eliminate all race conditions.
Henrik
.IO
 
Posts: 1827
Joined: January 4th, 2010, 1:53 pm

Re: Race condition on creating record

Postby robertflesch » February 23rd, 2017, 5:31 am

Thanks Henrik.

I will give that a try rather then using createObject.

Bet you are happy to be free of Yahoo...
robertflesch
Paid Member
 
Posts: 136
Joined: April 22nd, 2013, 9:18 pm


Return to BigDB