

broadcast
  put in queue
  put in rocksdb log
    <8 txid><8 term> msg

receive BatchPush
  if last term or last txid is too high
    send BatchRes
      false
      batch id
      last learned term
      last learned tx
    return
  if last term or last txid is lower than our tip
    throw away everything beyond that (it should not be committed)
    
  else
    append
    send BatchRes
      true
      batch id

receive BatchRes
  if accepted
    bump peer's last accepted to this batch id
    if all peers highest accept # is >= this batch id
      throw it away
    send next if it exists
  else
    if peer's last accepted no longer is present in local log
      snapshot range
      send batch push 
  





server 
  has receiver for event loop messages
  thread loops <recv> process <reply>

event loop
  configurable slots
  sends to handler, passing through wire codec
  thread runs

ServerConn
  max in-flight req of one
  when it reads, keep allowing reading until single complete
  when it finishes reading, it sends request away and disables all notifications
  when it receives response, it allows only writing
  when it finishes sending, it allows only reading

clients
  4096 (configurable) max conns
  <ClientReq,ClientRes>

peers
  16 (configurable) max conns

id | action | key len | val len | key | val
8  |   1    |   2     |    6    | <-  | <-


ByteBuf -> Codec<ByteBuf, Req> -> StateMachine<Req, Res>.handle(req) -> Codec<ByteBuf, Res> -> ByteBuf

StateMachine may care about
  message
  origin

