Forum BigDB Objects being reverted to a past state

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

Objects being reverted to a past state

Postby robscherer123 » December 21st, 2013, 4:42 pm

I've had a strange problem with this before, and found out it was probably related to the rooms not closing bug. However now I have a problem that I'm really not sure why it's happening, and I'm not sure it's related to that. Maybe I'm overlooking something crazy, but it's pretty simple and I can't see how it could be happening.

This isn't happening very often, but it's happening enough and to certain players continuously. I have things in my game called "pets" and they gain XP, health, etc. A player trains them and they get stronger. What is happening is a small amount of players are reporting that their "pets" are reverting to a past state. For example a players pet will reach level 40, they will play for maybe even a few hours, change rooms, etc, then the pets data will randomly revert to the data it had hours ago (for example level 32). I've even see if happen myself. The new data will show up in the admin panel for the table, and then seemingly at a random point, it will change back to an older state. It generally gets stuck reverting to the same certain state.

The main thing that's got me confused is that I put in some server code to prevent this from happening even in weird cases, but it's still not preventing it. Below is a small example:


Code: Select all
PlayerIO.BigDB.Load("petData", _pet.Name, delegate(DatabaseObject _dbPet){
      if (_dbPet != null && _pet.xp >= _dbPet.GetInt("xp")) {
            _dbPet.Set("xp", _pet.xp);

            _dbPet.Save();
       }
});



You can see on the second line that I check to NEVER save a pet into the database if its XP is less than whats stored in the database. Nonetheless, it is still somehow reverting to that past version which contains less XP, so I don't see how I could be saving to an older version. The client does not have access to any other rights on the table other than loading. I do not save to this table anywhere else other than here. Any help or feedback would be much appreciated.
robscherer123
Paid Member
 
Posts: 313
Joined: December 12th, 2012, 8:46 pm

Re: Objects being reverted to a past state

Postby Henrik » January 3rd, 2014, 5:15 am

Why not use the built-in optimistic locking of BigDB? It ensures that writes fail if the object you have locally is out-of-date.

http://playerio.com/documentation/bigdb/advanced
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Objects being reverted to a past state

Postby robscherer123 » January 3rd, 2014, 2:26 pm

Hmm.. Thanks for the reply. I never though of that, I will give it a try. I thought optimistic locking was more for objects that were being saved often from multiple players at the same time. My object on the other hand should only ever be saved from the actual player, no one else. Regardless, I will give this a try, maybe it will fix it.
robscherer123
Paid Member
 
Posts: 313
Joined: December 12th, 2012, 8:46 pm


Return to BigDB



cron