2012-06-13 21:54:23 +00:00
|
|
|
{- git-annex assistant sanity checker
|
|
|
|
-
|
assistant: Detect stale git lock files at startup time, and remove them.
Extends the index.lock handling to other git lock files. I surveyed
all lock files used by git, and found more than I expected. All are
handled the same in git; it leaves them open while doing the operation,
possibly writing the new file content to the lock file, and then closes
them when done.
The gc.pid file is excluded because it won't affect the normal operation
of the assistant, and waiting for a gc to finish on startup wouldn't be
good.
All threads except the webapp thread wait on the new startup sanity checker
thread to complete, so they won't try to do things with git that fail
due to stale lock files. The webapp thread mostly avoids doing that kind of
thing itself. A few configurators might fail on lock files, but only if the
user is explicitly trying to run them. The webapp needs to start
immediately when the user has opened it, even if there are stale lock
files.
Arranging for the threads to wait on the startup sanity checker was a bit
of a bear. Have to get all the NotificationHandles set up before the
startup sanity checker runs, or they won't see its signal. Perhaps
the NotificationBroadcaster is not the best interface to have used for
this. Oh well, it works.
This commit was sponsored by Michael Jakl
2013-10-05 21:02:11 +00:00
|
|
|
- Copyright 2012, 2013 Joey Hess <joey@kitenet.net>
|
2012-06-23 05:20:40 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
2012-06-13 21:54:23 +00:00
|
|
|
-}
|
|
|
|
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2012-06-25 20:10:10 +00:00
|
|
|
module Assistant.Threads.SanityChecker (
|
assistant: Detect stale git lock files at startup time, and remove them.
Extends the index.lock handling to other git lock files. I surveyed
all lock files used by git, and found more than I expected. All are
handled the same in git; it leaves them open while doing the operation,
possibly writing the new file content to the lock file, and then closes
them when done.
The gc.pid file is excluded because it won't affect the normal operation
of the assistant, and waiting for a gc to finish on startup wouldn't be
good.
All threads except the webapp thread wait on the new startup sanity checker
thread to complete, so they won't try to do things with git that fail
due to stale lock files. The webapp thread mostly avoids doing that kind of
thing itself. A few configurators might fail on lock files, but only if the
user is explicitly trying to run them. The webapp needs to start
immediately when the user has opened it, even if there are stale lock
files.
Arranging for the threads to wait on the startup sanity checker was a bit
of a bear. Have to get all the NotificationHandles set up before the
startup sanity checker runs, or they won't see its signal. Perhaps
the NotificationBroadcaster is not the best interface to have used for
this. Oh well, it works.
This commit was sponsored by Michael Jakl
2013-10-05 21:02:11 +00:00
|
|
|
sanityCheckerStartupThread,
|
2013-03-01 17:30:48 +00:00
|
|
|
sanityCheckerDailyThread,
|
|
|
|
sanityCheckerHourlyThread
|
2012-06-13 21:54:23 +00:00
|
|
|
) where
|
|
|
|
|
2012-07-20 23:29:59 +00:00
|
|
|
import Assistant.Common
|
2012-06-13 21:54:23 +00:00
|
|
|
import Assistant.DaemonStatus
|
2012-07-29 21:53:18 +00:00
|
|
|
import Assistant.Alert
|
2013-10-29 17:41:44 +00:00
|
|
|
import Assistant.Repair
|
2014-01-23 20:51:16 +00:00
|
|
|
import Assistant.Drop
|
2013-12-21 00:58:36 +00:00
|
|
|
import Assistant.Ssh
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
import Assistant.TransferQueue
|
|
|
|
import Assistant.Types.UrlRenderer
|
2014-09-15 18:45:37 +00:00
|
|
|
import Assistant.Restart
|
2014-01-14 21:10:30 +00:00
|
|
|
import qualified Annex.Branch
|
2014-09-15 18:45:37 +00:00
|
|
|
import qualified Git
|
2012-07-20 23:29:59 +00:00
|
|
|
import qualified Git.LsFiles
|
2014-07-04 16:18:49 +00:00
|
|
|
import qualified Git.Command.Batch
|
2013-03-03 18:07:13 +00:00
|
|
|
import qualified Git.Config
|
2012-06-13 21:54:23 +00:00
|
|
|
import Utility.ThreadScheduler
|
2012-06-25 20:10:10 +00:00
|
|
|
import qualified Assistant.Threads.Watcher as Watcher
|
2013-06-21 17:29:42 +00:00
|
|
|
import Utility.Batch
|
assistant: Detect stale git lock files at startup time, and remove them.
Extends the index.lock handling to other git lock files. I surveyed
all lock files used by git, and found more than I expected. All are
handled the same in git; it leaves them open while doing the operation,
possibly writing the new file content to the lock file, and then closes
them when done.
The gc.pid file is excluded because it won't affect the normal operation
of the assistant, and waiting for a gc to finish on startup wouldn't be
good.
All threads except the webapp thread wait on the new startup sanity checker
thread to complete, so they won't try to do things with git that fail
due to stale lock files. The webapp thread mostly avoids doing that kind of
thing itself. A few configurators might fail on lock files, but only if the
user is explicitly trying to run them. The webapp needs to start
immediately when the user has opened it, even if there are stale lock
files.
Arranging for the threads to wait on the startup sanity checker was a bit
of a bear. Have to get all the NotificationHandles set up before the
startup sanity checker runs, or they won't see its signal. Perhaps
the NotificationBroadcaster is not the best interface to have used for
this. Oh well, it works.
This commit was sponsored by Michael Jakl
2013-10-05 21:02:11 +00:00
|
|
|
import Utility.NotificationBroadcaster
|
2013-03-04 18:25:18 +00:00
|
|
|
import Config
|
2013-10-26 16:42:58 +00:00
|
|
|
import Utility.HumanTime
|
2014-01-23 19:09:43 +00:00
|
|
|
import Utility.Tense
|
2013-11-13 18:27:17 +00:00
|
|
|
import Git.Repair
|
2013-11-30 18:29:11 +00:00
|
|
|
import Git.Index
|
2014-01-23 19:09:43 +00:00
|
|
|
import Assistant.Unused
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
import Logs.Unused
|
|
|
|
import Logs.Transfer
|
|
|
|
import Config.Files
|
2014-12-29 21:25:59 +00:00
|
|
|
import Types.Key (keyBackendName)
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
import qualified Annex
|
|
|
|
#ifdef WITH_WEBAPP
|
|
|
|
import Assistant.WebApp.Types
|
|
|
|
#endif
|
2014-02-25 18:09:39 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
|
|
|
import Utility.LogFile
|
2014-12-29 21:25:59 +00:00
|
|
|
import Utility.DiskFree
|
2014-02-25 18:09:39 +00:00
|
|
|
#endif
|
2012-06-13 21:54:23 +00:00
|
|
|
|
|
|
|
import Data.Time.Clock.POSIX
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
import qualified Data.Text as T
|
2012-06-13 21:54:23 +00:00
|
|
|
|
assistant: Detect stale git lock files at startup time, and remove them.
Extends the index.lock handling to other git lock files. I surveyed
all lock files used by git, and found more than I expected. All are
handled the same in git; it leaves them open while doing the operation,
possibly writing the new file content to the lock file, and then closes
them when done.
The gc.pid file is excluded because it won't affect the normal operation
of the assistant, and waiting for a gc to finish on startup wouldn't be
good.
All threads except the webapp thread wait on the new startup sanity checker
thread to complete, so they won't try to do things with git that fail
due to stale lock files. The webapp thread mostly avoids doing that kind of
thing itself. A few configurators might fail on lock files, but only if the
user is explicitly trying to run them. The webapp needs to start
immediately when the user has opened it, even if there are stale lock
files.
Arranging for the threads to wait on the startup sanity checker was a bit
of a bear. Have to get all the NotificationHandles set up before the
startup sanity checker runs, or they won't see its signal. Perhaps
the NotificationBroadcaster is not the best interface to have used for
this. Oh well, it works.
This commit was sponsored by Michael Jakl
2013-10-05 21:02:11 +00:00
|
|
|
{- This thread runs once at startup, and most other threads wait for it
|
|
|
|
- to finish. (However, the webapp thread does not, to prevent the UI
|
|
|
|
- being nonresponsive.) -}
|
2013-10-26 16:42:58 +00:00
|
|
|
sanityCheckerStartupThread :: Maybe Duration -> NamedThread
|
|
|
|
sanityCheckerStartupThread startupdelay = namedThreadUnchecked "SanityCheckerStartup" $ do
|
2013-10-29 20:48:06 +00:00
|
|
|
{- Stale git locks can prevent commits from happening, etc. -}
|
2013-10-29 18:22:56 +00:00
|
|
|
void $ repairStaleGitLocks =<< liftAnnex gitRepo
|
2013-10-26 16:42:58 +00:00
|
|
|
|
2013-11-13 18:27:17 +00:00
|
|
|
{- A corrupt index file can prevent the assistant from working at
|
|
|
|
- all, so detect and repair. -}
|
2013-12-10 19:40:01 +00:00
|
|
|
ifM (not <$> liftAnnex (inRepo checkIndexFast))
|
2013-11-13 18:39:26 +00:00
|
|
|
( do
|
2013-11-13 18:42:59 +00:00
|
|
|
notice ["corrupt index file found at startup; removing and restaging"]
|
2013-11-30 18:29:11 +00:00
|
|
|
liftAnnex $ inRepo $ nukeFile . indexFile
|
2013-11-13 18:39:26 +00:00
|
|
|
{- Normally the startup scan avoids re-staging files,
|
|
|
|
- but with the index deleted, everything needs to be
|
|
|
|
- restaged. -}
|
|
|
|
modifyDaemonStatus_ $ \s -> s { forceRestage = True }
|
|
|
|
, whenM (liftAnnex $ inRepo missingIndex) $ do
|
|
|
|
debug ["no index file; restaging"]
|
|
|
|
modifyDaemonStatus_ $ \s -> s { forceRestage = True }
|
|
|
|
)
|
2014-01-14 21:10:30 +00:00
|
|
|
{- If the git-annex index file is corrupt, it's ok to remove it;
|
|
|
|
- the data from the git-annex branch will be used, and the index
|
|
|
|
- will be automatically regenerated. -}
|
|
|
|
unlessM (liftAnnex $ Annex.Branch.withIndex $ inRepo $ Git.Repair.checkIndexFast) $ do
|
|
|
|
notice ["corrupt annex/index file found at startup; removing"]
|
|
|
|
liftAnnex $ liftIO . nukeFile =<< fromRepo gitAnnexIndex
|
2013-11-13 18:27:17 +00:00
|
|
|
|
2013-12-21 00:58:36 +00:00
|
|
|
{- Fix up ssh remotes set up by past versions of the assistant. -}
|
|
|
|
liftIO $ fixUpSshRemotes
|
|
|
|
|
2014-04-28 01:15:26 +00:00
|
|
|
{- Clean up old temp files. -}
|
unify exception handling into Utility.Exception
Removed old extensible-exceptions, only needed for very old ghc.
Made webdav use Utility.Exception, to work after some changes in DAV's
exception handling.
Removed Annex.Exception. Mostly this was trivial, but note that
tryAnnex is replaced with tryNonAsync and catchAnnex replaced with
catchNonAsync. In theory that could be a behavior change, since the former
caught all exceptions, and the latter don't catch async exceptions.
However, in practice, nothing in the Annex monad uses async exceptions.
Grepping for throwTo and killThread only find stuff in the assistant,
which does not seem related.
Command.Add.undo is changed to accept a SomeException, and things
that use it for rollback now catch non-async exceptions, rather than
only IOExceptions.
2014-08-08 01:55:44 +00:00
|
|
|
void $ liftAnnex $ tryNonAsync $ do
|
2014-05-30 19:08:49 +00:00
|
|
|
cleanOldTmpMisc
|
|
|
|
cleanReallyOldTmp
|
2014-04-28 01:15:26 +00:00
|
|
|
|
2013-10-29 20:48:06 +00:00
|
|
|
{- If there's a startup delay, it's done here. -}
|
2013-10-26 16:42:58 +00:00
|
|
|
liftIO $ maybe noop (threadDelaySeconds . Seconds . fromIntegral . durationSeconds) startupdelay
|
|
|
|
|
|
|
|
{- Notify other threads that the startup sanity check is done. -}
|
|
|
|
status <- getDaemonStatus
|
|
|
|
liftIO $ sendNotification $ startupSanityCheckNotifier status
|
assistant: Detect stale git lock files at startup time, and remove them.
Extends the index.lock handling to other git lock files. I surveyed
all lock files used by git, and found more than I expected. All are
handled the same in git; it leaves them open while doing the operation,
possibly writing the new file content to the lock file, and then closes
them when done.
The gc.pid file is excluded because it won't affect the normal operation
of the assistant, and waiting for a gc to finish on startup wouldn't be
good.
All threads except the webapp thread wait on the new startup sanity checker
thread to complete, so they won't try to do things with git that fail
due to stale lock files. The webapp thread mostly avoids doing that kind of
thing itself. A few configurators might fail on lock files, but only if the
user is explicitly trying to run them. The webapp needs to start
immediately when the user has opened it, even if there are stale lock
files.
Arranging for the threads to wait on the startup sanity checker was a bit
of a bear. Have to get all the NotificationHandles set up before the
startup sanity checker runs, or they won't see its signal. Perhaps
the NotificationBroadcaster is not the best interface to have used for
this. Oh well, it works.
This commit was sponsored by Michael Jakl
2013-10-05 21:02:11 +00:00
|
|
|
|
2013-03-01 17:30:48 +00:00
|
|
|
{- This thread wakes up hourly for inxepensive frequent sanity checks. -}
|
|
|
|
sanityCheckerHourlyThread :: NamedThread
|
|
|
|
sanityCheckerHourlyThread = namedThread "SanityCheckerHourly" $ forever $ do
|
|
|
|
liftIO $ threadDelaySeconds $ Seconds oneHour
|
|
|
|
hourlyCheck
|
|
|
|
|
|
|
|
{- This thread wakes up daily to make sure the tree is in good shape. -}
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
sanityCheckerDailyThread :: UrlRenderer -> NamedThread
|
|
|
|
sanityCheckerDailyThread urlrenderer = namedThread "SanityCheckerDaily" $ forever $ do
|
2014-01-23 20:57:49 +00:00
|
|
|
waitForNextCheck
|
|
|
|
|
2012-10-29 06:21:04 +00:00
|
|
|
debug ["starting sanity check"]
|
2012-10-29 20:49:47 +00:00
|
|
|
void $ alertWhile sanityCheckAlert go
|
2012-10-29 06:21:04 +00:00
|
|
|
debug ["sanity check complete"]
|
|
|
|
where
|
|
|
|
go = do
|
2012-10-30 19:39:15 +00:00
|
|
|
modifyDaemonStatus_ $ \s -> s { sanityCheckRunning = True }
|
2012-10-29 06:21:04 +00:00
|
|
|
|
2013-10-03 02:59:07 +00:00
|
|
|
now <- liftIO getPOSIXTime -- before check started
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
r <- either showerr return
|
|
|
|
=<< (tryIO . batch) <~> dailyCheck urlrenderer
|
2012-07-29 21:53:18 +00:00
|
|
|
|
2012-10-30 19:39:15 +00:00
|
|
|
modifyDaemonStatus_ $ \s -> s
|
2012-10-29 06:21:04 +00:00
|
|
|
{ sanityCheckRunning = False
|
|
|
|
, lastSanityCheck = Just now
|
|
|
|
}
|
2012-07-29 21:53:18 +00:00
|
|
|
|
2012-10-29 06:21:04 +00:00
|
|
|
return r
|
2012-07-20 23:29:59 +00:00
|
|
|
|
2012-10-29 06:21:04 +00:00
|
|
|
showerr e = do
|
|
|
|
liftAnnex $ warning $ show e
|
|
|
|
return False
|
2012-07-30 06:07:02 +00:00
|
|
|
|
2012-06-13 21:54:23 +00:00
|
|
|
{- Only run one check per day, from the time of the last check. -}
|
2012-10-29 06:21:04 +00:00
|
|
|
waitForNextCheck :: Assistant ()
|
|
|
|
waitForNextCheck = do
|
2012-10-30 18:44:18 +00:00
|
|
|
v <- lastSanityCheck <$> getDaemonStatus
|
2012-10-29 06:21:04 +00:00
|
|
|
now <- liftIO getPOSIXTime
|
|
|
|
liftIO $ threadDelaySeconds $ Seconds $ calcdelay now v
|
|
|
|
where
|
|
|
|
calcdelay _ Nothing = oneDay
|
|
|
|
calcdelay now (Just lastcheck)
|
|
|
|
| lastcheck < now = max oneDay $
|
|
|
|
oneDay - truncate (now - lastcheck)
|
|
|
|
| otherwise = oneDay
|
2012-06-13 21:54:23 +00:00
|
|
|
|
2012-06-13 23:25:47 +00:00
|
|
|
{- It's important to stay out of the Annex monad as much as possible while
|
|
|
|
- running potentially expensive parts of this check, since remaining in it
|
|
|
|
- will block the watcher. -}
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
dailyCheck :: UrlRenderer -> Assistant Bool
|
|
|
|
dailyCheck urlrenderer = do
|
2014-09-15 18:45:37 +00:00
|
|
|
checkRepoExists
|
|
|
|
|
2012-10-29 06:21:04 +00:00
|
|
|
g <- liftAnnex gitRepo
|
2014-01-22 21:11:41 +00:00
|
|
|
batchmaker <- liftIO getBatchCommandMaker
|
2013-03-03 17:39:57 +00:00
|
|
|
|
2012-06-13 23:25:47 +00:00
|
|
|
-- Find old unstaged symlinks, and add them to git.
|
2012-10-29 06:21:04 +00:00
|
|
|
(unstaged, cleanup) <- liftIO $ Git.LsFiles.notInRepo False ["."] g
|
2013-10-03 02:59:07 +00:00
|
|
|
now <- liftIO getPOSIXTime
|
2012-06-13 23:25:47 +00:00
|
|
|
forM_ unstaged $ \file -> do
|
2012-10-29 06:21:04 +00:00
|
|
|
ms <- liftIO $ catchMaybeIO $ getSymbolicLinkStatus file
|
2012-06-13 23:25:47 +00:00
|
|
|
case ms of
|
|
|
|
Just s | toonew (statusChangeTime s) now -> noop
|
2012-10-29 06:21:04 +00:00
|
|
|
| isSymbolicLink s -> addsymlink file ms
|
2012-06-13 23:25:47 +00:00
|
|
|
_ -> noop
|
2012-10-29 06:21:04 +00:00
|
|
|
liftIO $ void cleanup
|
2013-03-03 17:39:57 +00:00
|
|
|
|
|
|
|
{- Allow git-gc to run once per day. More frequent gc is avoided
|
2013-03-03 18:07:13 +00:00
|
|
|
- by default to avoid slowing things down. Only run repacks when 100x
|
|
|
|
- the usual number of loose objects are present; we tend
|
|
|
|
- to have a lot of small objects and they should not be a
|
|
|
|
- significant size. -}
|
|
|
|
when (Git.Config.getMaybe "gc.auto" g == Just "0") $
|
2014-07-04 16:18:49 +00:00
|
|
|
liftIO $ void $ Git.Command.Batch.run batchmaker
|
2013-03-03 18:07:13 +00:00
|
|
|
[ Param "-c", Param "gc.auto=670000"
|
|
|
|
, Param "gc"
|
|
|
|
, Param "--auto"
|
|
|
|
] g
|
2013-03-03 17:39:57 +00:00
|
|
|
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
{- Check if the unused files found last time have been dealt with. -}
|
|
|
|
checkOldUnused urlrenderer
|
|
|
|
|
|
|
|
{- Run git-annex unused once per day. This is run as a separate
|
|
|
|
- process to stay out of the annex monad and so it can run as a
|
|
|
|
- batch job. -}
|
|
|
|
program <- liftIO readProgramFile
|
|
|
|
let (program', params') = batchmaker (program, [Param "unused"])
|
|
|
|
void $ liftIO $ boolSystem program' params'
|
|
|
|
{- Invalidate unused keys cache, and queue transfers of all unused
|
2014-01-23 20:51:16 +00:00
|
|
|
- keys, or if no transfers are called for, drop them. -}
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
unused <- liftAnnex unusedKeys'
|
|
|
|
void $ liftAnnex $ setUnusedKeys unused
|
2014-01-23 20:51:16 +00:00
|
|
|
forM_ unused $ \k -> do
|
|
|
|
unlessM (queueTransfers "unused" Later k Nothing Upload) $
|
|
|
|
handleDrops "unused" True k Nothing Nothing
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
|
2012-07-30 06:07:02 +00:00
|
|
|
return True
|
2012-10-29 06:21:04 +00:00
|
|
|
where
|
|
|
|
toonew timestamp now = now < (realToFrac (timestamp + slop) :: POSIXTime)
|
|
|
|
slop = fromIntegral tenMinutes
|
|
|
|
insanity msg = do
|
|
|
|
liftAnnex $ warning msg
|
2012-10-30 19:39:15 +00:00
|
|
|
void $ addAlert $ sanityCheckFixAlert msg
|
2012-10-29 06:21:04 +00:00
|
|
|
addsymlink file s = do
|
2013-03-04 18:25:18 +00:00
|
|
|
isdirect <- liftAnnex isDirect
|
|
|
|
Watcher.runHandler (Watcher.onAddSymlink isdirect) file s
|
2012-10-29 06:21:04 +00:00
|
|
|
insanity $ "found unstaged symlink: " ++ file
|
2013-03-01 17:30:48 +00:00
|
|
|
|
|
|
|
hourlyCheck :: Assistant ()
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
hourlyCheck = do
|
2014-09-15 18:45:37 +00:00
|
|
|
checkRepoExists
|
2014-02-11 19:04:07 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
checkLogSize 0
|
2014-02-11 19:04:07 +00:00
|
|
|
#else
|
|
|
|
noop
|
|
|
|
#endif
|
2013-03-01 17:30:48 +00:00
|
|
|
|
2014-02-11 19:04:07 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
2014-03-05 22:26:53 +00:00
|
|
|
{- Rotate logs once when total log file size is > 2 mb.
|
|
|
|
-
|
|
|
|
- If total log size is larger than the amount of free disk space,
|
|
|
|
- continue rotating logs until size is < 2 mb, even if this
|
|
|
|
- results in immediately losing the just logged data.
|
|
|
|
-}
|
2013-03-01 17:30:48 +00:00
|
|
|
checkLogSize :: Int -> Assistant ()
|
|
|
|
checkLogSize n = do
|
|
|
|
f <- liftAnnex $ fromRepo gitAnnexLogFile
|
|
|
|
logs <- liftIO $ listLogs f
|
2015-01-20 20:58:48 +00:00
|
|
|
totalsize <- liftIO $ sum <$> mapM getFileSize logs
|
2014-03-05 22:26:53 +00:00
|
|
|
when (totalsize > 2 * oneMegabyte) $ do
|
2013-03-01 17:30:48 +00:00
|
|
|
notice ["Rotated logs due to size:", show totalsize]
|
2014-06-17 23:10:51 +00:00
|
|
|
liftIO $ openLog f >>= handleToFd >>= redirLog
|
2014-03-05 22:26:53 +00:00
|
|
|
when (n < maxLogs + 1) $ do
|
|
|
|
df <- liftIO $ getDiskFree $ takeDirectory f
|
|
|
|
case df of
|
|
|
|
Just free
|
|
|
|
| free < fromIntegral totalsize ->
|
|
|
|
checkLogSize (n + 1)
|
|
|
|
_ -> noop
|
2013-03-01 17:30:48 +00:00
|
|
|
where
|
2015-01-20 20:58:48 +00:00
|
|
|
oneMegabyte :: Integer
|
2014-02-25 18:09:39 +00:00
|
|
|
oneMegabyte = 1000000
|
|
|
|
#endif
|
2013-03-01 17:30:48 +00:00
|
|
|
|
|
|
|
oneHour :: Int
|
|
|
|
oneHour = 60 * 60
|
|
|
|
|
|
|
|
oneDay :: Int
|
|
|
|
oneDay = 24 * oneHour
|
assistant: Detect stale git lock files at startup time, and remove them.
Extends the index.lock handling to other git lock files. I surveyed
all lock files used by git, and found more than I expected. All are
handled the same in git; it leaves them open while doing the operation,
possibly writing the new file content to the lock file, and then closes
them when done.
The gc.pid file is excluded because it won't affect the normal operation
of the assistant, and waiting for a gc to finish on startup wouldn't be
good.
All threads except the webapp thread wait on the new startup sanity checker
thread to complete, so they won't try to do things with git that fail
due to stale lock files. The webapp thread mostly avoids doing that kind of
thing itself. A few configurators might fail on lock files, but only if the
user is explicitly trying to run them. The webapp needs to start
immediately when the user has opened it, even if there are stale lock
files.
Arranging for the threads to wait on the startup sanity checker was a bit
of a bear. Have to get all the NotificationHandles set up before the
startup sanity checker runs, or they won't see its signal. Perhaps
the NotificationBroadcaster is not the best interface to have used for
this. Oh well, it works.
This commit was sponsored by Michael Jakl
2013-10-05 21:02:11 +00:00
|
|
|
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
{- If annex.expireunused is set, find any keys that have lingered unused
|
|
|
|
- for the specified duration, and remove them.
|
|
|
|
-
|
|
|
|
- Otherwise, check to see if unused keys are piling up, and let the user
|
2014-01-23 19:09:43 +00:00
|
|
|
- know. -}
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
checkOldUnused :: UrlRenderer -> Assistant ()
|
|
|
|
checkOldUnused urlrenderer = go =<< annexExpireUnused <$> liftAnnex Annex.getGitConfig
|
|
|
|
where
|
2014-01-23 03:10:51 +00:00
|
|
|
go (Just Nothing) = noop
|
2014-10-09 18:53:13 +00:00
|
|
|
go (Just (Just expireunused)) = expireUnused (Just expireunused)
|
2014-01-23 19:09:43 +00:00
|
|
|
go Nothing = maybe noop prompt =<< describeUnusedWhenBig
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
|
|
|
|
prompt msg =
|
|
|
|
#ifdef WITH_WEBAPP
|
|
|
|
do
|
2014-01-23 19:09:43 +00:00
|
|
|
button <- mkAlertButton True (T.pack "Configure") urlrenderer ConfigUnusedR
|
|
|
|
void $ addAlert $ unusedFilesAlert [button] $ T.unpack $ renderTense Present msg
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
#else
|
2014-02-08 18:18:36 +00:00
|
|
|
debug [show $ renderTense Past msg]
|
assistant unused file handling
Make sanity checker run git annex unused daily, and queue up transfers
of unused files to any remotes that will have them. The transfer retrying
code works for us here, so eg when a backup disk remote is plugged in,
any transfers to it are done. Once the unused files reach a remote,
they'll be removed locally as unwanted.
If the setup does not cause unused files to go to a remote, they'll pile
up, and the sanity checker detects this using some heuristics that are
pretty good -- 1000 unused files, or 10% of disk used by unused files,
or more disk wasted by unused files than is left free. Once it detects
this, it pops up an alert in the webapp, with a button to take action.
TODO: Webapp UI to configure this, and also the ability to launch an
immediate cleanup of all unused files.
This commit was sponsored by Simon Michael.
2014-01-23 02:48:56 +00:00
|
|
|
#endif
|
2014-04-28 01:15:26 +00:00
|
|
|
|
|
|
|
{- Files may be left in misctmp by eg, an interrupted add of files
|
|
|
|
- by the assistant, which hard links files to there as part of lockdown
|
|
|
|
- checks. Delete these files if they're more than a day old.
|
|
|
|
-
|
|
|
|
- Note that this is not safe to run after the Watcher starts up, since it
|
|
|
|
- will create such files, and due to hard linking they may have old
|
|
|
|
- mtimes. So, this should only be called from the
|
|
|
|
- sanityCheckerStartupThread, which runs before the Watcher starts up.
|
|
|
|
-
|
|
|
|
- Also, if a git-annex add is being run at the same time the assistant
|
|
|
|
- starts up, its tmp files could be deleted. However, the watcher will
|
|
|
|
- come along and add everything once it starts up anyway, so at worst
|
|
|
|
- this would make the git-annex add fail unexpectedly.
|
|
|
|
-}
|
|
|
|
cleanOldTmpMisc :: Annex ()
|
|
|
|
cleanOldTmpMisc = do
|
|
|
|
now <- liftIO getPOSIXTime
|
|
|
|
let oldenough = now - (60 * 60 * 24)
|
|
|
|
tmp <- fromRepo gitAnnexTmpMiscDir
|
|
|
|
liftIO $ mapM_ (cleanOld (<= oldenough)) =<< dirContentsRecursive tmp
|
|
|
|
|
|
|
|
{- While .git/annex/tmp is now only used for storing partially transferred
|
|
|
|
- objects, older versions of git-annex used it for misctemp. Clean up any
|
|
|
|
- files that might be left from that, by looking for files whose names
|
|
|
|
- cannot be the key of an annexed object. Only delete files older than
|
|
|
|
- 1 week old.
|
|
|
|
-
|
|
|
|
- Also, some remotes such as rsync may use this temp directory for storing
|
|
|
|
- eg, encrypted objects that are being transferred. So, delete old
|
|
|
|
- objects that use a GPGHMAC backend.
|
|
|
|
-}
|
|
|
|
cleanReallyOldTmp :: Annex ()
|
|
|
|
cleanReallyOldTmp = do
|
|
|
|
now <- liftIO getPOSIXTime
|
|
|
|
let oldenough = now - (60 * 60 * 24 * 7)
|
|
|
|
tmp <- fromRepo gitAnnexTmpObjectDir
|
|
|
|
liftIO $ mapM_ (cleanjunk (<= oldenough)) =<< dirContentsRecursive tmp
|
|
|
|
where
|
|
|
|
cleanjunk check f = case fileKey (takeFileName f) of
|
|
|
|
Nothing -> cleanOld check f
|
|
|
|
Just k
|
|
|
|
| "GPGHMAC" `isPrefixOf` keyBackendName k ->
|
|
|
|
cleanOld check f
|
|
|
|
| otherwise -> noop
|
|
|
|
|
|
|
|
cleanOld :: (POSIXTime -> Bool) -> FilePath -> IO ()
|
2014-05-30 19:08:49 +00:00
|
|
|
cleanOld check f = go =<< catchMaybeIO getmtime
|
|
|
|
where
|
|
|
|
getmtime = realToFrac . modificationTime <$> getSymbolicLinkStatus f
|
|
|
|
go (Just mtime) | check mtime = nukeFile f
|
|
|
|
go _ = noop
|
2014-09-15 18:45:37 +00:00
|
|
|
|
|
|
|
checkRepoExists :: Assistant ()
|
|
|
|
checkRepoExists = do
|
|
|
|
g <- liftAnnex gitRepo
|
|
|
|
liftIO $ unlessM (doesDirectoryExist $ Git.repoPath g) $
|
|
|
|
terminateSelf
|