Commits on Jun 22, 2012
  1. get last indexed sequence of a view using the HTTP API.

    It's useful to get the last sequence indexed in a view (all the view or
    in a range). If the sequences are indexed it is like getting the last
    sequence. If sequences aren't indexed, the last updated sequence of the
    view group is returned.
    Example of usage:
        $ curl 'http://localhost:5984/testdb/_design/test/_view/test/_last_seq'
        $ curl 'http://localhost:5984/testdb/_design/test/_view/test/_last_seq?key=1'
        $ curl 'http://localhost:5984/testdb/_design/test/_view/test/_last_seq?key=8'
    benoitc committed Jun 22, 2012
  2. add `couch_mrview:get_last_seq/4`

    This function allows us to get the real last indexed sequece in a view.
    benoitc committed Jun 22, 2012
  3. unlink subscriber.

    If we don't unlink subscriber, any crash will affect us.
    benoitc committed Jun 22, 2012
  4. fix include docs issue

    benoitc committed Jun 22, 2012
Commits on Jun 21, 2012
  1. correctly unsubscribe.

    Even if the event handler si supposed to handle none existing pids it's
    cleaner to unsubscribe when we can.
    benoitc committed Jun 21, 2012
  2. `_changes` is now supporting view index updatei events

    if the _view filters is passed in the url, the request process subscribe
    to the index updates using the new `couch_mrview_events:subscribe/3`
    function. All events are then returned to the HTTP api.
        $ curl
        id: 1
        id: 4
        id: 6
    benoitc committed Jun 21, 2012
  3. handle couch_mrview events.

    This change introduces an efficient way to manage couch_mrview events
    that notify a suscribed process about an index update.
    When a process subscribe to a an index updated using
    `couchdb_mrview_events:subscribe/3` it open a new indexer that will
    refresh the indexes each time the database is updated. When no more
    subscribers exists the automatic indexer is killed. Each indexer is
    The subscribe receive 2 kinds of notifications:
    - `{index_update, {DbName, DDocName}}` when an index is updated
    - `{index_shutdown, {DbName, DDocName}}` when the db or the index are
        1> couch_mrview_events:subscribe(<<"testdb">>, <<"_design/test">>).
        2> ok
        21:11:44.673 [info] - - POST /testdb 201
        21:11:44.698 [info] Opening index for db: testdb idx: _design/test sig: "8152471699732c18e2a4954ac27b1049"
        21:11:44.699 [info] Starting index update for db: testdb idx: _design/test
        21:11:44.737 [info] Index update finished for db: testdb idx: _design/test
        2> flush().
        Shell got {index_update,{<<"testdb">>,<<"_design/test">>}}
        21:12:09.799 [info] - - DELETE /testdb/_design/test?rev=1-114ec5224d4dc5d63912cd50536bdf48 200
        21:12:09.801 [info] Closing index for db: testdb idx: _design/test sig: "8152471699732c18e2a4954ac27b1049"
        3> flush().
        Shell got {index_shutdown,{<<"testdb">>,<<"_design/test">>}}
    benoitc committed Jun 21, 2012
  4. add `couch_mrview:refresh/2` function.

    Simple helper to refresh a view index.
    benoitc committed Jun 21, 2012
  5. add `seq_indexed` option to a design document.

    If the option `seq_indexed` is **true**, the views indexes will be also
    indexed by sequences. It is possible to retrieve changes using the
    `couch_mrview:view_changes_since/{5,6,7}`  function wich allows you to
    get all changes in a view or changes from a view in a range since last
    sequence. ex:
        couch_mrview:view_changes_since(Db, <<"_design/test">>, <<"test">>,
    0, fun(KV, Acc) -> io:format("kv ~p~n", [KV]), {ok, Acc} end,
    [{start_key, null}, {end_key, null}]).
        kv {{null,4},
    If the range is omitted all changes will be retrieved since the last
    When `seq_indexed` is created 1 main sequence is created for all the
    view group with the key `{ViewId, Seq}` and the value `{DocId, Key,
    is added. There can be multiple lines by sequences. These sequences are
    retrieved by querying the b-tree in the range:  `[{ViewId, StartSeq+1},
    {ViewId, EndSeq}]`
    where EndSeq depending on the direction can be 0 or a the last big
    To allows the querying of changes in a range, a new index is added per
    views with the composite key `{Key, Seq}` (instead DocId) and the value
    `{DocId, Val}` is indexed for this key. We query this index in the range
    `[{StartKey, StartSeq+1}, {EndKey, EndSeq}]` to retrieve the changes.
    The size of the indexes will grow significantly with this changes and
    compaction is needed more often.
    benoitc committed Jun 21, 2012
Commits on Jun 18, 2012
  1. add `include_deleted` option to a view

    add the possibility to index deleted documents in a view.
    benoitc committed Jun 18, 2012
Commits on Jun 13, 2012
  1. fix typos

    benoitc committed Jun 13, 2012
Commits on Jun 12, 2012
  1. make couch_httpd more resistant to failures.

    If vhosts or the authentication cache module crash we need to make sure that
    HTTPd bindings are restarted as well.
    benoitc committed Jun 12, 2012
  2. Upgrade the cowboy reauest to a mochiweb request

    Instead of only using the cowboy requets pool we now use a cowboy
    handler that upgrades the connections to a mochiweb request. It will
    will quietly allow us to replace mochiweb by cowboy. While I was here I
    also changed the way config changes are handled: the HTTP(s) listener is
    not any more restarted when only the dispatching rules change. Instead
    we update the cowboy dispatching rules.
    benoitc committed Jun 9, 2012
Commits on Jun 8, 2012
  1. Initial steps to use mochicow.

    Replace mochiweb connection handling by the cowboy one. We are using
    mochiweb to skip the need to rewrite handlers for now. Most of tests
    pass, some are still hanging like the change one but it may be a time
    benoitc committed Jun 8, 2012
Commits on May 22, 2012
  1. couch_stats is already loaded.

    benoitc committed May 22, 2012
  2. don't use the ini to load couch_uuids.

    This module is always needed, there is no need to keep it in the
    configuration file.
    benoitc committed May 22, 2012
  3. extract couch_stats in its own app.

    couch_stats is now a full erlang application booted at startup. Other
    changes are a better reinitialization of settings. Instead of exiting
    the gen_server, we just load new settings and overwrite older.
    benoitc committed May 22, 2012
Commits on May 18, 2012
  1. support system dbs. close #9 .

    Systems databases are databases only available and visible by admins.
    All systems databases are prefixed by `rc_` .
        $ curl -XPUT
        {"error":"unauthorized","reason":"You are not a server admin."}
        $ curl -XPUT http://admin:test@
        $ curl http://admin:test@
        $ curl
        $ curl -XPUT http://admin:test@ -d'{}'
        {"error":"file_exists","reason":"The database could not be created,
    the file already exists."}
        $ curl -XPUT http://admin:test@
        $ curl -XPUT
    -d'{}'{"error":"unauthorized","reason":"You are not authorized to access
    this db."}
        $ curl{"error":"unauthorized","reason":"You
    are not authorized to access this db."}
        $ curl http://admin:test@
    benoitc committed May 18, 2012
Commits on May 17, 2012
  1. vhosts values should not be empty.

    A vhost value can be empty when removed with the couch_config module.
    benoitc committed May 17, 2012
Commits on May 16, 2012
  1. all should be compile & deps.

    benoitc committed May 16, 2012
  2. fix whitespaces

    benoitc committed May 16, 2012
Commits on May 12, 2012
  1. filter fields in included doc when returned from a _changes

    With this changes you can only return a specified list of fields in the
    included docs by passing the list of them to an optionnal `fields`
    parameter. For now nested fields are ignored.
        $ curl -XPUT localhost:5984/testdb
        $ curl -XPUT localhost:5984/testdb/test -d'{"f1": 1, "f2": 2, "f3":
        $ curl -XPUT localhost:5984/testdb/test1 -d'{"f1": 1, "f2": 4, "f3":
        $ curl -XPUT localhost:5984/testdb/test2 -d'{"f1": 1, "f2": 7, "f3":
        $ curl "http://localhost:5984/testdb/_changes?include_docs=true"
        $ curl
        $ curl
    benoitc committed May 12, 2012
Commits on May 10, 2012
  1. add support of Server-Sent Events protocol to db changes API.

    This patch add support for the new specification of w3c by adding a new
    feed type named `eventsource`:
        $ curl
        id: 1
        id: 2
    benoitc committed May 10, 2012