2012-07-07 17:47:36 +00:00
|
|
|
{- git-annex transfer information files and lock files
|
2012-07-01 18:29:00 +00:00
|
|
|
-
|
fix transfer lock file for Download to not include uuid
While redundant concurrent transfers were already prevented in most
cases, it failed to prevent the case where two different repositories were
sending the same content to the same repository. By removing the uuid
from the transfer lock file for Download transfers, one repository
sending content will block the other one from also sending the same
content.
In order to interoperate with old git-annex, the old lock file is still
locked, as well as locking the new one. That added a lot of extra code
and work, and the plan is to eventually stop locking the old lock file,
at some point in time when an old git-annex process is unlikely to be
running at the same time.
Note that in the case of 2 repositories both doing eg
`git-annex copy foo --to origin`
the output is not that great:
copy b (to origin...)
transfer already in progress, or unable to take transfer lock
git-annex: transfer already in progress, or unable to take transfer lock
97% 966.81 MiB 534 GiB/s 0sp2pstdio: 1 failed
Lost connection (fd:14: hPutBuf: resource vanished (Broken pipe))
Transfer failed
Perhaps that output could be cleaned up? Anyway, it's a lot better than letting
the redundant transfer happen and then failing with an obscure error about
a temp file, which is what it did before. And it seems users don't often
try to do this, since nobody ever reported this bug to me before.
(The "97%" there is actually how far along the *other* transfer is.)
Sponsored-by: Joshua Antonishen on Patreon
2024-03-25 18:47:38 +00:00
|
|
|
- Copyright 2012-2024 Joey Hess <id@joeyh.name>
|
2012-07-01 18:29:00 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2012-07-01 18:29:00 +00:00
|
|
|
-}
|
|
|
|
|
2020-10-29 16:02:46 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2013-05-11 20:03:00 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2012-07-01 18:29:00 +00:00
|
|
|
module Logs.Transfer where
|
|
|
|
|
2016-08-03 16:37:12 +00:00
|
|
|
import Types.Transfer
|
2017-03-10 17:12:24 +00:00
|
|
|
import Types.ActionItem
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2012-07-01 18:29:00 +00:00
|
|
|
import qualified Git
|
2023-04-12 21:18:29 +00:00
|
|
|
import qualified Git.Quote
|
2013-03-28 21:03:04 +00:00
|
|
|
import Utility.Metered
|
2012-07-27 15:47:34 +00:00
|
|
|
import Utility.Percentage
|
2014-02-11 19:22:08 +00:00
|
|
|
import Utility.PID
|
2015-11-12 22:05:45 +00:00
|
|
|
import Annex.LockPool
|
2018-10-30 03:13:36 +00:00
|
|
|
import Utility.TimeStamp
|
2018-01-02 21:17:10 +00:00
|
|
|
import Logs.File
|
2020-10-29 16:02:46 +00:00
|
|
|
import qualified Utility.RawFilePath as R
|
2019-05-23 16:13:56 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
|
|
|
import Annex.Perms
|
|
|
|
#endif
|
2012-07-01 18:29:00 +00:00
|
|
|
|
|
|
|
import Data.Time.Clock
|
2012-07-18 22:42:41 +00:00
|
|
|
import Data.Time.Clock.POSIX
|
2021-02-03 19:35:32 +00:00
|
|
|
import Control.Concurrent.STM
|
2020-10-29 16:02:46 +00:00
|
|
|
import qualified Data.ByteString.Char8 as B8
|
|
|
|
import qualified System.FilePath.ByteString as P
|
2012-07-01 18:29:00 +00:00
|
|
|
|
2023-04-12 21:18:29 +00:00
|
|
|
describeTransfer :: Git.Quote.QuotePath -> Transfer -> TransferInfo -> String
|
git style filename quoting controlled by core.quotePath
This is by no means complete, but escaping filenames in actionItemDesc does
cover most commands.
Note that for ActionItemBranchFilePath, the value is branch:file, and I
choose to only quote the file part (if necessary). I considered quoting the
whole thing. But, branch names cannot contain control characters, and while
they can contain unicode, git coes not quote unicode when displaying branch
names. So, it would be surprising for git-annex to quote unicode in a
branch name.
The find command is the most obvious command that still needs to be
dealt with. There are probably other places that filenames also get
displayed, eg embedded in error messages.
Some other commands use ActionItemOther with a filename, I think that
ActionItemOther should either be pre-sanitized, or should explicitly not
be used for filenames, so that needs more work.
When --json is used, unicode does not get escaped, but control
characters were already escaped in json.
(Key escaping may turn out to be needed, but I'm ignoring that for now.)
Sponsored-by: unqueued on Patreon
2023-04-08 18:20:02 +00:00
|
|
|
describeTransfer qp t info = unwords
|
2013-03-01 19:23:59 +00:00
|
|
|
[ show $ transferDirection t
|
|
|
|
, show $ transferUUID t
|
2023-04-10 21:03:41 +00:00
|
|
|
, decodeBS $ quote qp $ actionItemDesc $ ActionItemAssociatedFile
|
2019-06-06 16:53:24 +00:00
|
|
|
(associatedFile info)
|
2017-03-10 17:12:24 +00:00
|
|
|
(transferKey t)
|
2013-04-02 20:38:47 +00:00
|
|
|
, show $ bytesComplete info
|
2013-03-01 19:23:59 +00:00
|
|
|
]
|
|
|
|
|
2012-08-29 19:24:09 +00:00
|
|
|
{- Transfers that will accomplish the same task. -}
|
|
|
|
equivilantTransfer :: Transfer -> Transfer -> Bool
|
|
|
|
equivilantTransfer t1 t2
|
|
|
|
| transferDirection t1 == Download && transferDirection t2 == Download &&
|
2019-11-22 20:24:04 +00:00
|
|
|
transferKeyData t1 == transferKeyData t2 = True
|
2012-08-29 19:24:09 +00:00
|
|
|
| otherwise = t1 == t2
|
|
|
|
|
2012-07-27 15:47:34 +00:00
|
|
|
percentComplete :: Transfer -> TransferInfo -> Maybe Percentage
|
2019-11-22 20:24:04 +00:00
|
|
|
percentComplete t info =
|
|
|
|
percentage
|
|
|
|
<$> keySize (transferKeyData t)
|
|
|
|
<*> Just (fromMaybe 0 $ bytesComplete info)
|
2012-07-27 15:47:34 +00:00
|
|
|
|
2012-09-21 20:23:25 +00:00
|
|
|
{- Generates a callback that can be called as transfer progresses to update
|
fix transfer lock file for Download to not include uuid
While redundant concurrent transfers were already prevented in most
cases, it failed to prevent the case where two different repositories were
sending the same content to the same repository. By removing the uuid
from the transfer lock file for Download transfers, one repository
sending content will block the other one from also sending the same
content.
In order to interoperate with old git-annex, the old lock file is still
locked, as well as locking the new one. That added a lot of extra code
and work, and the plan is to eventually stop locking the old lock file,
at some point in time when an old git-annex process is unlikely to be
running at the same time.
Note that in the case of 2 repositories both doing eg
`git-annex copy foo --to origin`
the output is not that great:
copy b (to origin...)
transfer already in progress, or unable to take transfer lock
git-annex: transfer already in progress, or unable to take transfer lock
97% 966.81 MiB 534 GiB/s 0sp2pstdio: 1 failed
Lost connection (fd:14: hPutBuf: resource vanished (Broken pipe))
Transfer failed
Perhaps that output could be cleaned up? Anyway, it's a lot better than letting
the redundant transfer happen and then failing with an obscure error about
a temp file, which is what it did before. And it seems users don't often
try to do this, since nobody ever reported this bug to me before.
(The "97%" there is actually how far along the *other* transfer is.)
Sponsored-by: Joshua Antonishen on Patreon
2024-03-25 18:47:38 +00:00
|
|
|
- the transfer info file. Also returns an action that sets up the file with
|
|
|
|
- appropriate permissions, which should be run after locking the transfer
|
|
|
|
- lock file, but before using the callback, and a TVar that can be used to
|
|
|
|
- read the number of bytes processed so far. -}
|
|
|
|
mkProgressUpdater :: Transfer -> TransferInfo -> RawFilePath -> Annex (MeterUpdate, Annex (), TVar (Maybe BytesProcessed))
|
|
|
|
mkProgressUpdater t info tfile = do
|
2018-03-14 22:55:27 +00:00
|
|
|
let createtfile = void $ tryNonAsync $ writeTransferInfoFile info tfile
|
2021-02-03 19:35:32 +00:00
|
|
|
tvar <- liftIO $ newTVarIO Nothing
|
|
|
|
loggedtvar <- liftIO $ newTVarIO 0
|
fix transfer lock file for Download to not include uuid
While redundant concurrent transfers were already prevented in most
cases, it failed to prevent the case where two different repositories were
sending the same content to the same repository. By removing the uuid
from the transfer lock file for Download transfers, one repository
sending content will block the other one from also sending the same
content.
In order to interoperate with old git-annex, the old lock file is still
locked, as well as locking the new one. That added a lot of extra code
and work, and the plan is to eventually stop locking the old lock file,
at some point in time when an old git-annex process is unlikely to be
running at the same time.
Note that in the case of 2 repositories both doing eg
`git-annex copy foo --to origin`
the output is not that great:
copy b (to origin...)
transfer already in progress, or unable to take transfer lock
git-annex: transfer already in progress, or unable to take transfer lock
97% 966.81 MiB 534 GiB/s 0sp2pstdio: 1 failed
Lost connection (fd:14: hPutBuf: resource vanished (Broken pipe))
Transfer failed
Perhaps that output could be cleaned up? Anyway, it's a lot better than letting
the redundant transfer happen and then failing with an obscure error about
a temp file, which is what it did before. And it seems users don't often
try to do this, since nobody ever reported this bug to me before.
(The "97%" there is actually how far along the *other* transfer is.)
Sponsored-by: Joshua Antonishen on Patreon
2024-03-25 18:47:38 +00:00
|
|
|
return (liftIO . updater (fromRawFilePath tfile) tvar loggedtvar, createtfile, tvar)
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
fix transfer lock file for Download to not include uuid
While redundant concurrent transfers were already prevented in most
cases, it failed to prevent the case where two different repositories were
sending the same content to the same repository. By removing the uuid
from the transfer lock file for Download transfers, one repository
sending content will block the other one from also sending the same
content.
In order to interoperate with old git-annex, the old lock file is still
locked, as well as locking the new one. That added a lot of extra code
and work, and the plan is to eventually stop locking the old lock file,
at some point in time when an old git-annex process is unlikely to be
running at the same time.
Note that in the case of 2 repositories both doing eg
`git-annex copy foo --to origin`
the output is not that great:
copy b (to origin...)
transfer already in progress, or unable to take transfer lock
git-annex: transfer already in progress, or unable to take transfer lock
97% 966.81 MiB 534 GiB/s 0sp2pstdio: 1 failed
Lost connection (fd:14: hPutBuf: resource vanished (Broken pipe))
Transfer failed
Perhaps that output could be cleaned up? Anyway, it's a lot better than letting
the redundant transfer happen and then failing with an obscure error about
a temp file, which is what it did before. And it seems users don't often
try to do this, since nobody ever reported this bug to me before.
(The "97%" there is actually how far along the *other* transfer is.)
Sponsored-by: Joshua Antonishen on Patreon
2024-03-25 18:47:38 +00:00
|
|
|
updater tfile' tvar loggedtvar new = do
|
2021-02-03 19:35:32 +00:00
|
|
|
old <- atomically $ swapTVar tvar (Just new)
|
|
|
|
let oldbytes = maybe 0 fromBytesProcessed old
|
|
|
|
let newbytes = fromBytesProcessed new
|
|
|
|
when (newbytes - oldbytes >= mindelta) $ do
|
|
|
|
let info' = info { bytesComplete = Just newbytes }
|
fix transfer lock file for Download to not include uuid
While redundant concurrent transfers were already prevented in most
cases, it failed to prevent the case where two different repositories were
sending the same content to the same repository. By removing the uuid
from the transfer lock file for Download transfers, one repository
sending content will block the other one from also sending the same
content.
In order to interoperate with old git-annex, the old lock file is still
locked, as well as locking the new one. That added a lot of extra code
and work, and the plan is to eventually stop locking the old lock file,
at some point in time when an old git-annex process is unlikely to be
running at the same time.
Note that in the case of 2 repositories both doing eg
`git-annex copy foo --to origin`
the output is not that great:
copy b (to origin...)
transfer already in progress, or unable to take transfer lock
git-annex: transfer already in progress, or unable to take transfer lock
97% 966.81 MiB 534 GiB/s 0sp2pstdio: 1 failed
Lost connection (fd:14: hPutBuf: resource vanished (Broken pipe))
Transfer failed
Perhaps that output could be cleaned up? Anyway, it's a lot better than letting
the redundant transfer happen and then failing with an obscure error about
a temp file, which is what it did before. And it seems users don't often
try to do this, since nobody ever reported this bug to me before.
(The "97%" there is actually how far along the *other* transfer is.)
Sponsored-by: Joshua Antonishen on Patreon
2024-03-25 18:47:38 +00:00
|
|
|
_ <- tryIO $ updateTransferInfoFile info' tfile'
|
2021-02-03 19:35:32 +00:00
|
|
|
atomically $ writeTVar loggedtvar newbytes
|
|
|
|
|
2012-11-11 04:51:07 +00:00
|
|
|
{- The minimum change in bytesComplete that is worth
|
|
|
|
- updating a transfer info file for is 1% of the total
|
|
|
|
- keySize, rounded down. -}
|
2019-11-22 20:24:04 +00:00
|
|
|
mindelta = case keySize (transferKeyData t) of
|
2012-11-11 04:51:07 +00:00
|
|
|
Just sz -> sz `div` 100
|
|
|
|
Nothing -> 100 * 1024 -- arbitrarily, 100 kb
|
2012-07-01 18:29:00 +00:00
|
|
|
|
2017-03-10 17:12:24 +00:00
|
|
|
startTransferInfo :: AssociatedFile -> IO TransferInfo
|
|
|
|
startTransferInfo afile = TransferInfo
|
2012-09-21 20:23:25 +00:00
|
|
|
<$> (Just . utcTimeToPOSIXSeconds <$> getCurrentTime)
|
2013-12-11 04:15:10 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
2012-09-21 20:23:25 +00:00
|
|
|
<*> pure Nothing -- pid not stored in file, so omitted for speed
|
2013-12-11 04:15:10 +00:00
|
|
|
#else
|
2014-02-11 19:22:08 +00:00
|
|
|
<*> (Just <$> getPID)
|
2013-12-11 04:15:10 +00:00
|
|
|
#endif
|
2012-09-21 20:23:25 +00:00
|
|
|
<*> pure Nothing -- tid ditto
|
|
|
|
<*> pure Nothing -- not 0; transfer may be resuming
|
|
|
|
<*> pure Nothing
|
2017-03-10 17:12:24 +00:00
|
|
|
<*> pure afile
|
2012-09-21 20:23:25 +00:00
|
|
|
<*> pure False
|
|
|
|
|
2015-05-13 00:11:23 +00:00
|
|
|
{- If a transfer is still running, returns its TransferInfo.
|
|
|
|
-
|
|
|
|
- If no transfer is running, attempts to clean up the stale
|
fix transfer lock file for Download to not include uuid
While redundant concurrent transfers were already prevented in most
cases, it failed to prevent the case where two different repositories were
sending the same content to the same repository. By removing the uuid
from the transfer lock file for Download transfers, one repository
sending content will block the other one from also sending the same
content.
In order to interoperate with old git-annex, the old lock file is still
locked, as well as locking the new one. That added a lot of extra code
and work, and the plan is to eventually stop locking the old lock file,
at some point in time when an old git-annex process is unlikely to be
running at the same time.
Note that in the case of 2 repositories both doing eg
`git-annex copy foo --to origin`
the output is not that great:
copy b (to origin...)
transfer already in progress, or unable to take transfer lock
git-annex: transfer already in progress, or unable to take transfer lock
97% 966.81 MiB 534 GiB/s 0sp2pstdio: 1 failed
Lost connection (fd:14: hPutBuf: resource vanished (Broken pipe))
Transfer failed
Perhaps that output could be cleaned up? Anyway, it's a lot better than letting
the redundant transfer happen and then failing with an obscure error about
a temp file, which is what it did before. And it seems users don't often
try to do this, since nobody ever reported this bug to me before.
(The "97%" there is actually how far along the *other* transfer is.)
Sponsored-by: Joshua Antonishen on Patreon
2024-03-25 18:47:38 +00:00
|
|
|
- lock and info files, which can be left behind when a transfer
|
|
|
|
- process was interrupted.
|
2015-05-13 00:11:23 +00:00
|
|
|
-}
|
2012-07-01 18:29:00 +00:00
|
|
|
checkTransfer :: Transfer -> Annex (Maybe TransferInfo)
|
2018-11-19 19:00:24 +00:00
|
|
|
checkTransfer t = debugLocks $ do
|
fix transfer lock file for Download to not include uuid
While redundant concurrent transfers were already prevented in most
cases, it failed to prevent the case where two different repositories were
sending the same content to the same repository. By removing the uuid
from the transfer lock file for Download transfers, one repository
sending content will block the other one from also sending the same
content.
In order to interoperate with old git-annex, the old lock file is still
locked, as well as locking the new one. That added a lot of extra code
and work, and the plan is to eventually stop locking the old lock file,
at some point in time when an old git-annex process is unlikely to be
running at the same time.
Note that in the case of 2 repositories both doing eg
`git-annex copy foo --to origin`
the output is not that great:
copy b (to origin...)
transfer already in progress, or unable to take transfer lock
git-annex: transfer already in progress, or unable to take transfer lock
97% 966.81 MiB 534 GiB/s 0sp2pstdio: 1 failed
Lost connection (fd:14: hPutBuf: resource vanished (Broken pipe))
Transfer failed
Perhaps that output could be cleaned up? Anyway, it's a lot better than letting
the redundant transfer happen and then failing with an obscure error about
a temp file, which is what it did before. And it seems users don't often
try to do this, since nobody ever reported this bug to me before.
(The "97%" there is actually how far along the *other* transfer is.)
Sponsored-by: Joshua Antonishen on Patreon
2024-03-25 18:47:38 +00:00
|
|
|
(tfile, lck, moldlck) <- fromRepo $ transferFileAndLockFile t
|
|
|
|
let deletestale = do
|
2020-10-29 16:02:46 +00:00
|
|
|
void $ tryIO $ R.removeLink tfile
|
|
|
|
void $ tryIO $ R.removeLink lck
|
fix transfer lock file for Download to not include uuid
While redundant concurrent transfers were already prevented in most
cases, it failed to prevent the case where two different repositories were
sending the same content to the same repository. By removing the uuid
from the transfer lock file for Download transfers, one repository
sending content will block the other one from also sending the same
content.
In order to interoperate with old git-annex, the old lock file is still
locked, as well as locking the new one. That added a lot of extra code
and work, and the plan is to eventually stop locking the old lock file,
at some point in time when an old git-annex process is unlikely to be
running at the same time.
Note that in the case of 2 repositories both doing eg
`git-annex copy foo --to origin`
the output is not that great:
copy b (to origin...)
transfer already in progress, or unable to take transfer lock
git-annex: transfer already in progress, or unable to take transfer lock
97% 966.81 MiB 534 GiB/s 0sp2pstdio: 1 failed
Lost connection (fd:14: hPutBuf: resource vanished (Broken pipe))
Transfer failed
Perhaps that output could be cleaned up? Anyway, it's a lot better than letting
the redundant transfer happen and then failing with an obscure error about
a temp file, which is what it did before. And it seems users don't often
try to do this, since nobody ever reported this bug to me before.
(The "97%" there is actually how far along the *other* transfer is.)
Sponsored-by: Joshua Antonishen on Patreon
2024-03-25 18:47:38 +00:00
|
|
|
maybe noop (void . tryIO . R.removeLink) moldlck
|
2013-08-02 16:27:32 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
2015-11-12 22:05:45 +00:00
|
|
|
v <- getLockStatus lck
|
fix transfer lock file for Download to not include uuid
While redundant concurrent transfers were already prevented in most
cases, it failed to prevent the case where two different repositories were
sending the same content to the same repository. By removing the uuid
from the transfer lock file for Download transfers, one repository
sending content will block the other one from also sending the same
content.
In order to interoperate with old git-annex, the old lock file is still
locked, as well as locking the new one. That added a lot of extra code
and work, and the plan is to eventually stop locking the old lock file,
at some point in time when an old git-annex process is unlikely to be
running at the same time.
Note that in the case of 2 repositories both doing eg
`git-annex copy foo --to origin`
the output is not that great:
copy b (to origin...)
transfer already in progress, or unable to take transfer lock
git-annex: transfer already in progress, or unable to take transfer lock
97% 966.81 MiB 534 GiB/s 0sp2pstdio: 1 failed
Lost connection (fd:14: hPutBuf: resource vanished (Broken pipe))
Transfer failed
Perhaps that output could be cleaned up? Anyway, it's a lot better than letting
the redundant transfer happen and then failing with an obscure error about
a temp file, which is what it did before. And it seems users don't often
try to do this, since nobody ever reported this bug to me before.
(The "97%" there is actually how far along the *other* transfer is.)
Sponsored-by: Joshua Antonishen on Patreon
2024-03-25 18:47:38 +00:00
|
|
|
v' <- case (moldlck, v) of
|
|
|
|
(Nothing, _) -> pure v
|
|
|
|
(_, StatusLockedBy pid) -> pure (StatusLockedBy pid)
|
|
|
|
(Just oldlck, _) -> getLockStatus oldlck
|
|
|
|
case v' of
|
2015-11-12 22:05:45 +00:00
|
|
|
StatusLockedBy pid -> liftIO $ catchDefaultIO Nothing $
|
2020-10-29 16:02:46 +00:00
|
|
|
readTransferInfoFile (Just pid) (fromRawFilePath tfile)
|
2017-10-02 17:55:26 +00:00
|
|
|
_ -> do
|
fix transfer lock file for Download to not include uuid
While redundant concurrent transfers were already prevented in most
cases, it failed to prevent the case where two different repositories were
sending the same content to the same repository. By removing the uuid
from the transfer lock file for Download transfers, one repository
sending content will block the other one from also sending the same
content.
In order to interoperate with old git-annex, the old lock file is still
locked, as well as locking the new one. That added a lot of extra code
and work, and the plan is to eventually stop locking the old lock file,
at some point in time when an old git-annex process is unlikely to be
running at the same time.
Note that in the case of 2 repositories both doing eg
`git-annex copy foo --to origin`
the output is not that great:
copy b (to origin...)
transfer already in progress, or unable to take transfer lock
git-annex: transfer already in progress, or unable to take transfer lock
97% 966.81 MiB 534 GiB/s 0sp2pstdio: 1 failed
Lost connection (fd:14: hPutBuf: resource vanished (Broken pipe))
Transfer failed
Perhaps that output could be cleaned up? Anyway, it's a lot better than letting
the redundant transfer happen and then failing with an obscure error about
a temp file, which is what it did before. And it seems users don't often
try to do this, since nobody ever reported this bug to me before.
(The "97%" there is actually how far along the *other* transfer is.)
Sponsored-by: Joshua Antonishen on Patreon
2024-03-25 18:47:38 +00:00
|
|
|
mode <- annexFileMode
|
|
|
|
-- Ignore failure due to permissions, races, etc.
|
|
|
|
void $ tryIO $ tryLockExclusive (Just mode) lck >>= \case
|
|
|
|
Just lockhandle -> case moldlck of
|
|
|
|
Nothing -> liftIO $ do
|
|
|
|
deletestale
|
2015-11-12 22:05:45 +00:00
|
|
|
dropLock lockhandle
|
fix transfer lock file for Download to not include uuid
While redundant concurrent transfers were already prevented in most
cases, it failed to prevent the case where two different repositories were
sending the same content to the same repository. By removing the uuid
from the transfer lock file for Download transfers, one repository
sending content will block the other one from also sending the same
content.
In order to interoperate with old git-annex, the old lock file is still
locked, as well as locking the new one. That added a lot of extra code
and work, and the plan is to eventually stop locking the old lock file,
at some point in time when an old git-annex process is unlikely to be
running at the same time.
Note that in the case of 2 repositories both doing eg
`git-annex copy foo --to origin`
the output is not that great:
copy b (to origin...)
transfer already in progress, or unable to take transfer lock
git-annex: transfer already in progress, or unable to take transfer lock
97% 966.81 MiB 534 GiB/s 0sp2pstdio: 1 failed
Lost connection (fd:14: hPutBuf: resource vanished (Broken pipe))
Transfer failed
Perhaps that output could be cleaned up? Anyway, it's a lot better than letting
the redundant transfer happen and then failing with an obscure error about
a temp file, which is what it did before. And it seems users don't often
try to do this, since nobody ever reported this bug to me before.
(The "97%" there is actually how far along the *other* transfer is.)
Sponsored-by: Joshua Antonishen on Patreon
2024-03-25 18:47:38 +00:00
|
|
|
Just oldlck -> tryLockExclusive (Just mode) oldlck >>= \case
|
|
|
|
Just oldlockhandle -> liftIO $ do
|
|
|
|
deletestale
|
|
|
|
dropLock oldlockhandle
|
|
|
|
dropLock lockhandle
|
|
|
|
Nothing -> liftIO $ dropLock lockhandle
|
|
|
|
Nothing -> noop
|
2015-11-12 22:05:45 +00:00
|
|
|
return Nothing
|
2013-05-11 20:03:00 +00:00
|
|
|
#else
|
2017-10-02 17:55:26 +00:00
|
|
|
v <- liftIO $ lockShared lck
|
2014-01-28 18:17:14 +00:00
|
|
|
liftIO $ case v of
|
|
|
|
Nothing -> catchDefaultIO Nothing $
|
2020-11-19 16:33:00 +00:00
|
|
|
readTransferInfoFile Nothing (fromRawFilePath tfile)
|
2014-01-28 18:17:14 +00:00
|
|
|
Just lockhandle -> do
|
|
|
|
dropLock lockhandle
|
2024-03-26 17:12:58 +00:00
|
|
|
deletestale
|
2014-01-28 18:17:14 +00:00
|
|
|
return Nothing
|
2013-05-11 20:03:00 +00:00
|
|
|
#endif
|
2012-07-01 18:29:00 +00:00
|
|
|
|
|
|
|
{- Gets all currently running transfers. -}
|
|
|
|
getTransfers :: Annex [(Transfer, TransferInfo)]
|
2015-05-12 22:34:49 +00:00
|
|
|
getTransfers = getTransfers' [Download, Upload] (const True)
|
2015-05-12 19:19:08 +00:00
|
|
|
|
2015-05-12 22:34:49 +00:00
|
|
|
getTransfers' :: [Direction] -> (Key -> Bool) -> Annex [(Transfer, TransferInfo)]
|
|
|
|
getTransfers' dirs wanted = do
|
|
|
|
transfers <- filter (wanted . transferKey)
|
|
|
|
<$> mapMaybe parseTransferFile . concat <$> findfiles
|
2012-07-01 18:29:00 +00:00
|
|
|
infos <- mapM checkTransfer transfers
|
2020-04-15 17:55:08 +00:00
|
|
|
return $ mapMaybe running $ zip transfers infos
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2023-08-15 16:57:41 +00:00
|
|
|
findfiles = liftIO . mapM (emptyWhenDoesNotExist . dirContentsRecursive . fromRawFilePath)
|
2015-05-12 19:19:08 +00:00
|
|
|
=<< mapM (fromRepo . transferDir) dirs
|
2020-04-15 17:55:08 +00:00
|
|
|
running (t, Just i) = Just (t, i)
|
|
|
|
running (_, Nothing) = Nothing
|
2012-07-01 18:29:00 +00:00
|
|
|
|
2015-05-12 19:19:08 +00:00
|
|
|
{- Number of bytes remaining to download from matching downloads that are in
|
|
|
|
- progress. -}
|
|
|
|
sizeOfDownloadsInProgress :: (Key -> Bool) -> Annex Integer
|
2015-05-12 22:34:49 +00:00
|
|
|
sizeOfDownloadsInProgress wanted = sum . map remaining
|
|
|
|
<$> getTransfers' [Download] wanted
|
2015-05-12 19:19:08 +00:00
|
|
|
where
|
|
|
|
remaining (t, info) =
|
2019-11-22 20:24:04 +00:00
|
|
|
case (fromKey keySize (transferKey t), bytesComplete info) of
|
2015-05-12 19:19:08 +00:00
|
|
|
(Just sz, Just done) -> sz - done
|
|
|
|
(Just sz, Nothing) -> sz
|
|
|
|
(Nothing, _) -> 0
|
|
|
|
|
2012-08-23 19:22:23 +00:00
|
|
|
{- Gets failed transfers for a given remote UUID. -}
|
|
|
|
getFailedTransfers :: UUID -> Annex [(Transfer, TransferInfo)]
|
|
|
|
getFailedTransfers u = catMaybes <$> (liftIO . getpairs =<< concat <$> findfiles)
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
|
|
|
getpairs = mapM $ \f -> do
|
|
|
|
let mt = parseTransferFile f
|
|
|
|
mi <- readTransferInfoFile Nothing f
|
|
|
|
return $ case (mt, mi) of
|
|
|
|
(Just t, Just i) -> Just (t, i)
|
|
|
|
_ -> Nothing
|
2023-08-15 16:57:41 +00:00
|
|
|
findfiles = liftIO . mapM (emptyWhenDoesNotExist . dirContentsRecursive . fromRawFilePath)
|
2012-11-11 04:51:07 +00:00
|
|
|
=<< mapM (fromRepo . failedTransferDir u) [Download, Upload]
|
2012-08-23 19:22:23 +00:00
|
|
|
|
2013-09-25 15:46:17 +00:00
|
|
|
clearFailedTransfers :: UUID -> Annex [(Transfer, TransferInfo)]
|
|
|
|
clearFailedTransfers u = do
|
|
|
|
failed <- getFailedTransfers u
|
2013-09-26 03:19:01 +00:00
|
|
|
mapM_ (removeFailedTransfer . fst) failed
|
2013-09-25 15:46:17 +00:00
|
|
|
return failed
|
|
|
|
|
2012-09-17 18:58:43 +00:00
|
|
|
removeFailedTransfer :: Transfer -> Annex ()
|
|
|
|
removeFailedTransfer t = do
|
|
|
|
f <- fromRepo $ failedTransferFile t
|
2020-10-29 16:02:46 +00:00
|
|
|
liftIO $ void $ tryIO $ R.removeLink f
|
2012-09-17 18:58:43 +00:00
|
|
|
|
2013-03-19 00:34:56 +00:00
|
|
|
recordFailedTransfer :: Transfer -> TransferInfo -> Annex ()
|
|
|
|
recordFailedTransfer t info = do
|
|
|
|
failedtfile <- fromRepo $ failedTransferFile t
|
2018-01-02 21:17:10 +00:00
|
|
|
writeTransferInfoFile info failedtfile
|
2013-03-19 00:34:56 +00:00
|
|
|
|
fix transfer lock file for Download to not include uuid
While redundant concurrent transfers were already prevented in most
cases, it failed to prevent the case where two different repositories were
sending the same content to the same repository. By removing the uuid
from the transfer lock file for Download transfers, one repository
sending content will block the other one from also sending the same
content.
In order to interoperate with old git-annex, the old lock file is still
locked, as well as locking the new one. That added a lot of extra code
and work, and the plan is to eventually stop locking the old lock file,
at some point in time when an old git-annex process is unlikely to be
running at the same time.
Note that in the case of 2 repositories both doing eg
`git-annex copy foo --to origin`
the output is not that great:
copy b (to origin...)
transfer already in progress, or unable to take transfer lock
git-annex: transfer already in progress, or unable to take transfer lock
97% 966.81 MiB 534 GiB/s 0sp2pstdio: 1 failed
Lost connection (fd:14: hPutBuf: resource vanished (Broken pipe))
Transfer failed
Perhaps that output could be cleaned up? Anyway, it's a lot better than letting
the redundant transfer happen and then failing with an obscure error about
a temp file, which is what it did before. And it seems users don't often
try to do this, since nobody ever reported this bug to me before.
(The "97%" there is actually how far along the *other* transfer is.)
Sponsored-by: Joshua Antonishen on Patreon
2024-03-25 18:47:38 +00:00
|
|
|
{- The transfer information file and transfer lock file
|
|
|
|
- to use for a given Transfer.
|
|
|
|
-
|
|
|
|
- The transfer lock file used for an Upload includes the UUID.
|
|
|
|
- This allows multiple transfers of the same key to different remote
|
|
|
|
- repositories run at the same time, while preventing multiple
|
|
|
|
- transfers of the same key to the same remote repository.
|
|
|
|
-
|
|
|
|
- The transfer lock file used for a Download does not include the UUID.
|
|
|
|
- This prevents multiple transfers of the same key into the local
|
|
|
|
- repository at the same time.
|
|
|
|
-
|
|
|
|
- Since old versions of git-annex (10.20240227 and older) used to
|
|
|
|
- include the UUID in the transfer lock file for a Download, this also
|
|
|
|
- returns a second lock file for Downloads, which has to be locked
|
|
|
|
- in order to interoperate with the old git-annex processes.
|
|
|
|
- Lock order is the same as return value order.
|
|
|
|
- At some point in the future, when old git-annex processes are no longer
|
|
|
|
- a concern, this complication can be removed.
|
|
|
|
-}
|
|
|
|
transferFileAndLockFile :: Transfer -> Git.Repo -> (RawFilePath, RawFilePath, Maybe RawFilePath)
|
|
|
|
transferFileAndLockFile (Transfer direction u kd) r =
|
|
|
|
case direction of
|
|
|
|
Upload -> (transferfile, uuidlockfile, Nothing)
|
|
|
|
Download -> (transferfile, nouuidlockfile, Just uuidlockfile)
|
|
|
|
where
|
|
|
|
td = transferDir direction r
|
|
|
|
fu = B8.filter (/= '/') (fromUUID u)
|
|
|
|
kf = keyFile (mkKey (const kd))
|
|
|
|
lckkf = "lck." <> kf
|
|
|
|
transferfile = td P.</> fu P.</> kf
|
|
|
|
uuidlockfile = td P.</> fu P.</> lckkf
|
|
|
|
nouuidlockfile = td P.</> "lck" P.</> lckkf
|
2012-07-01 18:29:00 +00:00
|
|
|
|
2012-08-23 19:22:23 +00:00
|
|
|
{- The transfer information file to use to record a failed Transfer -}
|
2020-10-29 16:02:46 +00:00
|
|
|
failedTransferFile :: Transfer -> Git.Repo -> RawFilePath
|
|
|
|
failedTransferFile (Transfer direction u kd) r =
|
|
|
|
failedTransferDir u direction r
|
|
|
|
P.</> keyFile (mkKey (const kd))
|
2012-08-23 19:22:23 +00:00
|
|
|
|
2012-07-01 18:29:00 +00:00
|
|
|
{- Parses a transfer information filename to a Transfer. -}
|
2012-07-01 20:59:54 +00:00
|
|
|
parseTransferFile :: FilePath -> Maybe Transfer
|
2012-07-17 21:26:53 +00:00
|
|
|
parseTransferFile file
|
2013-04-03 07:52:41 +00:00
|
|
|
| "lck." `isPrefixOf` takeFileName file = Nothing
|
2012-07-17 21:26:53 +00:00
|
|
|
| otherwise = case drop (length bits - 3) bits of
|
2012-07-01 19:04:29 +00:00
|
|
|
[direction, u, key] -> Transfer
|
2017-02-24 22:51:57 +00:00
|
|
|
<$> parseDirection direction
|
2012-07-01 20:59:54 +00:00
|
|
|
<*> pure (toUUID u)
|
2019-12-18 20:45:03 +00:00
|
|
|
<*> fmap (fromKey id) (fileKey (toRawFilePath key))
|
2012-07-01 18:29:00 +00:00
|
|
|
_ -> Nothing
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
|
|
|
bits = splitDirectories file
|
2012-07-01 18:29:00 +00:00
|
|
|
|
2020-10-29 16:02:46 +00:00
|
|
|
writeTransferInfoFile :: TransferInfo -> RawFilePath -> Annex ()
|
2018-01-02 21:17:10 +00:00
|
|
|
writeTransferInfoFile info tfile = writeLogFile tfile $ writeTransferInfo info
|
|
|
|
|
|
|
|
-- The file keeps whatever permissions it has, so should be used only
|
|
|
|
-- after it's been created with the right perms by writeTransferInfoFile.
|
|
|
|
updateTransferInfoFile :: TransferInfo -> FilePath -> IO ()
|
|
|
|
updateTransferInfoFile info tfile = writeFile tfile $ writeTransferInfo info
|
2012-09-16 05:53:06 +00:00
|
|
|
|
2012-09-19 20:08:37 +00:00
|
|
|
{- File format is a header line containing the startedTime and any
|
|
|
|
- bytesComplete value. Followed by a newline and the associatedFile.
|
|
|
|
-
|
2013-12-11 04:15:10 +00:00
|
|
|
- On unix, the transferPid is not included; instead it is obtained
|
|
|
|
- by looking at the process that locks the file.
|
|
|
|
-
|
|
|
|
- On windows, the transferPid is included, as a second line.
|
2012-09-19 20:08:37 +00:00
|
|
|
-}
|
2012-07-01 18:29:00 +00:00
|
|
|
writeTransferInfo :: TransferInfo -> String
|
2012-07-01 19:04:29 +00:00
|
|
|
writeTransferInfo info = unlines
|
2012-09-19 20:08:37 +00:00
|
|
|
[ (maybe "" show $ startedTime info) ++
|
2013-04-03 07:52:41 +00:00
|
|
|
(maybe "" (\b -> ' ' : show b) (bytesComplete info))
|
2013-12-11 04:15:10 +00:00
|
|
|
#ifdef mingw32_HOST_OS
|
|
|
|
, maybe "" show (transferPid info)
|
|
|
|
#endif
|
2017-03-10 17:12:24 +00:00
|
|
|
-- comes last; arbitrary content
|
|
|
|
, let AssociatedFile afile = associatedFile info
|
2019-11-26 19:27:22 +00:00
|
|
|
in maybe "" fromRawFilePath afile
|
2012-07-01 18:29:00 +00:00
|
|
|
]
|
|
|
|
|
2013-12-11 03:32:10 +00:00
|
|
|
readTransferInfoFile :: Maybe PID -> FilePath -> IO (Maybe TransferInfo)
|
2014-02-03 14:16:05 +00:00
|
|
|
readTransferInfoFile mpid tfile = catchDefaultIO Nothing $
|
2016-12-24 18:46:31 +00:00
|
|
|
readTransferInfo mpid <$> readFileStrict tfile
|
2012-09-16 05:53:06 +00:00
|
|
|
|
2013-12-11 03:32:10 +00:00
|
|
|
readTransferInfo :: Maybe PID -> String -> Maybe TransferInfo
|
2012-09-19 20:08:37 +00:00
|
|
|
readTransferInfo mpid s = TransferInfo
|
|
|
|
<$> time
|
2013-12-11 04:15:10 +00:00
|
|
|
#ifdef mingw32_HOST_OS
|
2013-12-11 04:18:58 +00:00
|
|
|
<*> pure (if isJust mpid then mpid else mpid')
|
2013-12-11 04:15:10 +00:00
|
|
|
#else
|
2012-09-19 20:08:37 +00:00
|
|
|
<*> pure mpid
|
2013-12-11 04:15:10 +00:00
|
|
|
#endif
|
2012-09-19 20:08:37 +00:00
|
|
|
<*> pure Nothing
|
|
|
|
<*> pure Nothing
|
|
|
|
<*> bytes
|
2019-11-26 19:27:22 +00:00
|
|
|
<*> pure (AssociatedFile (if null filename then Nothing else Just (toRawFilePath filename)))
|
2012-09-19 20:08:37 +00:00
|
|
|
<*> pure False
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2013-12-11 04:15:10 +00:00
|
|
|
#ifdef mingw32_HOST_OS
|
2014-01-28 18:43:20 +00:00
|
|
|
(firstline, otherlines) = separate (== '\n') s
|
|
|
|
(secondline, rest) = separate (== '\n') otherlines
|
2013-12-11 04:15:10 +00:00
|
|
|
mpid' = readish secondline
|
|
|
|
#else
|
2012-12-19 18:16:58 +00:00
|
|
|
(firstline, rest) = separate (== '\n') s
|
2013-12-11 04:15:10 +00:00
|
|
|
#endif
|
2012-12-19 20:15:39 +00:00
|
|
|
filename
|
|
|
|
| end rest == "\n" = beginning rest
|
|
|
|
| otherwise = rest
|
2017-01-31 22:40:42 +00:00
|
|
|
bits = splitc ' ' firstline
|
2012-11-11 04:51:07 +00:00
|
|
|
numbits = length bits
|
|
|
|
time = if numbits > 0
|
|
|
|
then Just <$> parsePOSIXTime =<< headMaybe bits
|
|
|
|
else pure Nothing -- not failure
|
|
|
|
bytes = if numbits > 1
|
|
|
|
then Just <$> readish =<< headMaybe (drop 1 bits)
|
|
|
|
else pure Nothing -- not failure
|
2012-07-19 00:48:08 +00:00
|
|
|
|
2012-08-23 17:42:13 +00:00
|
|
|
{- The directory holding transfer information files for a given Direction. -}
|
2020-10-29 16:02:46 +00:00
|
|
|
transferDir :: Direction -> Git.Repo -> RawFilePath
|
|
|
|
transferDir direction r = gitAnnexTransferDir r P.</> formatDirection direction
|
2012-08-23 17:42:13 +00:00
|
|
|
|
2012-08-23 19:22:23 +00:00
|
|
|
{- The directory holding failed transfer information files for a given
|
|
|
|
- Direction and UUID -}
|
2020-10-29 16:02:46 +00:00
|
|
|
failedTransferDir :: UUID -> Direction -> Git.Repo -> RawFilePath
|
2012-08-23 19:22:23 +00:00
|
|
|
failedTransferDir u direction r = gitAnnexTransferDir r
|
2020-10-29 16:02:46 +00:00
|
|
|
P.</> "failed"
|
|
|
|
P.</> formatDirection direction
|
|
|
|
P.</> B8.filter (/= '/') (fromUUID u)
|
2013-02-28 01:42:07 +00:00
|
|
|
|
|
|
|
prop_read_write_transferinfo :: TransferInfo -> Bool
|
|
|
|
prop_read_write_transferinfo info
|
2013-04-03 07:52:41 +00:00
|
|
|
| isJust (transferRemote info) = True -- remote not stored
|
|
|
|
| isJust (transferTid info) = True -- tid not stored
|
2013-02-28 01:42:07 +00:00
|
|
|
| otherwise = Just (info { transferPaused = False }) == info'
|
|
|
|
where
|
|
|
|
info' = readTransferInfo (transferPid info) (writeTransferInfo info)
|
|
|
|
|