Comment 4 for bug 788592

Revision history for this message
Scott Ritchie (sritchie) wrote : Re: [Bug 788592] Re: KeyValue service errors when first creating UserGameProfile

Yeah it's actually quite suprising that this is the first time it has come
up - i didnt get this error when writing the populated datastore button, i
was quite happily creating multiple different entities using the same
PersistenceManager.

On Thu, May 26, 2011 at 11:11 PM, Matt Giuca <email address hidden>wrote:

> So this can be traced down to
> UserGameProfileGetter.getCurrentUserGameProfile(PersistenceManager, String),
> which does the following, if and only if the UGP does not yet exist:
> 1. Get a UserData from the datastore (with the same persistence manager),
> 2. Get a GameData from the datastore (with the same persistence manager),
> 3. Create a new UserGameProfileData,
> 4. Write the UserGameProfileData to the datastore (with the same
> persistence manager),
> 5. Update the UserData to refer to the UserGameProfileData,
> 6. Update the GameData to refer to the UserGameProfileData.
>
> Then, in KeyValuePairGetter:51, it calls pm.close() which brings
> everything crashing down.
>
> It seems like the problem is that the *same* persistence manager is
> being used to write to both the GameData *and* the UserGameProfileData.
> The problem goes away if you change step #1 and #2 to each create their
> own PM (trivial -- just remove the PM argument to the call).
>
> I'm quite surprised about this. I knew that a *transaction* could only
> apply to a single entity group, but I had no idea that a persistence
> manager could only apply to one entity group for its lifetime. I am
> surprised that this hasn't come up elsewhere. We should be on the look
> out for it.
>
> --
> You received this bug notification because you are subscribed to MUGLE.
> https://bugs.launchpad.net/bugs/788592
>
> Title:
> KeyValue service errors when first creating UserGameProfile
>
> Status in Melbourne University Game-based Learning Environment:
> In Progress
>
> Bug description:
> I'm not quite sure what's happening now. This doesn't happen in my API
> test, but in one of the student games. The game makes many requests to
> the KeyValue service while it is starting up (perhaps that's the
> difference -- APITest only makes requests after some length of time).
>
> Every one of the requests fails with a server error, but this only
> happens the first time a user plays that particular game. On all
> subsequent plays, it is fine.
>
> The message on the server is:
> Caused by: javax.jdo.JDOFatalUserException: Illegal argument
> NestedThrowables: java.lang.IllegalArgumentException: can't operate on
> multiple entity groups in a single transaction. found both Element { type:
> "UserGameProfileData" id: 389 } and Element { type: "GameData" id: 3 }
> at
> au.edu.unimelb.csse.mugle.server.model.KeyValuePairGetter.getKeyValuePair(KeyValuePairGetter.java:51)
> at
> au.edu.unimelb.csse.mugle.server.api.KeyValueServiceImpl.get(KeyValueServiceImpl.java:58)
>