Forum BigDB Possible caching issue?

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

Possible caching issue?

Postby jak322 » November 24th, 2010, 2:41 pm

Hi everyone, I'm having an issue with a DB query returning a result which is out of date, here is the server side code.

Code: Select all

//Get waiting players in order of largest party
PlayerIO.BigDB.LoadRange("matchmaking", "partyCount", null, 18, 1, 100, delegate(DatabaseObject[] result) {

    for(int i = 0; i <= result.Length - 1; i ++) {

        //Attempt to place this person / party in an existing game
        /* DEV NOTICE - ACTUAL SETUP ONLY PLACES FIRST ARRAY ELEMENT (FIRST FBUID) INTO GAME, SEE [0] BELOW */
        string curFBUID = result[i].GetArray("facebookUIDs")[0].ToString();
        Console.WriteLine("Attempting to place " + curFBUID + " in an existing game");
        PlayerIO.BigDB.LoadRange("activeGames", "totalFreeSlots", null, 18, result[i].GetInt("partyCount"), 1, delegate(DatabaseObject[] resultEG) {

            if(resultEG.Length > 0) {

                //Found existing game with free slot(s), moving this player / party to that game
                Console.WriteLine("Found existing game with suitable slot(s), moving this player / party their");
                int newcount = resultEG[0].GetInt("totalFreeSlots") - 1;
                Console.WriteLine("scratch 1 ... to ... " + newcount);
                resultEG[0].Set("totalFreeSlots", resultEG[0].GetInt("totalFreeSlots") - 1);
                resultEG[0].Save();
           
            } else {

                //No suitable games found, create one
                Console.WriteLine("No suitable existing games have been found, creating new game");
                DatabaseObject obj = new DatabaseObject();
                DatabaseArray inGameFBUIDs = new DatabaseArray();
                obj.Set("totalFreeSlots", 18);
                obj.Set("facebookUIDs", curFBUID);
                PlayerIO.BigDB.CreateObject("activeGames", null, obj, delegate(DatabaseObject resultNG) {

                resultNG.Set("totalFreeSlots", resultNG.GetInt("totalFreeSlots") - 1);
                resultNG.Save();

                });

            }

        });

    }

});



The issue is in the if(resultEG.Length > 0) loop, as you can see the DB is supposed to be updated with a decremented value but instead what happens is if the original value was 18 it will go down to 17 the first time but then when it reads the current DB value again as per the for(int i = 0; i <= result.Length - 1; i ++) loop which it is contained in, it reads it as 18 instead of 17 (it's original number prior to the update) and so it will update only once. Can anyone shed some light onto why this might be happening?

Thanks.
jak322
 
Posts: 13
Joined: July 2nd, 2010, 3:24 pm

Re: Possible caching issue?

Postby fox1980 » November 24th, 2010, 3:31 pm

This doesn't sound like a caching problem to me. BigDB save is async so when you call:

Code: Select all
resultEG[0].Save();


it doesn't get saved right away, but your code keeps executing before the object is updated. I believe this is what causing your problem.
fox1980
 
Posts: 206
Joined: April 1st, 2010, 10:39 pm

Re: Possible caching issue?

Postby jak322 » November 26th, 2010, 7:25 pm

Thanks for the help.
jak322
 
Posts: 13
Joined: July 2nd, 2010, 3:24 pm


Return to BigDB



cron