Skip to content

Commit 2832079

Browse files
sorkiTravisWhitaker
andcommitted
remote: use DList Logger
instead of slow-to-append-to list. Thanks for the suggestion! Closes #63. Co-Authored-By: Travis Whitaker <[email protected]>
1 parent 58011db commit 2832079

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

docs/01-Contributors.org

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ in order of appearance:
2828
+ Luigy Leon @luigy
2929
+ squalus @squalus
3030
+ Vaibhav Sagar @vaibhavsagar
31-
* Ryan Trinkle @ryantrinkle
31+
+ Ryan Trinkle @ryantrinkle
32+
+ Travis Whitaker @TravisWhitaker

hnix-store-remote/hnix-store-remote.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ library
117117
, data-default-class
118118
, dependent-sum > 0.7
119119
, dependent-sum-template > 0.1.1 && < 0.3
120+
, dlist >= 1.0
120121
, generic-arbitrary < 1.1
121122
, hashable
122123
, text

hnix-store-remote/src/System/Nix/Store/Remote.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ runStoreOptsTCP host port sd code = do
121121
(Network.Socket.addrAddress sockAddr)
122122
sd
123123
code
124-
_ -> pure (Left RemoteStoreError_GetAddrInfoFailed, [])
124+
_ -> pure (Left RemoteStoreError_GetAddrInfoFailed, mempty)
125125

126126
runStoreOpts'
127127
:: Family

hnix-store-remote/src/System/Nix/Store/Remote/Client.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module System.Nix.Store.Remote.Client
1717
import Control.Monad (unless, when)
1818
import Control.Monad.Except (throwError)
1919
import Control.Monad.IO.Class (MonadIO, liftIO)
20+
import Data.DList (DList)
2021
import Data.Serialize.Put (Put, runPut)
2122
import Data.Some (Some(Some))
2223

@@ -157,7 +158,7 @@ addToStore name source method hashAlgo repair = do
157158
isValidPath :: MonadRemoteStore m => StorePath -> m Bool
158159
isValidPath = doReq . IsValidPath
159160

160-
type Run m a = m (Either RemoteStoreError a, [Logger])
161+
type Run m a = m (Either RemoteStoreError a, DList Logger)
161162

162163
runStoreSocket
163164
:: ( Monad m

hnix-store-remote/src/System/Nix/Store/Remote/MonadStore.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Control.Monad.Trans.State.Strict (StateT, runStateT, mapStateT)
2424
import Control.Monad.Trans.Except (ExceptT, runExceptT, mapExceptT)
2525
import Control.Monad.Trans.Reader (ReaderT, runReaderT, withReaderT)
2626
import Data.ByteString (ByteString)
27+
import Data.DList (DList)
2728
import Data.Word (Word64)
2829
import Network.Socket (Socket)
2930
import System.Nix.Nar (NarSource)
@@ -33,8 +34,10 @@ import System.Nix.Store.Remote.Types.Logger (Logger)
3334
import System.Nix.Store.Remote.Types.ProtoVersion (HasProtoVersion(..), ProtoVersion)
3435
import System.Nix.Store.Remote.Types.StoreConfig (HasStoreSocket(..), StoreConfig)
3536

37+
import qualified Data.DList
38+
3639
data RemoteStoreState = RemoteStoreState {
37-
remoteStoreState_logs :: [Logger]
40+
remoteStoreState_logs :: DList Logger
3841
, remoteStoreState_gotError :: Bool
3942
, remoteStoreState_mDataSource :: Maybe (Word64 -> IO (Maybe ByteString))
4043
-- ^ Source for @Logger_Read@, this will be called repeatedly
@@ -121,7 +124,7 @@ runRemoteStoreT
121124
)
122125
=> r
123126
-> RemoteStoreT r m a
124-
-> m (Either RemoteStoreError a, [Logger])
127+
-> m (Either RemoteStoreError a, DList Logger)
125128
runRemoteStoreT r =
126129
fmap (\(res, RemoteStoreState{..}) -> (res, remoteStoreState_logs))
127130
. (`runReaderT` r)
@@ -304,7 +307,7 @@ instance ( MonadIO m
304307
appendLog x =
305308
RemoteStoreT
306309
$ modify
307-
$ \s -> s { remoteStoreState_logs = remoteStoreState_logs s ++ [x] }
310+
$ \s -> s { remoteStoreState_logs = remoteStoreState_logs s `Data.DList.snoc` x }
308311

309312
setError = RemoteStoreT $ modify $ \s -> s { remoteStoreState_gotError = True }
310313
clearError = RemoteStoreT $ modify $ \s -> s { remoteStoreState_gotError = False }

hnix-store-remote/tests-io/NixDaemon.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import System.Nix.Build
2929
import System.Nix.StorePath
3030
import System.Nix.StorePath.Metadata
3131
import System.Nix.Store.Remote
32+
import System.Nix.Store.Remote.Client (Run)
3233
import System.Nix.Store.Remote.MonadStore (mapStoreConfig)
3334

3435
import Crypto.Hash (SHA256)
@@ -89,7 +90,7 @@ error: changing ownership of path '/run/user/1000/test-nix-store-06b0d249e561612
8990

9091
startDaemon
9192
:: FilePath
92-
-> IO (P.ProcessHandle, MonadStore a -> IO (Either RemoteStoreError a, [Logger]))
93+
-> IO (P.ProcessHandle, MonadStore a -> Run IO a)
9394
startDaemon fp = do
9495
writeConf (fp </> "etc" </> "nix.conf")
9596
p <- createProcessEnv fp "nix-daemon" []
@@ -110,7 +111,7 @@ enterNamespaces = do
110111
writeGroupMappings Nothing [GroupMapping 0 gid 1] True
111112

112113
withNixDaemon
113-
:: ((MonadStore a -> IO (Either RemoteStoreError a, [Logger])) -> IO a) -> IO a
114+
:: ((MonadStore a -> Run IO a) -> IO a) -> IO a
114115
withNixDaemon action =
115116
withSystemTempDirectory "test-nix-store" $ \path -> do
116117

0 commit comments

Comments
 (0)