Add Database.update()
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Microfiber |
Fix Released
|
High
|
Jason Gerard DeRose |
Bug Description
I'm porting the `dmeida.
update_doc(db, doc, func, *args) => Database.
Conflicts are an interesting problem in Dmedia and Novacut. In Dmedia, the general approach is to ignore conflicts (last change wins) and frequently re-sample reality, and this approach has worked well. It's simple and robust and easy to prove.
However, there are some places where we really want a single retry should there be a conflict. The typical scenario is something like file verification where a fairly long amount of time can elapse between when the doc is first retrieved and when the verification completes and we need to save the doc.
The "single retry" approach involves an update function that will modify a document in-place, like this:
func(doc, *args)
Then we try to save the doc. If there is a conflict, we do a Database.get() to retrieve the latest document revision. We then call the update function again, this time using the new doc we just retrieved from the database:
func(doc, *args)
And then we save the doc with Database.save(). If there is yet again a conflict, this time we do nothing special, and the exception propagates upward as normal.
For reference, see the current `dmedia.
http://
Related branches
- David Jordan: Approve
-
Diff: 141 lines (+109/-0)2 files modifiedmicrofiber/__init__.py (+16/-0)
microfiber/tests/__init__.py (+93/-0)
Changed in microfiber: | |
status: | In Progress → Fix Committed |
Changed in microfiber: | |
milestone: | 13.04 → 13.05 |
Changed in microfiber: | |
milestone: | 13.05 → 13.04 |
status: | Fix Committed → Fix Released |