remote: add CollectGarbage StoreRequest

This commit is contained in:
sorki 2023-12-02 15:26:21 +01:00
parent 6074504bcc
commit 217ea1b8ad
4 changed files with 40 additions and 2 deletions

View File

@ -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
@ -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

View File

@ -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
@ -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
@ -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

View File

@ -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

View File

@ -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)
@ -87,6 +88,10 @@ data StoreRequest :: Type -> Type where
-> BuildMode
-> StoreRequest BuildResult
CollectGarbage
:: GCOptions
-> StoreRequest GCResult
EnsurePath
:: StorePath
-> StoreRequest ()
@ -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'