this repo has no description
2
fork

Configure Feed

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

Start stateful servers in slots on restart

garrison 9cf2b642 dbc5bb11

+41 -9
+40 -8
lib/servers/server_supervisor.ex
··· 220 220 end 221 221 222 222 defp load_tlog_slots(%State{} = state) do 223 - Enum.reduce(state.slots.tlog, {[], state}, fn path, {acc, state} -> 224 - SimFile.mkdir_p(path) 225 - # TODO: start existing and accumulate slots which lack tlogs for this generation 226 - {[path | acc], state} 223 + Enum.reduce(state.slots.tlog, {[], state}, fn slot_path, {acc, state} -> 224 + SimFile.mkdir_p(slot_path) 225 + 226 + # [{path, generation}, ...] 227 + kv_files = 228 + SimFile.ls(slot_path) 229 + |> then(fn {:ok, names} -> names end) 230 + |> Enum.reduce([], fn name, acc -> 231 + case Regex.run(~r"^tlog_gen_(\d+)\.kv$", name) do 232 + [^name, gen_str] -> [{slot_path <> "/" <> name, String.to_integer(gen_str)} | acc] 233 + nil -> acc 234 + end 235 + end) 236 + 237 + %State{} = state = 238 + Enum.reduce(kv_files, state, fn {kv_path, gen}, state -> 239 + {state, _pid} = spawn_child(state, gen, Hobbes.Servers.TLog, %{path: kv_path, cluster: state.cluster}, %{path: kv_path}) 240 + state 241 + end) 242 + 243 + # Only mark this slot as open if there is no TLog for the current generation 244 + # TODO: in practice this is essentially unreachable as a ServerSupervisor rebooting during the current generation should cause a recovery 245 + # Maybe assert this away or find a way to guarantee that recovery occurs? 246 + case Enum.any?(kv_files, fn {_path, gen} -> gen == state.cluster.generation end) do 247 + true -> {acc, state} 248 + false -> {[slot_path | acc], state} 249 + end 227 250 end) 228 251 |> then(fn {tlog_slots, state} -> 229 252 %{state | open_tlog: Enum.reverse(tlog_slots)} ··· 231 254 end 232 255 233 256 defp load_storage_slots(%State{} = state) do 234 - Enum.reduce(state.slots.storage, {[], state}, fn path, {acc, state} -> 235 - SimFile.mkdir_p(path) 236 - # TODO: start existing 237 - {[path | acc], state} 257 + Enum.reduce(state.slots.storage, {[], state}, fn slot_path, {acc, state} -> 258 + SimFile.mkdir_p(slot_path) 259 + 260 + kv_path = slot_path <> "/storage.kv" 261 + case SimFile.exists?(kv_path) do 262 + true -> 263 + gen = nil 264 + {state, _pid} = spawn_child(state, gen, Hobbes.Servers.Storage, %{path: kv_path, cluster: state.cluster}, %{path: kv_path}) 265 + 266 + {acc, state} 267 + 268 + false -> {[slot_path | acc], state} 269 + end 238 270 end) 239 271 |> then(fn {storage_slots, state} -> 240 272 %{state | open_storage: Enum.reverse(storage_slots)}
+1 -1
lib/servers/storage.ex
··· 487 487 TLog.peek(pid, nonce, tag, start_version) 488 488 end) 489 489 490 - SimServer.send_after self(), {:peek_timeout, nonce}, 100 490 + SimServer.send_after self(), {:peek_timeout, nonce}, 300 491 491 %{state | peek_nonce: nonce, peek_results: %{}} 492 492 end 493 493