Skip to content

Commit

Permalink
fabric: switch to maps for view rows
Browse files Browse the repository at this point in the history
The `#view_row{}` record that is used for capturing messages with
row data is not flexible enough to have it extended easily.  If
one wanted to introduce a fresh field, the change would have to be
propagated through many functions and modules.  Especially, if
support for mixed-version clusters is a concern, this would come
with some degree of duplication.

Leverage Erlang/OTP's built-in maps for mitigating this issue and
offer the view callbacks the `view_row_map` Boolean key in
`#mrargs.extra` to request this communication format.  This way the
old record-based format would be still in use unless requested
otherwise.  This facilitates the smooth interoperability of old
coordinators and new workers.  In parallel to that, the new
coordinator could still receive view rows from old workers.
  • Loading branch information
pgj committed Mar 15, 2024
1 parent 2d12ab0 commit b964a84
Show file tree
Hide file tree
Showing 17 changed files with 2,415 additions and 222 deletions.
7 changes: 4 additions & 3 deletions src/couch_mrview/src/couch_mrview.erl
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ query_all_docs(Db, Args0, Callback, Acc) ->
all_docs_fold(Db, Args2, Callback, Acc1).

query_view(Db, DDoc, VName) ->
query_view(Db, DDoc, VName, #mrargs{}).
Args = #mrargs{extra = [{view_row_map, true}]},
query_view(Db, DDoc, VName, Args).

query_view(Db, DDoc, VName, Args) when is_list(Args) ->
query_view(Db, DDoc, VName, to_mrargs(Args), fun default_cb/2, []);
Expand Down Expand Up @@ -325,7 +326,7 @@ get_view_info(Db, DDoc, VName) ->
Db,
DDoc,
VName,
#mrargs{}
#mrargs{extra = [{view_row_map, true}]}
),

%% get the total number of rows
Expand Down Expand Up @@ -763,7 +764,7 @@ to_mrargs(KeyList) ->
Index = lookup_index(couch_util:to_existing_atom(Key)),
setelement(Index, Acc, Value)
end,
#mrargs{},
#mrargs{extra = [{view_row_map, true}]},
KeyList
).

Expand Down
9 changes: 6 additions & 3 deletions src/couch_mrview/src/couch_mrview_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ row_to_json(Id0, Row) ->
parse_params(#httpd{} = Req, Keys) ->
parse_params(chttpd:qs(Req), Keys);
parse_params(Props, Keys) ->
Args = #mrargs{},
Args = #mrargs{extra = [{view_row_map, true}]},
parse_params(Props, Keys, Args).

parse_params(Props, Keys, Args) ->
Expand Down Expand Up @@ -511,13 +511,16 @@ parse_body_and_query(Req, Keys) ->
#mrargs{
keys = Keys,
group = undefined,
group_level = undefined
group_level = undefined,
extra = [{view_row_map, true}]
},
[keep_group_level]
).

parse_body_and_query(Req, {Props}, Keys) ->
Args = #mrargs{keys = Keys, group = undefined, group_level = undefined},
Args = #mrargs{
keys = Keys, group = undefined, group_level = undefined, extra = [{view_row_map, true}]
},
BodyArgs0 = parse_params(Props, Keys, Args, [decoded]),
BodyArgs1 =
case is_view(Req) of
Expand Down

0 comments on commit b964a84

Please sign in to comment.