Commits on Jul 11, 2012
  1. @benoitc

    add validate_doc_read property to a design document.

    Like validate_doc_update, this function validate if the document can be
    read by the curreny user.
        function(doc, userCtx) {
            if ((typeof !== 'undefined') && ( != {
                throw({unauthorized: + ' cannnot read ' + doc._id});
    will allow the current user to only read the documents where the
    properties name is the name of the user.
    Note: admins can always read the documents.
    benoitc committed Jul 11, 2012
  2. @benoitc

    fix system dbs opening.

    benoitc committed Jul 11, 2012
Commits on Jul 8, 2012
  1. @benoitc
  2. @benoitc

    Signficantly simplify the auth cache

    The old cache was overly complicated for doing what it does. This new
    version does introduce a race condition on cache invalidation because
    the update has to go through the even notification and then the changes
    feed needs to be processed. In the future we should generalize the db
    hook functions and turn it into a write through cache. Until then I just
    added a short wait in the tests.
    patch from @davisp edited for rcouch.
    benoitc committed Jul 4, 2012
  3. @benoitc

    Refactor couch_server for performance

    This is a backport of a change in BigCouch that changes the behaviour of
    couch_server to be more performant as well as be more robust under heavy
    There are two main parts to this change. First, it removes the need to
    have synchronous message passing between the couch_server gen_server and
    every process that wants to open a database that is already open. It
    does this by using a protected ets table that is used to by pass having
    to talk directly to couch_server.
    The second major portion of this patch rewrites the LRU handling inside
    couch_server so that it doesn't turn into an N^2 loop when the
    max_dbs_limit is reached and all databases are in use.
    apply patch from @davisp edited for rcouch.
    benoitc committed Jul 4, 2012
  4. @benoitc

    Remove couch_ref_counter and use process monitors

    This patch removes the ref counting code that used process links and a
    gen_server to manage when databases are idle. This is important ground
    work for the refactoring of couch_server which relies on having a sane
    interface to managing database.
    This code has two major parts. The first part removes the gen_server
    from couch_db.erl and instead relies on checking who's monitoring the
    database's couch_file gen_server. The database is idle when this list
    only includes the updater and possible the couch_stats_collector which
    monitors open databases.
    The second half is how couch_file's are managed by listening for who is
    monitoring them. If they're monitored by only zero or one process then
    they close themselves. This allows for the semantics of staying open
    long enough to handle any current connections while being replaced with
    a new couch_file (ie, due to compaction).
    Applied patch from @davisp edited with some additions for rcouch.
    benoitc committed Jul 4, 2012
  5. @benoitc

    Remove second fd from couch_db_updater

    This reverts the change to use a second file descriptor for
    couch_db_udpaters to split read and writes. This is ground work for the
    next few patches that change how databases are managed
    apply patch from @davisp edited for rcouch.
    benoitc committed Jul 4, 2012
Commits on Jul 4, 2012
  1. @benoitc

    fix test

    benoitc committed Jul 4, 2012
  2. @benoitc

    allows couch_collate upgrade

    benoitc committed Jul 4, 2012
  3. @rnewson @benoitc

    Handle ddoc_updated event correctly.

    COUCHDB-1309 introduced a new update event of the form {ddoc_updated,
    {DbName, DDocId}}. Unfortunately it did not update
    couch_db_update_notifier with a clause that can marshal this to JSON
    successfully, breaking all uses of [update_notification]
    This commit improves event encoding so that the above renders as
    rnewson committed with benoitc Jul 4, 2012
  4. @benoitc

    fix time issue.

    benoitc committed Jul 4, 2012
  5. @benoitc


    benoitc committed Jul 4, 2012
  6. @benoitc
  7. @benoitc

    fix couch_httpd_proxy.

    use mochicow request module to receive data.
    benoitc committed Jul 4, 2012
  8. @benoitc

    fix changes test

    benoitc committed Jul 4, 2012
  9. @benoitc

    fix format

    benoitc committed Jul 4, 2012
Commits on Jul 3, 2012
  1. @rnewson @benoitc
Commits on Jun 28, 2012
  1. @benoitc

    fix pattern matching

    couch_btree:query_modify return a tuple instead of a list when there is
    only one to return.
    benoitc committed Jun 28, 2012
  2. @benoitc

    handle non mrargs keys

    benoitc committed Jun 28, 2012
Commits on Jun 22, 2012
  1. @benoitc
  2. @benoitc

    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
  3. @benoitc

    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
  4. @benoitc
  5. @benoitc

    `_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
  6. @benoitc
  7. @benoitc

    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
  8. @benoitc

    add `couch_mrview:refresh/2` function.

    Simple helper to refresh a view index.
    benoitc committed Jun 21, 2012
Commits on Jun 21, 2012
  1. @benoitc

    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. @benoitc

    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. @benoitc

    fix typos

    benoitc committed Jun 13, 2012
  2. @benoitc
Commits on Jun 12, 2012
  1. @benoitc

    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. @benoitc

    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. @benoitc

    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. @benoitc

    couch_stats is already loaded.

    benoitc committed May 22, 2012