diff --git a/RaftFable/src/App.fs b/RaftFable/src/App.fs index 13559f0..f4e7d66 100644 --- a/RaftFable/src/App.fs +++ b/RaftFable/src/App.fs @@ -1,5 +1,6 @@ namespace RaftFable +open System open System.Collections.Generic open System.Security.Cryptography open Fable.Core.JS @@ -62,9 +63,9 @@ module App = (fun () -> match response with | RegisterClientResponse.Success client -> - if clients.TryAdd (client, HashSet ()) then - () - else + try + clients.Add (client, HashSet ()) + with :? ArgumentException -> failwith "got a response a second time - need to handle this in the UI" | RegisterClientResponse.NotLeader hint -> failwith "asked a non-leader, have to handle it" ) diff --git a/RaftFable/src/Ui.fs b/RaftFable/src/Ui.fs index ae3e1b4..19f0906 100644 --- a/RaftFable/src/Ui.fs +++ b/RaftFable/src/Ui.fs @@ -284,47 +284,48 @@ module Ui = | None -> leaderIdBox.innerText <- sprintf "%i: not a leader" userPrefs.LeaderUnderConsideration | Some leaderState -> - let knownStoredIndices = - leaderState.MatchIndex - |> Seq.mapi (fun target index -> - let target = target * 1 + let knownStoredIndices = + leaderState.MatchIndex + |> Seq.mapi (fun target index -> + let target = target * 1 - if target = userPrefs.LeaderUnderConsideration then - "(self)" - else - sprintf "%i" index - ) - |> Seq.toList - |> fun l -> "Log index known to be stored on each node" :: l - |> List.map (fun text -> - let node = document.createElement "div" - node.innerText <- text - Some node - ) + if target = userPrefs.LeaderUnderConsideration then + "(self)" + else + sprintf "%i" index + ) + |> Seq.toList + |> fun l -> "Log index known to be stored on each node" :: l + |> List.map (fun text -> + let node = document.createElement "div" + node.innerText <- text + Some node + ) - Table.createRow document knownStoredIndices ui.LeaderStateTable |> ignore + Table.createRow document knownStoredIndices ui.LeaderStateTable |> ignore - let nextToSend = - leaderState.ToSend - |> Seq.mapi (fun target index -> - let target = target * 1 + let nextToSend = + leaderState.ToSend + |> Seq.mapi (fun target index -> + let target = target * 1 - if target = userPrefs.LeaderUnderConsideration then - "(self)" - else - sprintf "%i" index - ) - |> Seq.toList - |> fun l -> "Will try next to send this index" :: l - |> List.map (fun text -> - let node = document.createElement "div" - node.innerText <- text - Some node - ) + if target = userPrefs.LeaderUnderConsideration then + "(self)" + else + sprintf "%i" index + ) + |> Seq.toList + |> fun l -> "Will try next to send this index" :: l + |> List.map (fun text -> + let node = document.createElement "div" + node.innerText <- text + Some node + ) - Table.createRow document nextToSend ui.LeaderStateTable |> ignore + Table.createRow document nextToSend ui.LeaderStateTable |> ignore Table.createHeaderRow document [ "Client ID" ; "Successful requests" ] ui.ClientsList + // Clients for KeyValue (clientId, committed) in state.Clients do let clientNode = @@ -339,8 +340,6 @@ module Ui = node.innerText <- text node - printfn "hi!" - Table.createRow document [ Some clientNode ; Some messagesNode ] ui.ClientsList |> ignore