From dev-return-49297-archive-asf-public=cust-asf.ponee.io@couchdb.apache.org Thu Apr 30 17:35:36 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id EDB5B180630 for ; Thu, 30 Apr 2020 19:35:35 +0200 (CEST) Received: (qmail 44501 invoked by uid 500); 30 Apr 2020 17:35:35 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 44482 invoked by uid 99); 30 Apr 2020 17:35:34 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Apr 2020 17:35:34 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 44CF7181443 for ; Thu, 30 Apr 2020 17:35:34 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.3 X-Spam-Level: X-Spam-Status: No, score=0.3 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, KAM_NUMSUBJECT=0.5, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-ec2-va.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id i9FTRIbr_-6C for ; Thu, 30 Apr 2020 17:35:32 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.217.47; helo=mail-vs1-f47.google.com; envelope-from=vatamane@gmail.com; receiver= Received: from mail-vs1-f47.google.com (mail-vs1-f47.google.com [209.85.217.47]) by mx1-ec2-va.apache.org (ASF Mail Server at mx1-ec2-va.apache.org) with ESMTPS id 01934BB8B2 for ; Thu, 30 Apr 2020 17:35:31 +0000 (UTC) Received: by mail-vs1-f47.google.com with SMTP id a5so4578910vsm.7 for ; Thu, 30 Apr 2020 10:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=5RXwO7nSwC0jxhxLrxdFzqeq8JfhD7QynI5oyD84n6s=; b=qRNPhJzDNuHb9cakA5IDnQI3UEV6rBGgms+sLOTYGk68G4rDnlijJD/bhH6XxeLJTJ u94xa8AS/SmgNUiJH0nxG/QtsoQ/BASDsV9wrmdNhxrASULlChrjqnwnsBxuYa8Qm01s 8dxxx6TNhW7gPb37TCwRYVLmSISl0ej53Xhv6x2FRvjLhDVsUBn9QeP5MHHvC4Y/nJFE jxYoOGDGnxjxDrB70f+j3mqK1KDDk0QEiIL3xwt9CgTy859ymf10pmtWuCyMCWAS8wEG vRAeIWqV9Rh/+Xq5dbsC37c/a77qkb0wvOTqdosSJYVGve3w6OnWuyzXGCaRvW4Qi2U+ wlfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=5RXwO7nSwC0jxhxLrxdFzqeq8JfhD7QynI5oyD84n6s=; b=c/mrM5lIvfueED2X7WnHN9YRt5tDp2bkY0tYYvDPbjd5+/MCZg7HRmWagbX//E9c2B OsT5xlH8fthmAZSV7k2EFoSR+D4tRO2hVNhO8xiizeZr5OVp9JT+6sn9LGug2zkoH3Kd IuH61wJLu/Ay4hAgMTqBo+pcPe7X0IE4mBCtUL7O1tEnDsa66Y1NloI/rx4V/vo3AvUX vuLQBlcdlAjMc5WHhODf2yzJD45du9waHzqLhcHKwYVb731D/vU2Qh/t3nbaZcPU30pM H3JdrFOJeuSL9v0nf4iPWU1Hlgx674J6i1/coAPXmjyTT7ojKHtghTG/nVcI2PMXIRk2 hYmw== X-Gm-Message-State: AGi0PuaWg0e5e7VBCj5ZhirOEAMC2pJfz/UzQGb0rBP5SfrT3SF+5SUP mOTYrt/cZlwJuOQD7jP2UosOhhNfNM+GffrDuUxQDvkW X-Google-Smtp-Source: APiQypJHr+nH0QG8+juBoXjVvNK9qB2Yf/ipBMRDyTdbZ8L/DWvcLTB7kXFE05w6vj0EDcsA1v+/fgwz6LjY1aIqCP4= X-Received: by 2002:a67:6487:: with SMTP id y129mr4417501vsb.48.1588268130688; Thu, 30 Apr 2020 10:35:30 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Nick Vatamaniuc Date: Thu, 30 Apr 2020 13:35:18 -0400 Message-ID: Subject: Re: [DISCUSS] Streaming API in CouchDB 4.0 To: dev@couchdb.apache.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Ilya, Maybe we should set a hard limit on the maximum doc ids size, 2-4KB? We have a config setting to do it already. And we also have hard limit of 10KB for FDB keys. Due to a limitation in Erlang http header parser, used through mochiweb, 8KB is (was?) the limit based on the default socket receive buffer size (see [1] for gory details). I was going to suggest 4KB initially but say users would want to specify a start_key and end_key + the dbname, so maybe 3KB or 2KB is a better option? It will be an incompatible change so that's something balance against. Regarding setting server_name in the config, you're referring to the specific limitation of 8KB from the mochweb header parsing, that shouldn't include the domain name, just individual request + header lines. It would look like "GET /dbname/_all_docs?bookmark...". Also was curious, in the latest proposal what will be included in the bookmark? Proposal said "The bookmark would include information needed to ensure proper pagination without the need to repeat initial parameters of the request". [1] https://github.com/apache/couchdb/commit/d23025ebd7176f6c307ddf49902cf2= 0b33bd55c4 On Thu, Apr 30, 2020 at 10:23 AM Ilya Khlopotov wrote: > > There is a problem with representing `next`/`previous`/`first` as path. W= ith 5kB sized doc keys and we could exceed max URL length (8192 bytes). Thi= s means we would have to support POST. The question is how to handle the ca= se when the URL is greater than 8192. The problem is CouchDB don't knows it= 's DNS name so we don't know the safe value to compare with. > > Options are: > 1) always use POST for pagination > 2) add server_name to config and return error when bookmark length exceed= s dynamically calculated threshold. The threshold would account for db name= length, server_name length, port and scheme length. > - what error to return? > > I think option number 2 is too subtle to implement. > > The downside of option 1 is it is a bit harder to use from the browser or= curl. > > On 2020/04/29 17:27:59, Ilya Khlopotov wrote: > > I think I addressed all comments and created an RFC https://github.com/= apache/couchdb-documentation/pull/530 > > > > On 2020/04/28 11:56:15, Ilya Khlopotov wrote: > > > Hello, > > > > > > I would like to introduce second proposal. > > > > > > 1) Add new optional query field called `bookmark` (or `token`) to fol= lowing endpoints > > > - {db}/_all_docs > > > - {db}/_all_docs/queries > > > - _dbs_info > > > - {db}/_design/{ddoc}/_view/{view} > > > - {db}/_design/{ddoc}/_view/{view}/queries > > > 2) Add following additional fields into response: > > > ``` > > > "first": { > > > "href": "https://myserver.com/myddb/_all_docs?limit=3D50&desc= ending=3Dtrue" > > > }, > > > "previous": { > > > "href": "https://myserver.com/myddb/_all_docs?bookmark=3D983= uiwfjkdsdf" > > > }, > > > "next": { > > > "href": "https://myserver.com/myddb/_all_docs?bookmark=3D1234= 3tyekf3" > > > }, > > > ``` > > > 3) Implement per-endpoint configurable max limits > > > ``` > > > [request_limits] > > > _all_docs =3D 5000 > > > _all_docs/queries =3D 5000 > > > _all_dbs =3D 5000 > > > _dbs_info =3D 5000 > > > _view =3D 2500 > > > _view/queries =3D 2500 > > > _find =3D 2500 > > > ``` > > > 4) Implement following semantics: > > > - The bookmark would be opaque token and would include information= needed to ensure proper pagination without the need to repeat initial para= meters of the request. In fact we might prohibit setting additional paramet= ers when bookmark query field is specified. > > > - don't use delayed responses when `bookmark` field is provided > > > - don't use delayed responses when `limit` query key is specified = and when it is below the max limit > > > - return 400 when limit query key is specified and it is greater t= han the max limit > > > - return 400 when we stream rows (in case when `limit` query key w= asn't specified) and reach max limit > > > - the `previous`/`next`/`first` keys are optional and we omit them= for the cases they don't make sense > > > > > > Latter on we would introduce API versioning and deal with `{db}/_chan= ges` and `_all_docs` endpoints. > > > > > > Questions: > > > - `bookmark` vs `token`? > > > - should we prohibit setting other fields when bookmark is set? > > > - `previous`/`next`/`first` as href vs token value itself (i.e. `{"pr= evious": "983uiwfjkdsdf", "next": "12343tyekf3", "first": "iekjhfwo034"}`) > > > > > > Best regards, > > > iilyak > > > > > > On 2020/04/22 20:18:57, Ilya Khlopotov wrote: > > > > Hello everyone, > > > > > > > > Based on the discussions on the thread I would like to propose a nu= mber of first steps: > > > > 1) introduce new endpoints > > > > - {db}/_all_docs/page > > > > - {db}/_all_docs/queries/page > > > > - _all_dbs/page > > > > - _dbs_info/page > > > > - {db}/_design/{ddoc}/_view/{view}/page > > > > - {db}/_design/{ddoc}/_view/{view}/queries/page > > > > - {db}/_find/page > > > > > > > > These new endpoints would act as follows: > > > > - don't use delayed responses > > > > - return object with following structure > > > > ``` > > > > { > > > > "total": Total, > > > > "bookmark": base64 encoded opaque value, > > > > "completed": true | false, > > > > "update_seq": when available, > > > > "page": current page number, > > > > "items": [ > > > > ] > > > > } > > > > ``` > > > > - the bookmark would include following data (base64 or protobuff???= ): > > > > - direction > > > > - page > > > > - descending > > > > - endkey > > > > - endkey_docid > > > > - inclusive_end > > > > - startkey > > > > - startkey_docid > > > > - last_key > > > > - update_seq > > > > - timestamp > > > > ``` > > > > > > > > 2) Implement per-endpoint configurable max limits > > > > ``` > > > > _all_docs =3D 5000 > > > > _all_docs/queries =3D 5000 > > > > _all_dbs =3D 5000 > > > > _dbs_info =3D 5000 > > > > _view =3D 2500 > > > > _view/queries =3D 2500 > > > > _find =3D 2500 > > > > ``` > > > > > > > > Latter (after few years) CouchDB would deprecate and remove old end= points. > > > > > > > > Best regards, > > > > iilyak > > > > > > > > On 2020/02/19 22:39:45, Nick Vatamaniuc wrote= : > > > > > Hello everyone, > > > > > > > > > > I'd like to discuss the shape and behavior of streaming APIs for = CouchDB 4.x > > > > > > > > > > By "streaming APIs" I mean APIs which stream data in row as it ge= ts > > > > > read from the database. These are the endpoints I was thinking of= : > > > > > > > > > > _all_docs, _all_dbs, _dbs_info and query results > > > > > > > > > > I want to focus on what happens when FoundationDB transactions > > > > > time-out after 5 seconds. Currently, all those APIs except _chang= es[1] > > > > > feeds, will crash or freeze. The reason is because the > > > > > transaction_too_old error at the end of 5 seconds is retry-able b= y > > > > > default, so the request handlers run again and end up shoving the > > > > > whole request down the socket again, headers and all, which is > > > > > obviously broken and not what we want. > > > > > > > > > > There are few alternatives discussed in couchdb-dev channel. I'll > > > > > present some behaviors but feel free to add more. Some ideas migh= t > > > > > have been discounted on the IRC discussion already but I'll prese= nt > > > > > them anyway in case is sparks further conversation: > > > > > > > > > > A) Do what _changes[1] feeds do. Start a new transaction and cont= inue > > > > > streaming the data from the next key after last emitted in the > > > > > previous transaction. Document the API behavior change that it ma= y > > > > > present a view of the data is never a point-in-time[4] snapshot o= f the > > > > > DB. > > > > > > > > > > - Keeps the API shape the same as CouchDB <4.0. Client libraries > > > > > don't have to change to continue using these CouchDB 4.0 endpoint= s > > > > > - This is the easiest to implement since it would re-use the > > > > > implementation for _changes feed (an extra option passed to the f= old > > > > > function). > > > > > - Breaks API behavior if users relied on having a point-in-time[= 4] > > > > > snapshot view of the data. > > > > > > > > > > B) Simply end the stream. Let the users pass a `?transaction=3Dtr= ue` > > > > > param which indicates they are aware the stream may end early and= so > > > > > would have to paginate from the last emitted key with a skip=3D1.= This > > > > > will keep the request bodies the same as current CouchDB. However= , if > > > > > the users got all the data one request, they will end up wasting > > > > > another request to see if there is more data available. If they d= idn't > > > > > get any data they might have a too large of a skip value (see [2]= ) so > > > > > would have to guess different values for start/end keys. Or impos= e max > > > > > limit for the `skip` parameter. > > > > > > > > > > C) End the stream and add a final metadata row like a "transactio= n": > > > > > "timeout" at the end. That will let the user know to keep paginat= ing > > > > > from the last key onward. This won't work for `_all_dbs` and > > > > > `_dbs_info`[3] Maybe let those two endpoints behave like _changes > > > > > feeds and only use this for views and and _all_docs? If we like t= his > > > > > choice, let's think what happens for those as I couldn't come up = with > > > > > anything decent there. > > > > > > > > > > D) Same as C but to solve the issue with skips[2], emit a bookmar= k > > > > > "key" of where the iteration stopped and the current "skip" and > > > > > "limit" params, which would keep decreasing. Then user would pass > > > > > those in "start_key=3D..." in the next request along with the lim= it and > > > > > skip params. So something like "continuation":{"skip":599, "limit= ":5, > > > > > "key":"..."}. This has the same issue with array results for > > > > > `_all_dbs` and `_dbs_info`[3]. > > > > > > > > > > E) Enforce low `limit` and `skip` parameters. Enforce maximum val= ues > > > > > there such that response time is likely to fit in one transaction= . > > > > > This could be tricky as different runtime environments will have > > > > > different characteristics. Also, if the timeout happens there isn= 't a > > > > > a nice way to send an HTTP error since we already sent the 200 > > > > > response. The downside is that this might break how some users us= e the > > > > > API, if say the are using large skips and limits already. Perhaps= here > > > > > we do both B and D, such that if users want transactional behavio= r, > > > > > they specify that `transaction=3Dtrue` param and only then we enf= orce > > > > > low limit and skip maximums. > > > > > > > > > > F) At least for `_all_docs` it seems providing a point-in-time > > > > > snapshot view doesn't necessarily need to be tied to transaction > > > > > boundaries. We could check the update sequence of the database at= the > > > > > start of the next transaction and if it hasn't changed we can con= tinue > > > > > emitting a consistent view. This can apply to C and D and would j= ust > > > > > determine when the stream ends. If there are no writes happening = to > > > > > the db, this could potential streams all the data just like optio= n A > > > > > would do. Not entirely sure if this would work for views. > > > > > > > > > > So what do we think? I can see different combinations of options = here, > > > > > maybe even different for each API point. For example `_all_dbs`, > > > > > `_dbs_info` are always A, and `_all_docs` and views default to A = but > > > > > have parameters to do F, etc. > > > > > > > > > > Cheers, > > > > > -Nick > > > > > > > > > > Some footnotes: > > > > > > > > > > [1] _changes feeds is the only one that works currently. It behav= es as > > > > > per RFC https://github.com/apache/couchdb-documentation/blob/mast= er/rfcs/003-fdb-seq-index.md#access-patterns. > > > > > That is, we continue streaming the data by resetting the transact= ion > > > > > object and restarting from the last emitted key (db sequence in t= his > > > > > case). However, because the transaction restarts if a document is > > > > > updated while the streaming take place, it may appear in the _cha= nges > > > > > feed twice. That's a behavior difference from CouchDB < 4.0 and w= e'd > > > > > have to document it, since previously we presented this point-in-= time > > > > > snapshot of the database from when we started streaming. > > > > > > > > > > [2] Our streaming APIs have both skips and limits. Since FDB does= n't > > > > > currently support efficient offsets for key selectors > > > > > (https://apple.github.io/foundationdb/known-limitations.html#dont= -use-key-selectors-for-paging) > > > > > we implemented skip by iterating over the data. This means that a= skip > > > > > of say 100000 could keep timing out the transaction without yield= ing > > > > > any data. > > > > > > > > > > [3] _all_dbs and _dbs_info return a JSON array so they don't have= an > > > > > obvious place to insert a last metadata row. > > > > > > > > > > [4] For example they have a constraint that documents "a" and "z" > > > > > cannot both be in the database at the same time. But when iterati= ng > > > > > it's possible that "a" was there at the start. Then by the end, "= a" > > > > > was removed and "z" added, so both "a" and "z" would appear in th= e > > > > > emitted stream. Note that FoundationDB has APIs which exhibit the= same > > > > > "relaxed" constrains: > > > > > https://apple.github.io/foundationdb/api-python.html#module-fdb.l= ocality > > > > > > > > > > > > > >