summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2020-01-10 12:53:46 -0500
committerNick Vatamaniuc <vatamane@apache.org>2020-01-10 12:59:09 -0500
commit752d6d0e958db0c768d293fe253b81a7caaf317a (patch)
tree8198d4733822bbce9a215290f4c539ee0160eb9e
parent24201a34288b6d28c2153f6f9dc7f81bd50f8353 (diff)
downloadcouchdb-reset-target-shard-on-init-copy-retries.tar.gz
When shard splitting make sure to reset the targets before any retriesreset-target-shard-on-init-copy-retries
Previously the target was reset only when the whole job started, but not when the initial copy phase restarted on its own. If that happened, we left the target around so the retry failed always with the `eexist` error. Target reset has a check to make sure the shards are not in the global shard map, in case someone manually added them, for example. If they are found there the job panics and exists.
-rw-r--r--src/mem3/src/mem3_reshard_job.erl14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/mem3/src/mem3_reshard_job.erl b/src/mem3/src/mem3_reshard_job.erl
index d3a33d3f6..aedca21bb 100644
--- a/src/mem3/src/mem3_reshard_job.erl
+++ b/src/mem3/src/mem3_reshard_job.erl
@@ -184,19 +184,12 @@ run(#job{split_state = CurrState} = Job) ->
set_start_state(#job{split_state = State} = Job) ->
- case {State, maps:get(State, ?STATE_RESTART, undefined)} of
- {_, undefined} ->
+ case maps:get(State, ?STATE_RESTART, undefined) of
+ undefined ->
Fmt1 = "~p recover : unknown state ~s",
couch_log:error(Fmt1, [?MODULE, jobfmt(Job)]),
erlang:error({invalid_split_job_recover_state, Job});
- {initial_copy, initial_copy} ->
- % Since we recover from initial_copy to initial_copy, we need
- % to reset the target state as initial_copy expects to
- % create a new target
- Fmt2 = "~p recover : resetting target ~s",
- couch_log:notice(Fmt2, [?MODULE, jobfmt(Job)]),
- reset_target(Job);
- {_, StartState} ->
+ StartState->
Job#job{split_state = StartState}
end.
@@ -403,6 +396,7 @@ initial_copy_impl(#job{source = Source, target = Targets0} = Job) ->
LogMsg1 = "~p initial_copy started ~s",
LogArgs1 = [?MODULE, shardsstr(Source, Targets0)],
couch_log:notice(LogMsg1, LogArgs1),
+ reset_target(Job),
case couch_db_split:split(SourceName, TMap, fun pickfun/3) of
{ok, Seq} ->
LogMsg2 = "~p initial_copy of ~s finished @ seq:~p",