remote: use DList Logger

instead of slow-to-append-to list. Thanks for the suggestion!

Closes #63.

Co-Authored-By: Travis Whitaker <pi.boy.travis@gmail.com>
This commit is contained in:
sorki 2023-12-03 16:51:55 +01:00
parent 675581903e
commit b506f1a2d7
6 changed files with 15 additions and 8 deletions

View File

@ -28,4 +28,5 @@ in order of appearance:
+ Luigy Leon @luigy
+ squalus @squalus
+ Vaibhav Sagar @vaibhavsagar
* Ryan Trinkle @ryantrinkle
+ Ryan Trinkle @ryantrinkle
+ Travis Whitaker @TravisWhitaker

View File

@ -117,6 +117,7 @@ library
, data-default-class
, dependent-sum > 0.7
, dependent-sum-template > 0.1.1 && < 0.3
, dlist >= 1.0
, generic-arbitrary < 1.1
, hashable
, text

View File

@ -121,7 +121,7 @@ runStoreOptsTCP host port sd code = do
(Network.Socket.addrAddress sockAddr)
sd
code
_ -> pure (Left RemoteStoreError_GetAddrInfoFailed, [])
_ -> pure (Left RemoteStoreError_GetAddrInfoFailed, mempty)
runStoreOpts'
:: Family

View File

@ -17,6 +17,7 @@ module System.Nix.Store.Remote.Client
import Control.Monad (unless, when)
import Control.Monad.Except (throwError)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.DList (DList)
import Data.Serialize.Put (Put, runPut)
import Data.Some (Some(Some))
@ -157,7 +158,7 @@ addToStore name source method hashAlgo repair = do
isValidPath :: MonadRemoteStore m => StorePath -> m Bool
isValidPath = doReq . IsValidPath
type Run m a = m (Either RemoteStoreError a, [Logger])
type Run m a = m (Either RemoteStoreError a, DList Logger)
runStoreSocket
:: ( Monad m

View File

@ -24,6 +24,7 @@ import Control.Monad.Trans.State.Strict (StateT, runStateT, mapStateT)
import Control.Monad.Trans.Except (ExceptT, runExceptT, mapExceptT)
import Control.Monad.Trans.Reader (ReaderT, runReaderT, withReaderT)
import Data.ByteString (ByteString)
import Data.DList (DList)
import Data.Word (Word64)
import Network.Socket (Socket)
import System.Nix.Nar (NarSource)
@ -33,8 +34,10 @@ import System.Nix.Store.Remote.Types.Logger (Logger)
import System.Nix.Store.Remote.Types.ProtoVersion (HasProtoVersion(..), ProtoVersion)
import System.Nix.Store.Remote.Types.StoreConfig (HasStoreSocket(..), StoreConfig)
import qualified Data.DList
data RemoteStoreState = RemoteStoreState {
remoteStoreState_logs :: [Logger]
remoteStoreState_logs :: DList Logger
, remoteStoreState_gotError :: Bool
, remoteStoreState_mDataSource :: Maybe (Word64 -> IO (Maybe ByteString))
-- ^ Source for @Logger_Read@, this will be called repeatedly
@ -121,7 +124,7 @@ runRemoteStoreT
)
=> r
-> RemoteStoreT r m a
-> m (Either RemoteStoreError a, [Logger])
-> m (Either RemoteStoreError a, DList Logger)
runRemoteStoreT r =
fmap (\(res, RemoteStoreState{..}) -> (res, remoteStoreState_logs))
. (`runReaderT` r)
@ -304,7 +307,7 @@ instance ( MonadIO m
appendLog x =
RemoteStoreT
$ modify
$ \s -> s { remoteStoreState_logs = remoteStoreState_logs s ++ [x] }
$ \s -> s { remoteStoreState_logs = remoteStoreState_logs s `Data.DList.snoc` x }
setError = RemoteStoreT $ modify $ \s -> s { remoteStoreState_gotError = True }
clearError = RemoteStoreT $ modify $ \s -> s { remoteStoreState_gotError = False }

View File

@ -29,6 +29,7 @@ import System.Nix.Build
import System.Nix.StorePath
import System.Nix.StorePath.Metadata
import System.Nix.Store.Remote
import System.Nix.Store.Remote.Client (Run)
import System.Nix.Store.Remote.MonadStore (mapStoreConfig)
import Crypto.Hash (SHA256)
@ -89,7 +90,7 @@ error: changing ownership of path '/run/user/1000/test-nix-store-06b0d249e561612
startDaemon
:: FilePath
-> IO (P.ProcessHandle, MonadStore a -> IO (Either RemoteStoreError a, [Logger]))
-> IO (P.ProcessHandle, MonadStore a -> Run IO a)
startDaemon fp = do
writeConf (fp </> "etc" </> "nix.conf")
p <- createProcessEnv fp "nix-daemon" []
@ -110,7 +111,7 @@ enterNamespaces = do
writeGroupMappings Nothing [GroupMapping 0 gid 1] True
withNixDaemon
:: ((MonadStore a -> IO (Either RemoteStoreError a, [Logger])) -> IO a) -> IO a
:: ((MonadStore a -> Run IO a) -> IO a) -> IO a
withNixDaemon action =
withSystemTempDirectory "test-nix-store" $ \path -> do