Skip to content

Commit e276f3b

Browse files
committed
remote: add CollectGarbage StoreRequest
1 parent c565768 commit e276f3b

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ deriving via GenericArbitrary Logger
6969
deriving via GenericArbitrary Verbosity
7070
instance Arbitrary Verbosity
7171

72+
-- * GC
73+
74+
deriving via GenericArbitrary GCAction
75+
instance Arbitrary GCAction
76+
77+
deriving via GenericArbitrary GCOptions
78+
instance Arbitrary GCOptions
79+
80+
deriving via GenericArbitrary GCResult
81+
instance Arbitrary GCResult
82+
7283
-- * Handshake
7384

7485
deriving via GenericArbitrary WorkerMagic
@@ -91,6 +102,7 @@ instance Arbitrary (Some StoreRequest) where
91102
, Some . AddTempRoot <$> arbitrary
92103
, Some <$> (BuildPaths <$> arbitrary <*> arbitrary)
93104
, Some <$> (BuildDerivation <$> arbitrary <*> arbitrary <*> arbitrary)
105+
, Some . CollectGarbage <$> arbitrary
94106
, Some . EnsurePath <$> arbitrary
95107
, pure $ Some FindRoots
96108
, Some . IsValidPath <$> arbitrary

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,16 @@ storeRequest = Serializer
10171017
buildMode' <- getS buildMode
10181018
pure $ Some (BuildDerivation path drv buildMode')
10191019

1020+
WorkerOp_CollectGarbage -> do
1021+
gcOptions_operation <- getS enum
1022+
gcOptions_pathsToDelete <- getS (hashSet storePath)
1023+
gcOptions_ignoreLiveness <- getS bool
1024+
gcOptions_maxFreed <- getS int
1025+
-- obsolete fields
1026+
Control.Monad.forM_ [0..(2 :: Word8)]
1027+
$ pure $ getS (int @Word8)
1028+
pure $ Some (CollectGarbage GCOptions{..})
1029+
10201030
WorkerOp_EnsurePath ->
10211031
Some . EnsurePath <$> getS storePath
10221032

@@ -1080,7 +1090,6 @@ storeRequest = Serializer
10801090
WorkerOp_AddToStoreNar -> undefined
10811091
WorkerOp_BuildPathsWithResults -> undefined
10821092
WorkerOp_ClearFailedPaths -> undefined
1083-
WorkerOp_CollectGarbage -> undefined
10841093
WorkerOp_ExportPath -> undefined
10851094
WorkerOp_HasSubstitutes -> undefined
10861095
WorkerOp_ImportPaths -> undefined
@@ -1139,6 +1148,17 @@ storeRequest = Serializer
11391148
putS derivation drv
11401149
putS buildMode buildMode'
11411150

1151+
Some (CollectGarbage GCOptions{..}) -> do
1152+
putS workerOp WorkerOp_CollectGarbage
1153+
1154+
putS enum gcOptions_operation
1155+
putS (hashSet storePath) gcOptions_pathsToDelete
1156+
putS bool gcOptions_ignoreLiveness
1157+
putS int gcOptions_maxFreed
1158+
-- obsolete fields
1159+
Control.Monad.forM_ [0..(2 :: Word8)]
1160+
$ pure $ putS int (0 :: Word8)
1161+
11421162
Some (EnsurePath path) -> do
11431163
putS workerOp WorkerOp_EnsurePath
11441164
putS storePath path

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ data GCOptions = GCOptions
3030
-- | Paths to delete for @GCAction_DeleteSpecific@
3131
, gcOptions_pathsToDelete :: HashSet StorePath
3232
-- | Stop after `gcOptions_maxFreed` bytes have been freed
33-
, gcOptions_maxFreed :: Integer
33+
, gcOptions_maxFreed :: Word64
3434
} deriving (Eq, Generic, Ord, Show)
3535

3636
-- | Result of the garbage collection operation

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import System.Nix.Signature (Signature)
2424
import System.Nix.Store.Types (FileIngestionMethod, RepairMode)
2525
import System.Nix.StorePath (StorePath, StorePathName, StorePathHashPart)
2626
import System.Nix.StorePath.Metadata (Metadata)
27+
import System.Nix.Store.Remote.Types.GC (GCOptions, GCResult)
2728
import System.Nix.Store.Remote.Types.CheckMode (CheckMode)
2829
import System.Nix.Store.Remote.Types.Query.Missing (Missing)
2930
import System.Nix.Store.Remote.Types.StoreText (StoreText)
@@ -87,6 +88,10 @@ data StoreRequest :: Type -> Type where
8788
-> BuildMode
8889
-> StoreRequest BuildResult
8990

91+
CollectGarbage
92+
:: GCOptions
93+
-> StoreRequest GCResult
94+
9095
EnsurePath
9196
:: StorePath
9297
-> StoreRequest ()
@@ -169,6 +174,7 @@ instance {-# OVERLAPPING #-} Eq (Some StoreRequest) where
169174
Some (AddTempRoot a) == Some (AddTempRoot a') = a == a'
170175
Some (BuildPaths a b) == Some (BuildPaths a' b') = (a, b) == (a', b')
171176
Some (BuildDerivation a b c) == Some (BuildDerivation a' b' c') = (a, b, c) == (a', b', c')
177+
Some (CollectGarbage a) == Some (CollectGarbage a') = a == a'
172178
Some (EnsurePath a) == Some (EnsurePath a') = a == a'
173179
Some (FindRoots) == Some (FindRoots) = True
174180
Some (IsValidPath a) == Some (IsValidPath a') = a == a'

0 commit comments

Comments
 (0)