Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch local docs in fold_docs function #2869

Merged
merged 2 commits into from
May 8, 2020
Merged

fetch local docs in fold_docs function #2869

merged 2 commits into from
May 8, 2020

Conversation

garrensmith
Copy link
Member

Overview

Testing recommendations

Related Issues or Pull Requests

Checklist

@garrensmith garrensmith requested a review from nickva May 5, 2020 10:41
Copy link
Member

@davisp davisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to either reject mixing _local doc lookups (which is an API change) or refactor things such that local docs have a corresponding future shape to doc bodies.

user_fun := UserFun
} = Acc,

NewUserAcc = maybe_stop(UserFun(DocId, DocResp, UserAcc)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is broken. You can't mix synchronous and asynchronous fetches like this. POST /dbname/_all_docs has a (perhaps implicit?) contract for returning docs in the order specified in the body. Mixing these operations means that we'd be returning any _local docs in some random position within the previous 100 or so docs returned.

Copy link
Contributor

@nickva nickva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid whitespace changes and add a some eunit tests to maintain our code coverage

@garrensmith
Copy link
Member Author

@nickva and @davisp thanks for the review. I've updated the PR to make the local docs async and also added some eunit tests.

@@ -996,12 +986,12 @@ fold_docs(Db, DocIds, UserFun, UserAcc0, Options) ->
user_fun => UserFun
},

FinalAcc1 = lists:foldl(fun(DocId, Acc) ->
FinalAcc1 = lists:foldl(fun (DocId, Acc) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: whitespace change

Copy link
Contributor

@nickva nickva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better, @garrensmith

I think we need to account for deleted docs as well:

http post $DB1/db/_all_docs?include_docs=true keys:='["d1", "_local/l1", "d3"]'
HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Type: application/json
Date: Wed, 06 May 2020 17:47:36 GMT
Server: CouchDB/3.0.0-97227c4 (Erlang OTP/21)
Transfer-Encoding: chunked
X-Couch-Request-ID: 7ce49a7c4b
X-CouchDB-Body-Time: 0

{
    "offset": null,
    "rows": [
        {
            "doc": {
                "_id": "d1",
                "_rev": "1-935564bc7ec7e86aa82ecec3face18f6",
                "x": "y"
            },
            "id": "d1",
            "key": "d1",
            "value": {
                "rev": "1-935564bc7ec7e86aa82ecec3face18f6"
            }
        },
        {
            "doc": {
                "_id": "_local/l1",
                "_rev": "0-1",
                "l1doc": "x"
            },
            "id": "_local/l1",
            "key": "_local/l1",
            "value": {
                "rev": "0-1"
            }
        },
        {
            "error": "not_found",
            "key": "d3"
        }
    ],
    "total_rows": 2
}

nvatama@nvm asf (pr/2869) $ http delete $DB1/db/_local/l1
HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Length: 41
Content-Type: application/json
Date: Wed, 06 May 2020 17:47:43 GMT
ETag: "DKGUB9HWEX2KQNSCSMV0JG1KK"
Server: CouchDB/3.0.0-97227c4 (Erlang OTP/21)
X-Couch-Request-ID: 352a9b2160
X-CouchDB-Body-Time: 0

{
    "id": "_local/l1",
    "ok": true,
    "rev": "0-0"
}

$ http post $DB1/db/_all_docs?include_docs=true keys:='["d1", "_local/l1", "d3"]'
HTTP/1.1 500 Internal Server Error
Cache-Control: must-revalidate
Content-Length: 77
Content-Type: application/json
Date: Wed, 06 May 2020 17:47:44 GMT
Server: CouchDB/3.0.0-97227c4 (Erlang OTP/21)
X-Couch-Request-ID: cba45e587e
X-Couch-Stack-Hash: 1247935461
X-CouchDB-Body-Time: 0

{
    "error": "case_clause",
    "reason": "{ok,{not_found,missing}}",
    "ref": 1247935461
}

The logs show the place where error happens:

[error] 2020-05-06T17:47:45.194056Z [email protected] <0.8976.0> cba45e587e req_err(1247935461) case_clause : {ok,{not_found,missing}}
    [<<"chttpd_db:-send_all_docs_keys/3-fun-0-/5 L902">>,<<"fabric2_db:drain_one_fold_docs_body_future/2 L1361">>,<<"fabric2_db:drain_all_fold_docs_body_futures
/2 L1342">>,<<"fabric2_db:-fold_docs/5-fun-1-/5 L1003">>,<<"fabric2_fdb:execute_transaction/3 L1915">>,<<"fabric2_fdb:-do_transaction/2-fun-1-/3 L173">>,<<"erlf
db:do_transaction/2 L655">>,<<"fabric2_fdb:do_transaction/2 L158">>]

@garrensmith
Copy link
Member Author

@nickva thanks I've updated with a fix for the deleted doc. Great spot on the deleted doc. I've updated the elixir test to test for that.


assert resp.status_code == 200
rows = resp.body["rows"]
IO.inspect rows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A debug line? I notice elixir's credo test didn't like that:

Checking 74 source files (this might take a while) ...

  Warnings - please take a look
┃
┃ [W] ↗ There should be no calls to IO.inspect/1.
┃       test/elixir/test/all_docs_test.exs:343:5 #(AllDocsTest)

Please report incorrect results: https://github.com/rrrene/credo/issues

fold_docs_get_doc_body_wait(Db, <<?LOCAL_DOC_PREFIX, _/binary>> = DocId, [Rev],
_DocOpts, BodyFuture) ->
case fabric2_fdb:get_local_doc_body_wait(Db, DocId, Rev, BodyFuture) of
{not_found,missing} -> {not_found, missing};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: space between not_found and missing

Copy link
Contributor

@nickva nickva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 but see two minor issues about space and an IO.inspect call in Elixir tests

@garrensmith garrensmith merged commit d66e95a into apache:prototype/fdb-layer May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants