make WorkerStage an open type

Rather than limiting it to PerformStage and CleanupStage, this opens it
up so any number of stages can be added as needed by commands.

Each concurrent command has a set of stages that it uses, and only
transitions between those can block waiting for a free slot in the
worker pool. Calling enteringStage for some other stage does not block,
and has very little overhead.

Note that while before the Annex state was duplicated on the first call
to commandAction, this now happens earlier, in startConcurrency.
That means that seek stage actions should that use startConcurrency
and then modify Annex state won't modify the state of worker threads
they then start. I audited all of them, and only Command.Seek
did so; prepMerge changes the working directory and so has to come
before startConcurrency.

Also, the remote list is built before duplicating the state, which means
that it gets built earlier now than it used to. This would only have an
effect of making commands that end up not needing to perform any actions
unncessary build the remote list (only when they're run with concurrency
enable), but that's a minor overhead compared to commands seeking
through the work tree and determining they don't need to do anything.
This commit is contained in:
Joey Hess 2019-06-19 12:35:08 -04:00
parent e19408ed9d
commit 53882ab4a7
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
17 changed files with 230 additions and 147 deletions

View file

@ -7,7 +7,12 @@
{-# LANGUAGE CPP #-}
module Annex.Action where
module Annex.Action (
startup,
shutdown,
stopCoProcesses,
reapZombies,
) where
import qualified Data.Map as M
#ifndef mingw32_HOST_OS
@ -18,10 +23,7 @@ import Utility.Exception
import Annex.Common
import qualified Annex
import Annex.Content
import Annex.CatFile
import Annex.CheckAttr
import Annex.HashObject
import Annex.CheckIgnore
import Annex.Concurrent
{- Actions to perform each time ran. -}
startup :: Annex ()
@ -35,14 +37,6 @@ shutdown nocommit = do
stopCoProcesses
liftIO reapZombies -- zombies from long-running git processes
{- Stops all long-running git query processes. -}
stopCoProcesses :: Annex ()
stopCoProcesses = do
catFileStop
checkAttrStop
hashObjectStop
checkIgnoreStop
{- Reaps any zombie processes that may be hanging around.
-
- Warning: Not thread safe. Anything that was expecting to wait