You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2019/11/26 14:32:47 UTC
[couchdb] branch optimise-view-read created (now d9b20d5)
This is an automated email from the ASF dual-hosted git repository.
garren pushed a change to branch optimise-view-read
in repository https://gitbox.apache.org/repos/asf/couchdb.git.
at d9b20d5 Optimize view read latency when the view ready
This branch includes the following new commits:
new d9b20d5 Optimize view read latency when the view ready
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[couchdb] 01/01: Optimize view read latency when the view ready
Posted by ga...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
garren pushed a commit to branch optimise-view-read
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit d9b20d5992e9f2d3f68187c271abe57cae7d79fe
Author: Garren Smith <ga...@gmail.com>
AuthorDate: Tue Nov 26 16:27:50 2019 +0200
Optimize view read latency when the view ready
If the view is already built, read the view status and view
in the same transaction. This will improve view read latency.
---
src/couch_views/src/couch_views.erl | 46 +++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/src/couch_views/src/couch_views.erl b/src/couch_views/src/couch_views.erl
index 7c7588c..322415b 100644
--- a/src/couch_views/src/couch_views.erl
+++ b/src/couch_views/src/couch_views.erl
@@ -44,36 +44,42 @@ query(Db, DDoc, ViewName, Callback, Acc0, Args0) ->
false -> ok
end,
- ok = maybe_update_view(Db, Mrst, Args3),
-
try
- couch_views_reader:read(Db, Mrst, ViewName, Callback, Acc0, Args3)
- after
- UpdateAfter = Args3#mrargs.update == lazy,
- if UpdateAfter == false -> ok; true ->
- couch_views_jobs:build_view_async(Db, Mrst)
- end
+ fabric2_fdb:transactional(Db, fun(TxDb) ->
+ ok = maybe_update_view(TxDb, Mrst, Args3),
+ read_view(TxDb, Mrst, ViewName, Callback, Acc0, Args3)
+ end)
+ catch throw:{build_view, WaitSeq} ->
+ couch_views_jobs:build_view(Db, Mrst, WaitSeq),
+ read_view(Db, Mrst, ViewName, Callback, Acc0, Args3)
end.
+read_view(Db, Mrst, ViewName, Callback, Acc0, Args) ->
+ fabric2_fdb:transactional(Db, fun(TxDb) ->
+ try
+ couch_views_reader:read(TxDb, Mrst, ViewName, Callback, Acc0, Args)
+ after
+ UpdateAfter = Args#mrargs.update == lazy,
+ if UpdateAfter == false -> ok; true ->
+ couch_views_jobs:build_view_async(TxDb, Mrst)
+ end
+ end
+ end).
+
+
maybe_update_view(_Db, _Mrst, #mrargs{update = false}) ->
ok;
maybe_update_view(_Db, _Mrst, #mrargs{update = lazy}) ->
ok;
-maybe_update_view(Db, Mrst, _Args) ->
- WaitSeq = fabric2_fdb:transactional(Db, fun(TxDb) ->
- DbSeq = fabric2_db:get_update_seq(TxDb),
- ViewSeq = couch_views_fdb:get_update_seq(TxDb, Mrst),
- case DbSeq == ViewSeq of
- true -> ready;
- false -> DbSeq
- end
- end),
-
- if WaitSeq == ready -> ok; true ->
- couch_views_jobs:build_view(Db, Mrst, WaitSeq)
+maybe_update_view(TxDb, Mrst, _Args) ->
+ DbSeq = fabric2_db:get_update_seq(TxDb),
+ ViewSeq = couch_views_fdb:get_update_seq(TxDb, Mrst),
+ case DbSeq == ViewSeq of
+ true -> ok;
+ false -> throw({build_view, DbSeq})
end.