Skip to content

Commit

Permalink
fix(sut): make the zero-copy variant work by blocking cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Mar 15, 2022
1 parent bd62665 commit 5b7895e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 14 additions & 4 deletions src/sut/dumblog/src/Dumblog/ZeroCopy/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Control.Concurrent (MVar)
import Control.Concurrent.Async (link, withAsync)
import Journal (allocateJournal, defaultOptions, startJournal)
import Journal.Internal.Logger (nullLogger)
import Journal.Types (oLogger, oTermBufferLength)
import Journal.Types
(Subscriber(Sub2), oLogger, oMaxSubscriber, oTermBufferLength)

import Dumblog.ZeroCopy.HttpServer
import Dumblog.ZeroCopy.State
Expand All @@ -14,9 +15,18 @@ import Dumblog.ZeroCopy.Worker

zeroCopyDumblog :: Int -> Int -> FilePath -> Maybe (MVar ()) -> IO ()
zeroCopyDumblog capacity port fp mReady = do
let opts = defaultOptions { oTermBufferLength = capacity
, oLogger = nullLogger
}
let opts = defaultOptions
{ oTermBufferLength = capacity
, oLogger = nullLogger
-- NOTE: A second subscriber whose bytes consumed is never
-- incremented is used to avoid cleaning up the journal,
-- otherwise we can have reads that point to a cleaned up part of
-- the journal. A better longer term solution would be to have
-- the compaction phase of the journal store the data somewhere
-- more long term and update the in-memory location to point to
-- that instead and allow the journal to be cleaned up.
, oMaxSubscriber = Sub2
}
allocateJournal fp opts
jour <- startJournal fp opts
state <- initState 40000 fp
Expand Down
4 changes: 0 additions & 4 deletions src/sut/dumblog/src/Dumblog/ZeroCopy/Worker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ worker jour = go
go state'
Just (Read ix) -> do
conn <- mkSocket (CInt fd)
-- XXX: We need to not do `cleanBufferTo` otherwise it will clean
-- away the journal before can reply to it. I guess we could also
-- try to have subscriber `Sub2` never advance its consumed bytes
-- counter to disable cleaning...
readSendfile state conn ix
go state
Nothing -> go state
Expand Down

0 comments on commit 5b7895e

Please sign in to comment.