Add Database.update()

Bug #1160107 reported by Jason Gerard DeRose on 2013-03-26
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Microfiber
High
Jason Gerard DeRose

Bug Description

I'm porting the `dmeida.metastore.update_doc()` function to be the `Database.update()` method:

update_doc(db, doc, func, *args) => Database.update(doc, func, *args)

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.metastore.update_doc()` function:

http://bazaar.launchpad.net/~dmedia/dmedia/trunk/view/head:/dmedia/metastore.py?start_revid=593#L98

Related branches

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
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers