summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Doane <jaydoane@apache.org>2023-01-09 21:34:29 -0800
committerJay Doane <jay.s.doane@gmail.com>2023-01-11 14:54:03 -0800
commitb3b57e4457a838f92ea70f3e2cbabcc0532f1b9e (patch)
tree51afdbe00d682a8227a65c20f0e4e36f95892f27
parent1c43d028936c16f55882f702a14497aa1b168717 (diff)
downloadcouchdb-b3b57e4457a838f92ea70f3e2cbabcc0532f1b9e.tar.gz
Fix replication _scheduler/docs total_rows
The total_rows property was decremented by one to account for the VDU that was automatically added to the total. Now that a BDU has replaced the VDU [1] total_rows is one less than it should be. This removes the decrement so that total_rows equals the actual doc count. [1] https://github.com/apache/couchdb/pull/4274
-rw-r--r--src/couch_replicator/src/couch_replicator_httpd_util.erl8
-rw-r--r--src/couch_replicator/test/eunit/couch_replicator_scheduler_docs_tests.erl77
2 files changed, 78 insertions, 7 deletions
diff --git a/src/couch_replicator/src/couch_replicator_httpd_util.erl b/src/couch_replicator/src/couch_replicator_httpd_util.erl
index ddcc179d4..17efee3b3 100644
--- a/src/couch_replicator/src/couch_replicator_httpd_util.erl
+++ b/src/couch_replicator/src/couch_replicator_httpd_util.erl
@@ -158,7 +158,7 @@ docs_cb({meta, Meta}, #vacc{meta_sent = false, row_sent = false} = Acc) ->
Parts =
case couch_util:get_value(total, Meta) of
undefined -> [];
- Total -> [io_lib:format("\"total_rows\":~p", [adjust_total(Total)])]
+ Total -> [io_lib:format("\"total_rows\":~p", [Total])]
end ++
case couch_util:get_value(offset, Meta) of
undefined -> [];
@@ -193,9 +193,3 @@ row_to_json(Row) ->
Doc0 = couch_util:get_value(doc, Row),
Doc1 = update_db_name(Doc0),
?JSON_ENCODE(Doc1).
-
-%% Adjust Total as there is an automatically created validation design doc
-adjust_total(Total) when is_integer(Total), Total > 0 ->
- Total - 1;
-adjust_total(Total) when is_integer(Total) ->
- 0.
diff --git a/src/couch_replicator/test/eunit/couch_replicator_scheduler_docs_tests.erl b/src/couch_replicator/test/eunit/couch_replicator_scheduler_docs_tests.erl
new file mode 100644
index 000000000..bb71bf305
--- /dev/null
+++ b/src/couch_replicator/test/eunit/couch_replicator_scheduler_docs_tests.erl
@@ -0,0 +1,77 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_replicator_scheduler_docs_tests).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+
+scheduler_docs_test_() ->
+ {
+ foreach,
+ fun() ->
+ Ctx = couch_replicator_test_helper:test_setup(),
+ ok = config:set("replicator", "cluster_start_period", "0", false),
+ Opts = [{q, 1}, {n, 1}, ?ADMIN_CTX],
+ case fabric:create_db(<<"_replicator">>, Opts) of
+ ok -> ok;
+ {error, file_exists} -> ok
+ end,
+ Ctx
+ end,
+ fun(Ctx) ->
+ ok = config:delete("replicator", "cluster_start_period"),
+ ok = fabric:delete_db(<<"_replicator">>, [?ADMIN_CTX]),
+ couch_replicator_test_helper:test_teardown(Ctx)
+ end,
+ [
+ ?TDEF_FE(t_scheduler_docs_total_rows, 10)
+ ]
+ }.
+
+t_scheduler_docs_total_rows({_Ctx, {Source, Target}}) ->
+ SourceUrl = couch_replicator_test_helper:cluster_db_url(Source),
+ TargetUrl = couch_replicator_test_helper:cluster_db_url(Target),
+ RepDoc = jiffy:encode(
+ {[
+ {<<"source">>, SourceUrl},
+ {<<"target">>, TargetUrl}
+ ]}
+ ),
+ RepDocUrl = couch_replicator_test_helper:cluster_db_url(
+ list_to_binary("/_replicator/" ++ ?docid())
+ ),
+ {ok, 201, _, _} = test_request:put(binary_to_list(RepDocUrl), [], RepDoc),
+ SchedulerDocsUrl =
+ couch_replicator_test_helper:cluster_db_url(<<"/_scheduler/docs">>),
+ Body = test_util:wait(
+ fun() ->
+ case test_request:get(binary_to_list(SchedulerDocsUrl), []) of
+ {ok, 200, _, JsonBody} ->
+ Decoded = jiffy:decode(JsonBody, [return_maps]),
+ case maps:get(<<"docs">>, Decoded) of
+ [] ->
+ wait;
+ _ ->
+ Decoded
+ end;
+ _ ->
+ wait
+ end
+ end,
+ 10000,
+ 1000
+ ),
+ Docs = maps:get(<<"docs">>, Body),
+ TotalRows = maps:get(<<"total_rows">>, Body),
+ ?assertEqual(TotalRows, length(Docs)),
+ ok.