8000 daemon: don't mark successfully retried paths as failed by sandydoo · Pull Request #684 · cachix/cachix · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

daemon: don't mark successfully retried paths as failed #684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cachix/src/Cachix/Daemon/PushManager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import Control.Concurrent.STM.TBMQueue
import Control.Concurrent.STM.TVar
import Control.Monad.Catch qualified as E
import Control.Monad.Trans.Maybe (MaybeT (..), runMaybeT)
import Control.Retry (RetryStatus)
import Control.Retry (RetryStatus, rsIterNumber)
import Data.ByteString qualified as BS
import Data.HashMap.Strict qualified as HashMap
import Data.IORef
Expand Down Expand Up @@ -338,12 +338,15 @@ newPushStrategy store authToken opts cacheName compressionMethod storePath =
let errText = toS (displayException err)
sp <- liftIO $ storePathToPath store storePath
Katip.katipAddContext (Katip.sl "error" errText) $
Katip.logFM Katip.InfoS (Katip.ls $ "Failed " <> (toS sp :: Text))
Katip.logFM Katip.InfoS (Katip.ls $ "Failed to push " <> (toS sp :: Text))
pushStorePathFailed (toS sp) errText

onAttempt retryStatus size = do
sp <- liftIO $ storePathToPath store storePath
Katip.logFM Katip.InfoS $ Katip.ls $ "Pushing " <> (toS sp :: Text)
Katip.katipAddContext (Katip.sl "retry" (rsIterNumber retryStatus)) $
Katip.logFM Katip.InfoS $
Katip.ls $
"Pushing " <> (toS sp :: Text)
pushStorePathAttempt (toS sp) size retryStatus

onUncompressedNARStream _ size = do
Expand Down
16 changes: 6 additions & 10 deletions cachix/src/Cachix/Daemon/PushManager/PushJob.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,22 @@ populateQueue ResolvedClosure {..} timestamp pushJob@PushJob {..} = do
pushResult = pushResult {prSkippedPaths = skippedPaths}
}

addPushedPath :: FilePath -> PushResult -> PushResult
addPushedPath storePath pushResult =
pushResult {prPushedPaths = Set.insert storePath (prPushedPaths pushResult)}

addFailedPath :: FilePath -> PushResult -> PushResult
addFailedPath storePath pushResult =
pushResult {prFailedPaths = Set.insert storePath (prFailedPaths pushResult)}

markStorePathPushed :: FilePath -> PushJob -> PushJob
markStorePathPushed storePath pushJob@(PushJob {pushQueue, pushResult}) =
pushJob
{ pushQueue = Set.delete storePath pushQueue,
pushResult = addPushedPath storePath pushResult
pushResult =
pushResult
{ prPushedPaths = Set.insert storePath (prPushedPaths pushResult),
prFailedPaths = Set.delete storePath (prFailedPaths pushResult)
}
}

markStorePathFailed :: FilePath -> PushJob -> PushJob
markStorePathFailed storePath pushJob@(PushJob {pushQueue, pushResult}) =
pushJob
{ pushQueue = Set.delete storePath pushQueue,
pushResult = addFailedPath storePath pushResult
pushResult = pushResult {prFailedPaths = Set.insert storePath (prFailedPaths pushResult)}
}

status :: PushJob -> JobStatus
Expand Down
21 changes: 21 additions & 0 deletions cachix/test/Daemon/PushManagerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,27 @@ spec = do
PushJob.prSkippedPaths = mempty
}

it "unmark paths as failed after successful retry" $
do
let request = Protocol.PushRequest {Protocol.storePaths = ["foo", "bar"]}
pathSet = Set.fromList ["foo", "bar"]
closure = PushJob.ResolvedClosure pathSet pathSet

timestamp <- getCurrentTime
initPushJob <- PushJob.new request
let pushJob =
initPushJob
& PushJob.populateQueue closure timestamp
& PushJob.markStorePathFailed "foo"
& PushJob.markStorePathPushed "foo"
PushJob.status pushJob `shouldBe` Running
PushJob.result pushJob
`shouldBe` PushJob.PushResult
{ PushJob.prFailedPaths = mempty,
PushJob.prPushedPaths = Set.fromList ["foo"],
PushJob.prSkippedPaths = mempty
}

describe "push manager" $ do
it "queues push jobs " $ inPushManager $ do
let request = Protocol.PushRequest {Protocol.storePaths = ["foo", "bar"]}
Expand Down
0