Skip to content

Commit

Permalink
remote: add CollectGarbage StoreRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
sorki committed Dec 2, 2023
1 parent f28afe8 commit eaaaa99
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
12 changes: 12 additions & 0 deletions hnix-store-remote/src/System/Nix/Store/Remote/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ deriving via GenericArbitrary Logger
deriving via GenericArbitrary Verbosity
instance Arbitrary Verbosity

-- * GC

deriving via GenericArbitrary GCAction
instance Arbitrary GCAction

deriving via GenericArbitrary GCOptions
instance Arbitrary GCOptions

deriving via GenericArbitrary GCResult
instance Arbitrary GCResult

-- * Handshake

deriving via GenericArbitrary WorkerMagic
Expand All @@ -91,6 +102,7 @@ instance Arbitrary (Some StoreRequest) where
, Some . AddTempRoot <$> arbitrary
, Some <$> (BuildPaths <$> arbitrary <*> arbitrary)
, Some <$> (BuildDerivation <$> arbitrary <*> arbitrary <*> arbitrary)
, Some . CollectGarbage <$> arbitrary
, Some . EnsurePath <$> arbitrary
, pure $ Some FindRoots
, Some . IsValidPath <$> arbitrary
Expand Down
22 changes: 21 additions & 1 deletion hnix-store-remote/src/System/Nix/Store/Remote/Serializer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,16 @@ storeRequest = Serializer
buildMode' <- getS buildMode
pure $ Some (BuildDerivation path drv buildMode')

WorkerOp_CollectGarbage -> do
gcOptions_operation <- getS enum
gcOptions_pathsToDelete <- getS (hashSet storePath)
gcOptions_ignoreLiveness <- getS bool
gcOptions_maxFreed <- getS int
-- obsolete fields
Control.Monad.forM_ [0..(2 :: Word8)]
$ pure $ getS (int @Word8)
pure $ Some (CollectGarbage GCOptions{..})

WorkerOp_EnsurePath ->
Some . EnsurePath <$> getS storePath

Expand Down Expand Up @@ -1080,7 +1090,6 @@ storeRequest = Serializer
WorkerOp_AddToStoreNar -> undefined
WorkerOp_BuildPathsWithResults -> undefined
WorkerOp_ClearFailedPaths -> undefined
WorkerOp_CollectGarbage -> undefined
WorkerOp_ExportPath -> undefined
WorkerOp_HasSubstitutes -> undefined
WorkerOp_ImportPaths -> undefined
Expand Down Expand Up @@ -1139,6 +1148,17 @@ storeRequest = Serializer
putS derivation drv
putS buildMode buildMode'

Some (CollectGarbage GCOptions{..}) -> do
putS workerOp WorkerOp_CollectGarbage

putS enum gcOptions_operation
putS (hashSet storePath) gcOptions_pathsToDelete
putS bool gcOptions_ignoreLiveness
putS int gcOptions_maxFreed
-- obsolete fields
Control.Monad.forM_ [0..(2 :: Word8)]
$ pure $ putS int (0 :: Word8)

Some (EnsurePath path) -> do
putS workerOp WorkerOp_EnsurePath
putS storePath path
Expand Down
2 changes: 1 addition & 1 deletion hnix-store-remote/src/System/Nix/Store/Remote/Types/GC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ data GCOptions = GCOptions
-- | Paths to delete for @GCAction_DeleteSpecific@
, gcOptions_pathsToDelete :: HashSet StorePath
-- | Stop after `gcOptions_maxFreed` bytes have been freed
, gcOptions_maxFreed :: Integer
, gcOptions_maxFreed :: Word64
} deriving (Eq, Generic, Ord, Show)

-- | Result of the garbage collection operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import System.Nix.Signature (Signature)
import System.Nix.Store.Types (FileIngestionMethod, RepairMode)
import System.Nix.StorePath (StorePath, StorePathName, StorePathHashPart)
import System.Nix.StorePath.Metadata (Metadata)
import System.Nix.Store.Remote.Types.GC (GCOptions, GCResult)
import System.Nix.Store.Remote.Types.CheckMode (CheckMode)
import System.Nix.Store.Remote.Types.Query.Missing (Missing)
import System.Nix.Store.Remote.Types.StoreText (StoreText)
Expand Down Expand Up @@ -87,6 +88,10 @@ data StoreRequest :: Type -> Type where
-> BuildMode
-> StoreRequest BuildResult

CollectGarbage
:: GCOptions
-> StoreRequest GCResult

EnsurePath
:: StorePath
-> StoreRequest ()
Expand Down Expand Up @@ -169,6 +174,7 @@ instance {-# OVERLAPPING #-} Eq (Some StoreRequest) where
Some (AddTempRoot a) == Some (AddTempRoot a') = a == a'
Some (BuildPaths a b) == Some (BuildPaths a' b') = (a, b) == (a', b')
Some (BuildDerivation a b c) == Some (BuildDerivation a' b' c') = (a, b, c) == (a', b', c')
Some (CollectGarbage a) == Some (CollectGarbage a') = a == a'
Some (EnsurePath a) == Some (EnsurePath a') = a == a'
Some (FindRoots) == Some (FindRoots) = True
Some (IsValidPath a) == Some (IsValidPath a') = a == a'
Expand Down

0 comments on commit eaaaa99

Please sign in to comment.