google-code-export / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
1 stars 0 forks source link

Objectify Session is unaware of multithreading #173

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Load an entity in the main thread
2. Spawn a thread using App Engine's ThreadManager
3. In the new thread, load the entity, update some values, and save it
4. After completion of the new thread, try to load the updated entity in the 
main thread.

Expected:
4. returns the updated entity

Actual:
In 4., the main thread will always return the initially loaded instance of the 
entity. Calling clear() in 4. works around this issue.

Objectify 4, RC1

Original issue reported on code.google.com by mar...@greenrobot.de on 13 Aug 2013 at 8:01

GoogleCodeExporter commented 9 years ago
Forgot to mention, that each thread uses it's own ofy instance.

Could this issue also affect separate requests? For example:
1. Request A is handled in thread x, loads an entity
2. Request B is handled in thread y, loads, updates, and saves the entity
3. Request C is handled in thread x, loads the entity

The requests are strictly serial, called subsequently by the client.
--> Which entity instance is expected to be loaded in Request C? The outdated 
one from request A?

This would explain an issue we're having currently in this request scenario. If 
that's the case, a ServletFilter calling ofy.clear() would probably help.

Original comment by mar...@greenrobot.de on 13 Aug 2013 at 8:16

GoogleCodeExporter commented 9 years ago
Sounds like you don't have the ObjectifyFilter installed?

https://code.google.com/p/objectify-appengine/wiki/Setup#Enable_ObjectifyFilter_
for_your_requests
https://code.google.com/p/objectify-appengine/wiki/FrequentlyAskedQuestions#Stra
nge_things_are_showing_up_in_my_session_cache!

Original comment by lhori...@gmail.com on 13 Aug 2013 at 8:33

GoogleCodeExporter commented 9 years ago
Right, we forgot the ObjectifyFilter; thanks for reminding us of the obvious...

Nevertheless, do you any plans to support multithreading within a single 
request? It's probably not high priority, but some more notes on multi 
threading in the docs might help others. Thanks again...

For https://code.google.com/p/objectify-appengine/wiki/Caching, I'm not sure if 
the following sentence is still valid: "When you enter a transaction context, 
you receive a fresh, empty session cache." In my tests, I got stale entities 
from within a transaction, if I remember correctly.

Original comment by mar...@greenrobot.de on 13 Aug 2013 at 9:24

GoogleCodeExporter commented 9 years ago
There are no plans to support threading a single Objectify instance. It may not 
be possible; the underlying DatastoreService is not officially thread-safe. It 
would also add a lot of complexity.

That sentence is still valid. I would be very surprised if you can find 
contrary behavior - be careful in tests because you have to demarcate a 
"request" on your own (there's no ObjectifyFilter). Call 
ObjectifyFilter.complete() on your own between what ever demarcates a separate 
"request" in your test cases.

Original comment by lhori...@gmail.com on 16 Aug 2013 at 2:22