Skip to content

Commit 9cd7d35

Browse files
committed
remote, add Types.GC, use in deleteSpecific
1 parent 598cb89 commit 9cd7d35

File tree

8 files changed

+69
-16
lines changed

8 files changed

+69
-16
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ library
8484
, System.Nix.Store.Remote.Socket
8585
, System.Nix.Store.Remote.Types
8686
, System.Nix.Store.Remote.Types.Activity
87+
, System.Nix.Store.Remote.Types.GC
8788
, System.Nix.Store.Remote.Types.CheckMode
8889
, System.Nix.Store.Remote.Types.Logger
8990
, System.Nix.Store.Remote.Types.ProtoVersion

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,22 +169,23 @@ buildDerivation p drv buildMode = do
169169
-- | Delete store paths
170170
deleteSpecific
171171
:: HashSet StorePath -- ^ Paths to delete
172-
-> MonadStore (HashSet StorePath, Word64) -- ^ (Paths deleted, Bytes freed)
172+
-> MonadStore GCResult
173173
deleteSpecific paths = do
174174
storeDir <- getStoreDir
175175
runOpArgs CollectGarbage $ do
176-
putEnum GCDeleteSpecific
176+
putEnum GCAction_DeleteSpecific
177177
putPaths storeDir paths
178178
putBool False -- ignoreLiveness
179179
putInt (maxBound :: Word64) -- maxFreedBytes
180180
putInt (0::Int)
181181
putInt (0::Int)
182182
putInt (0::Int)
183183
getSocketIncremental $ do
184-
deletedPaths <- getPathsOrFail storeDir
185-
bytesFreed <- getInt
184+
gcResult_deletedPaths <- getPathsOrFail storeDir
185+
gcResult_bytesFreed <- getInt
186+
-- TODO: who knows
186187
_ :: Int <- getInt
187-
pure (deletedPaths, bytesFreed)
188+
pure GCResult{..}
188189

189190
ensurePath :: StorePath -> MonadStore ()
190191
ensurePath pn = do

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,3 @@ runStoreOpts' sockFamily sockAddr storeRootDir code =
152152
$ (`runReaderT` sock)
153153
$ (`runStateT` (Nothing, []))
154154
$ runExceptT (greet >> code)
155-
156-
data GCAction
157-
= GCReturnLive
158-
| GCReturnDead
159-
| GCDeleteDead
160-
| GCDeleteSpecific
161-
deriving (Eq, Show, Enum)
162-

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ instance Serialize BuildResult where
6161
putTime startTime
6262
putTime stopTime
6363

64+
-- * GCAction
65+
--
66+
instance Serialize GCAction where
67+
get = getEnum
68+
put = putEnum
69+
6470
-- * ProtoVersion
6571

6672
-- protoVersion_major & 0xFF00

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module System.Nix.Store.Remote.Types
22
( module System.Nix.Store.Remote.Types.Activity
3+
, module System.Nix.Store.Remote.Types.GC
34
, module System.Nix.Store.Remote.Types.CheckMode
45
, module System.Nix.Store.Remote.Types.Logger
56
, module System.Nix.Store.Remote.Types.ProtoVersion
@@ -10,6 +11,7 @@ module System.Nix.Store.Remote.Types
1011
) where
1112

1213
import System.Nix.Store.Remote.Types.Activity
14+
import System.Nix.Store.Remote.Types.GC
1315
import System.Nix.Store.Remote.Types.CheckMode
1416
import System.Nix.Store.Remote.Types.Logger
1517
import System.Nix.Store.Remote.Types.ProtoVersion
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{-|
2+
Description : Garbage collection actions / options
3+
Maintainer : srk <[email protected]>
4+
|-}
5+
module System.Nix.Store.Remote.Types.GC (
6+
GCAction(..)
7+
, GCOptions(..)
8+
, GCResult(..)
9+
) where
10+
11+
import Data.HashSet (HashSet)
12+
import Data.Word (Word64)
13+
import GHC.Generics (Generic)
14+
import System.Nix.StorePath (StorePath)
15+
16+
data GCAction
17+
= GCAction_ReturnLive -- ^ Return the set of paths reachable from roots (closure)
18+
| GCAction_ReturnDead -- ^ Return unreachable paths
19+
| GCAction_DeleteDead -- ^ Delete unreachable paths
20+
| GCAction_DeleteSpecific -- ^ Delete specified paths
21+
deriving (Bounded, Eq, Enum, Generic, Ord, Show)
22+
23+
-- | Garbage collector operation options
24+
data GCOptions = GCOptions
25+
{ -- | Operation
26+
gcOptions_operation :: GCAction
27+
-- | If set, then reachability from the roots is ignored (unused)
28+
, gcOptions_ignoreLiveness :: Bool
29+
-- | Paths to delete for @GCAction_DeleteSpecific@
30+
, gcOptions_pathsToDelete :: HashSet StorePath
31+
-- | Stop after `gcOptions_maxFreed` bytes have been freed
32+
, gcOptions_maxFreed :: Integer
33+
} deriving (Eq, Generic, Ord, Show)
34+
35+
data GCResult = GCResult
36+
{ -- | Depending on the action, the GC roots,
37+
-- or the paths that would be or have been deleted
38+
gcResult_deletedPaths :: HashSet StorePath
39+
-- | The number of bytes that would be or was freed for
40+
--
41+
-- - @GCAction_ReturnDead@
42+
-- - @GCAction_DeleteDead@
43+
-- - @GCAction_DeleteSpecific@
44+
, gcResult_bytesFreed :: Word64
45+
} deriving (Eq, Generic, Ord, Show)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ spec_protocol = Hspec.around withNixDaemon $
285285
liftIO $ forM_ tempRootList $ \entry -> do
286286
removeFile $ mconcat [ tempRootsDir, "/", entry ]
287287

288-
(deletedPaths, deletedBytes) <- deleteSpecific (HS.fromList [path])
289-
deletedPaths `shouldBe` HS.fromList [path]
290-
deletedBytes `shouldBe` 4
288+
GCResult{..} <- deleteSpecific (HS.fromList [path])
289+
gcResult_deletedPaths `shouldBe` HS.fromList [path]
290+
gcResult_bytesFreed `shouldBe` 4
291291

hnix-store-remote/tests/SerializeSpec.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ spec = parallel $ do
156156
it' "ResolvesToAlreadyValid" BuildStatus_ResolvesToAlreadyValid 13
157157
it' "NoSubstituters" BuildStatus_NoSubstituters 14
158158

159+
describe "GCAction enum order matches Nix" $ do
160+
it' "ReturnLive" GCAction_ReturnLive 0
161+
it' "ReturnDead" GCAction_ReturnDead 1
162+
it' "DeleteDead" GCAction_DeleteDead 2
163+
it' "DeleteSpecific" GCAction_DeleteSpecific 3
164+
159165
describe "Logger" $ do
160166
describe "Activity enum order matches Nix" $ do
161167
it' "CopyPath" Activity_CopyPath 100

0 commit comments

Comments
 (0)