From eaaaa9954f013340aea5afcc620c240ffabb5675 Mon Sep 17 00:00:00 2001 From: sorki Date: Sat, 2 Dec 2023 15:26:21 +0100 Subject: [PATCH] remote: add CollectGarbage StoreRequest --- .../src/System/Nix/Store/Remote/Arbitrary.hs | 12 ++++++++++ .../src/System/Nix/Store/Remote/Serializer.hs | 22 ++++++++++++++++++- .../src/System/Nix/Store/Remote/Types/GC.hs | 2 +- .../Nix/Store/Remote/Types/StoreRequest.hs | 6 +++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/hnix-store-remote/src/System/Nix/Store/Remote/Arbitrary.hs b/hnix-store-remote/src/System/Nix/Store/Remote/Arbitrary.hs index 16db6420..e5869b5c 100644 --- a/hnix-store-remote/src/System/Nix/Store/Remote/Arbitrary.hs +++ b/hnix-store-remote/src/System/Nix/Store/Remote/Arbitrary.hs @@ -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 diff --git a/hnix-store-remote/src/System/Nix/Store/Remote/Serializer.hs b/hnix-store-remote/src/System/Nix/Store/Remote/Serializer.hs index f6801ca0..63816c36 100644 --- a/hnix-store-remote/src/System/Nix/Store/Remote/Serializer.hs +++ b/hnix-store-remote/src/System/Nix/Store/Remote/Serializer.hs @@ -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 diff --git a/hnix-store-remote/src/System/Nix/Store/Remote/Types/GC.hs b/hnix-store-remote/src/System/Nix/Store/Remote/Types/GC.hs index 0eb5e9d6..8fdda8bd 100644 --- a/hnix-store-remote/src/System/Nix/Store/Remote/Types/GC.hs +++ b/hnix-store-remote/src/System/Nix/Store/Remote/Types/GC.hs @@ -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 diff --git a/hnix-store-remote/src/System/Nix/Store/Remote/Types/StoreRequest.hs b/hnix-store-remote/src/System/Nix/Store/Remote/Types/StoreRequest.hs index afa206c1..1e74c2e0 100644 --- a/hnix-store-remote/src/System/Nix/Store/Remote/Types/StoreRequest.hs +++ b/hnix-store-remote/src/System/Nix/Store/Remote/Types/StoreRequest.hs @@ -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'