summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Avdey <eiri@eiri.ca>2019-02-14 16:11:27 -0400
committerEric Avdey <eiri@eiri.ca>2019-02-15 21:45:04 -0400
commit92d406f74f81ab959c25d64ddd456c948aa571c2 (patch)
treed95d54e1c0e9638072c656546c6f31646a7a0fc8
parent5df22607c6b7a97367ec8b1d07fd748d6b8e8989 (diff)
downloadcouchdb-92d406f74f81ab959c25d64ddd456c948aa571c2.tar.gz
Restrict target map's size to min 2
-rw-r--r--src/couch/src/couch_db_split.erl3
-rw-r--r--src/couch/test/couch_db_split_tests.erl22
2 files changed, 18 insertions, 7 deletions
diff --git a/src/couch/src/couch_db_split.erl b/src/couch/src/couch_db_split.erl
index dc5a5f77c..87570b4f3 100644
--- a/src/couch/src/couch_db_split.erl
+++ b/src/couch/src/couch_db_split.erl
@@ -54,7 +54,8 @@
% Public API
-split(Source, #{} = Targets, PickFun) when is_function(PickFun, 3) ->
+split(Source, #{} = Targets, PickFun) when
+ map_size(Targets) >= 2, is_function(PickFun, 3) ->
case couch_db:open_int(Source, [?ADMIN_CTX]) of
{ok, SourceDb} ->
Engine = get_engine(SourceDb),
diff --git a/src/couch/test/couch_db_split_tests.erl b/src/couch/test/couch_db_split_tests.erl
index b41231a81..14c42fd47 100644
--- a/src/couch/test/couch_db_split_tests.erl
+++ b/src/couch/test/couch_db_split_tests.erl
@@ -16,7 +16,7 @@
-include_lib("couch/include/couch_db.hrl").
-define(RINGTOP, 2 bsl 31).
--define(BIGRANGE, [0, 2 bsl 31 - 1]).
+
setup() ->
DbName = ?tempdb(),
@@ -35,7 +35,6 @@ teardown(DbName) ->
split_test_() ->
Cases = [
{"Should split an empty shard", 0, 2},
- {"Should split shard into itself", 100, 1},
{"Should split shard in half", 100, 2},
{"Should split shard in three", 99, 3},
{"Should split shard in four", 100, 4}
@@ -54,7 +53,8 @@ split_test_() ->
fun setup/0, fun teardown/1,
[
fun should_fail_on_missing_source/1,
- fun should_fail_on_existing_target/1
+ fun should_fail_on_existing_target/1,
+ fun should_crash_on_invalid_tmap/1
]
}
]
@@ -94,17 +94,26 @@ should_split_shard({Desc, TotalDocs, Q}, DbName) ->
should_fail_on_missing_source(_DbName) ->
DbName = ?tempdb(),
- TMap = maps:from_list([{?BIGRANGE, ?tempdb()}]),
+ Ranges = make_ranges(2),
+ TMap = make_targets(Ranges),
Response = couch_db_split:split(DbName, TMap, fun fake_pickfun/3),
?_assertEqual({error, missing_source}, Response).
should_fail_on_existing_target(DbName) ->
- TMap = maps:from_list([{?BIGRANGE, DbName}]),
+ Ranges = make_ranges(2),
+ TMap = maps:map(fun(_, _) -> DbName end, make_targets(Ranges)),
Response = couch_db_split:split(DbName, TMap, fun fake_pickfun/3),
?_assertMatch({error, {target_create_error, DbName, eexist}}, Response).
+should_crash_on_invalid_tmap(DbName) ->
+ Ranges = make_ranges(1),
+ TMap = make_targets(Ranges),
+ ?_assertError(function_clause,
+ couch_db_split:split(DbName, TMap, fun fake_pickfun/3)).
+
+
copy_local_docs_test_() ->
Cases = [
{"Should work with no docs", 0, 2},
@@ -157,7 +166,8 @@ should_copy_local_docs({Desc, TotalDocs, Q}, DbName) ->
should_fail_copy_local_on_missing_source() ->
DbName = ?tempdb(),
- TMap = maps:from_list([{?BIGRANGE, ?tempdb()}]),
+ Ranges = make_ranges(2),
+ TMap = make_targets(Ranges),
PickFun = fun fake_pickfun/3,
Response = couch_db_split:copy_local_docs(DbName, TMap, PickFun),
?assertEqual({error, missing_source}, Response).