google-code-export / sandy-disaster-recovery

Automatically exported from code.google.com/p/sandy-disaster-recovery
2 stars 2 forks source link

Fix race conditions #45

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We have several race conditions between database reads and writes. We should 
prevent an object from being modified if someone else has modified it more 
recently.

Original issue reported on code.google.com by bruc...@gmail.com on 6 Nov 2012 at 11:47

GoogleCodeExporter commented 9 years ago

Original comment by bruc...@gmail.com on 7 Nov 2012 at 2:53

GoogleCodeExporter commented 9 years ago
I'm not too worried about this case, since it should happen far less often than 
user error. If we want to fix it though, we can use this:

https://developers.google.com/appengine/docs/python/datastore/transactions

Original comment by rostovp...@gmail.com on 7 Nov 2012 at 4:50

GoogleCodeExporter commented 9 years ago
I agree that this app is so small that the probability of a race within a 
single request is negligibly small. I'm much more worried about races between 
when content is sent to the client and when it's updated on the server. 
Consider this case:

1. Alice starts editing a site.
2. A few minutes later, Bob starts editing the site.
3. 15 minutes after she started, Alice has turned the record into a masterpiece 
of disaster recovery information, and she saves her changes.
4. A minute later, Bob saves his changes.

Alice's masterpiece was just destroyed.

One possible solution:
1. Add a new field to each model class. Call it a modification token.
2. Every time the client requests object data that it may want to mutate, we 
also send down the modification token.
3. When the client makes the modification request, it sends the token back to 
the server.
4. The server ensures that the modification token matches the current value in 
the datastore. If it doesn't, it rejects the mutation.

Original comment by bruc...@gmail.com on 7 Nov 2012 at 7:58

GoogleCodeExporter commented 9 years ago
I would like to bring this issue up again to make sure that we have at least a 
rudimentary method for either detecting or resolving crashes.

Original comment by v...@aarontitus.net on 15 Jan 2013 at 12:02