Created
February 12, 2013 13:38
-
-
Save bdionne/4769933 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| update_rep_doc(RepDbName, RepDocId, KVs) when is_binary(RepDocId) -> | |
| {Pid, Ref} = | |
| spawn_monitor(fun() -> | |
| try | |
| case fabric:open_doc(mem3:dbname(RepDbName), RepDocId, []) of | |
| {ok, LatestRepDoc} -> | |
| update_rep_doc(RepDbName, LatestRepDoc, KVs); | |
| _ -> | |
| ok | |
| end | |
| catch | |
| throw:conflict -> | |
| % a race condition may cause an update conflict, | |
| % in which cae update_rep_doc is called again to refetch | |
| twig:log(error, "Conflict error when updating replication document `~s`." | |
| " Retrying.", [RepDocId]), | |
| ok = timer:sleep(5), | |
| update_rep_doc(RepDbName, RepDocId, KVs); | |
| Type:Error -> | |
| exit({Type, Error}) | |
| end | |
| end), | |
| receive | |
| {'DOWN', Ref, process, Pid, normal} -> | |
| ok; | |
| {'DOWN', Ref, process, Pid, {throw, Error}} -> | |
| throw(Error); | |
| {'DOWN', Ref, process, Pid, {error, Error}} -> | |
| erlang:error(Error) | |
| end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment