Reputation: 324
I've posted a question earlier datastore: deleting entities outside transactions but did not get much luck on that, maybe i was too complex at describing the problem so I'll try to hit that problem with a different question:
I'm not using any transaction with my entity and realize that i could loose committed updates because of dirty reads and totally OK with it (mainly statistics). the only thing i need for sure is that if i delete it after a dirty read was already made but no update was committed yet that it won't write that entity back. I don't want to introduce contention or performance issues by using transactions because deletes are rare and update are many.
Servlet A
{
entity = persistenceManager.getObjectById(Entity.class, key)
//Stuff
persistenceManager.deletePersistent(entity);
}
Servlet B
{
entity = persistenceManager.getObjectById(Entity.class, key) // dirty read made before deletion
//Updated some fields, after deletion was commited
persistenceManager.flush(); ? the object would be written back
}
I've tested the case above by introducing 20 seconds sleep in B between dirty read and delete and it does write the object back (Actually that is the answer for the first question, will update that question).
Can i rely on memcache to let Servlet B before getting the entity know that A is about to delete the entity let us say by looking a Boolean cache entry 'deleting-entity-[KEY]' being put from A and if it is there then i should not read the entity in servlet B, I know that memcache does not guarantee not evicting data but if it is there is it instantly accessible from servlet B?
Any better ideas out there?
Upvotes: 0
Views: 218
Reputation: 15143
Use a transaction to in servlet B to verify the entity is still there before writing.
Why are you avoiding transactions? That's what transactions are for, and without them, you can not guarantee any data synchronization.
Upvotes: 0