Skip to content

Commit b964a84

Browse files
committed
fabric: switch to maps for view rows
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.
1 parent 2d12ab0 commit b964a84

17 files changed

+2415
-222
lines changed

src/couch_mrview/src/couch_mrview.erl

+4-3
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ query_all_docs(Db, Args0, Callback, Acc) ->
273273
all_docs_fold(Db, Args2, Callback, Acc1).
274274

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

278279
query_view(Db, DDoc, VName, Args) when is_list(Args) ->
279280
query_view(Db, DDoc, VName, to_mrargs(Args), fun default_cb/2, []);
@@ -325,7 +326,7 @@ get_view_info(Db, DDoc, VName) ->
325326
Db,
326327
DDoc,
327328
VName,
328-
#mrargs{}
329+
#mrargs{extra = [{view_row_map, true}]}
329330
),
330331

331332
%% get the total number of rows
@@ -763,7 +764,7 @@ to_mrargs(KeyList) ->
763764
Index = lookup_index(couch_util:to_existing_atom(Key)),
764765
setelement(Index, Acc, Value)
765766
end,
766-
#mrargs{},
767+
#mrargs{extra = [{view_row_map, true}]},
767768
KeyList
768769
).
769770

src/couch_mrview/src/couch_mrview_http.erl

+6-3
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ row_to_json(Id0, Row) ->
472472
parse_params(#httpd{} = Req, Keys) ->
473473
parse_params(chttpd:qs(Req), Keys);
474474
parse_params(Props, Keys) ->
475-
Args = #mrargs{},
475+
Args = #mrargs{extra = [{view_row_map, true}]},
476476
parse_params(Props, Keys, Args).
477477

478478
parse_params(Props, Keys, Args) ->
@@ -511,13 +511,16 @@ parse_body_and_query(Req, Keys) ->
511511
#mrargs{
512512
keys = Keys,
513513
group = undefined,
514-
group_level = undefined
514+
group_level = undefined,
515+
extra = [{view_row_map, true}]
515516
},
516517
[keep_group_level]
517518
).
518519

519520
parse_body_and_query(Req, {Props}, Keys) ->
520-
Args = #mrargs{keys = Keys, group = undefined, group_level = undefined},
521+
Args = #mrargs{
522+
keys = Keys, group = undefined, group_level = undefined, extra = [{view_row_map, true}]
523+
},
521524
BodyArgs0 = parse_params(Props, Keys, Args, [decoded]),
522525
BodyArgs1 =
523526
case is_view(Req) of

0 commit comments

Comments
 (0)