this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Refactor backoff into retry_acc

garrison 0ab7ee03 db388f6e

+32 -3
+2 -2
lib/transaction.ex
··· 99 99 100 100 # Note: this resends *all* requests if a single one fails due to too_old/too_new 101 101 # If a read touches a large number of servers this could become a problem 102 - backoff(nil, fn acc -> 102 + retry_acc(nil, fn acc -> 103 103 case acc || get_shards.() do 104 104 {:ok, shards} = shard_result -> 105 105 case do_multi_read(txn, keys, shards) do ··· 185 185 end 186 186 end 187 187 188 - backoff(nil, fn acc -> 188 + retry_acc(nil, fn acc -> 189 189 case acc || get_ranges.() do 190 190 {:ok, ranges} = acc -> 191 191 case do_read_split_range(txn, ranges) do
+29
lib/utils.ex
··· 376 376 |> Enum.sort() 377 377 end 378 378 379 + @spec retry_acc(term, (term -> {:cont, term, term} | {:halt, term}), pos_integer) :: term 380 + def retry_acc(acc, fun, count \\ 6) when is_function(fun, 1) and is_integer(count) and count > 0 do 381 + do_retry_acc(acc, fun, count, 1) 382 + end 383 + 384 + defp do_retry_acc(acc, fun, count, attempt) do 385 + assert attempt <= count 386 + 387 + case fun.(acc) do 388 + {:cont, acc, error} -> 389 + case attempt < count do 390 + true -> 391 + delay_ms = backoff_delay(attempt) 392 + SimProcess.sleep(delay_ms) 393 + do_retry_acc(acc, fun, count, attempt + 1) 394 + false -> 395 + error 396 + end 397 + 398 + {:halt, result} -> 399 + result 400 + end 401 + end 402 + 403 + defp backoff_delay(attempt) do 404 + # TODO: * 10 405 + Integer.pow(2, attempt) 406 + end 407 + 379 408 @spec backoff(term, ({:cont, term, term} | {:halt, term} -> term), non_neg_integer, non_neg_integer) :: term 380 409 def backoff(acc \\ nil, fun, count \\ 6, attempt \\ 0, last_error \\ nil) 381 410
+1 -1
lib/workloads.ex
··· 149 149 cluster_opts = Keyword.put(cluster_opts, :distributed, Sim.simulated?()) 150 150 {:ok, coordinator_pids} = Hobbes.Sandbox.start_cluster(cluster_opts) 151 151 152 - {:ok, %Cluster{} = cluster} = backoff(nil, fn _acc -> 152 + {:ok, %Cluster{} = cluster} = retry_acc(nil, fn _acc -> 153 153 case Hobbes.get_cluster(coordinator_pids) do 154 154 {:ok, _cluster} = result -> {:halt, result} 155 155 {:error, _err} = error -> {:cont, nil, error}