couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joscha Feth" <>
Subject Atomicity of getting update_seq after reading data
Date Wed, 30 Dec 2009 10:12:11 GMT
Hi Relaxers, 

there was a discussion in user@ about a common problem when reading
from couchDB and wanting to also informed of any changes on the data
after having read it.

Current standard procedure to do this is:

1)  Get the update_seq from the database
2)  Get data from a view
3)  Connect to _changes since updae_seq from #1

As making two requests are not atomic, there might have been updates
between 1) and 2) which need to be handled afterwards (data could even
have been removed completely in between).

Now there was a suggestion to add an X-Update-Seq header to any view
coming back which allows to not only save an additional request, but
also make this thing atomic.
Chris Anderson proposed to not add a header, but extend the JSON:

{"total_rows":1000,"offset":0, "update_seq": 1001, "rows":[

which I think is an equivalent solution.

I would be willing to write a patch for this, but I am a total beginner
in Erlang. I searched the code a little and found that one change
should be made in "couch_httpd_view.erl":

json_view_start_resp(Req, Etag, TotalViewCount, Offset, _Acc) ->
       UpdateSeq = get_update_seq_from_somewhere(),
   {ok, Resp} = start_json_response(Req, 200, [{"Etag", Etag}]),
   BeginBody =
           [TotalViewCount, Offset, UpdateSeq]),
   {ok, Resp, BeginBody}.

and get_update_seq_from_somewhere() is still a mistery for me :-)
Can anyone give me a hint where/how to get the latest update_seq



View raw message