Skip to content

Commit

Permalink
feat(dumblog): fix debug-file support for internal-messages/admin
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-daniel-gustafsson committed Mar 28, 2022
1 parent 856ca20 commit df8bb7e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/sut/dumblog/src/Dumblog/Journal/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import qualified Dumblog.Journal.Logger as DLogger
import Dumblog.Journal.Snapshot (Snapshot)
import qualified Dumblog.Journal.Snapshot as Snapshot
import Dumblog.Journal.StateMachine (InMemoryDumblog, initState)
import Dumblog.Journal.Types (ClientRequest(..), Input(..))
import Dumblog.Journal.Types (ClientRequest(..), Input(..), CommandName(..))
import Dumblog.Journal.Versions (dUMBLOG_CURRENT_VERSION, runCommand)
import Dumblog.Journal.Worker (WorkerInfo(..), worker)

Expand Down Expand Up @@ -101,14 +101,11 @@ replayDebug originCommands originState = do
(s', r) <- runCommand v (DLogger.queueLogger logger) s cmd
logLines <- DLogger.flushQueue logger
let
ev = case cmd of
ClientRequest (Read {}) -> "read"
ClientRequest (Write {})-> "write"
msg = show cmd
ce = DebEvent
{ from = "client"
, to = "dumblog"
, event = ev
, event = commandName cmd
, receivedLogical = logTime
, message = msg
}
Expand All @@ -120,7 +117,7 @@ replayDebug originCommands originState = do
, sent = [ DebEvent
{ from = "dumblog"
, to = "client"
, event = ev
, event = commandName r
, receivedLogical = logTime
, message = show r
}
Expand Down
29 changes: 29 additions & 0 deletions src/sut/dumblog/src/Dumblog/Journal/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,67 @@ import GHC.Generics (Generic)

------------------------------------------------------------------------

class CommandName c where
commandName :: c -> String

data Input
= ClientRequest ClientRequest
| InternalMessageIn InternalMessage
| AdminCommand AdminCommand
deriving stock (Generic, Show)
deriving anyclass Binary

instance CommandName Input where
commandName c = case c of
ClientRequest cr -> commandName cr
InternalMessageIn im -> commandName im
AdminCommand ac -> commandName ac

data ClientRequest
= Write ByteString
| Read Int
deriving stock (Generic, Show)
deriving anyclass Binary

instance CommandName ClientRequest where
commandName (Read {}) = "read"
commandName (Write {}) = "write"

data AdminCommand
= Connect Int
deriving stock (Generic, Show)
deriving anyclass Binary

instance CommandName AdminCommand where
commandName (Connect{}) = "connect"

data Output
= ClientResponse ClientResponse
| InternalMessageOut InternalMessage
| AdminResponse
deriving stock Show

instance CommandName Output where
commandName c = case c of
ClientResponse cr -> commandName cr
InternalMessageOut im -> commandName im
AdminResponse -> "admin" -- maybe not the nicest name

data ClientResponse
= OK ByteString
| NotFound
| Error ByteString
deriving stock Show

instance CommandName ClientResponse where
commandName _ = "client" -- maybe not the nicest name

data InternalMessage
= Backup Int ByteString
| Ack Int
deriving stock (Generic, Show)
deriving anyclass Binary

instance CommandName InternalMessage where
commandName (Backup {}) = "backup"
commandName (Ack {}) = "ack"

0 comments on commit df8bb7e

Please sign in to comment.