2012-07-05 20:34:20 +00:00
|
|
|
{- git-annex assistant data transferrer thread
|
|
|
|
-
|
|
|
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Assistant.Threads.Transferrer where
|
|
|
|
|
2012-07-20 23:29:59 +00:00
|
|
|
import Assistant.Common
|
2012-07-05 20:34:20 +00:00
|
|
|
import Assistant.DaemonStatus
|
|
|
|
import Assistant.TransferQueue
|
2012-07-06 20:39:07 +00:00
|
|
|
import Assistant.TransferSlots
|
2012-08-06 21:09:23 +00:00
|
|
|
import Assistant.Alert
|
2013-04-04 05:48:26 +00:00
|
|
|
import Assistant.Alert.Utility
|
ensure that git-annex branch is pushed after a successful transfer
I now have this topology working:
assistant ---> {bare repo, special remote} <--- assistant
And, I think, also this one:
+----------- bare repo --------+
v v
assistant ---> special remote <--- assistant
While before with assistant <---> assistant connections, both sides got
location info updated after a transfer, in this topology, the bare repo
*might* get its location info updated, but the other assistant has no way to
know that it did. And a special remote doesn't record location info,
so transfers to it won't propigate out location log changes at all.
So, for these to work, after a transfer succeeds, the git-annex branch
needs to be pushed. This is done by recording a synthetic commit has
occurred, which lets the pusher handle pushing out the change (which will
include actually committing any still journalled changes to the git-annex
branch).
Of course, this means rather a lot more syncing action than happened
before. At least the pusher bundles together very close together pushes,
somewhat. Currently it just waits 2 seconds between each push.
2012-10-28 20:05:34 +00:00
|
|
|
import Assistant.Commits
|
2012-11-24 20:30:15 +00:00
|
|
|
import Assistant.Drop
|
2013-03-19 22:46:29 +00:00
|
|
|
import Assistant.TransferrerPool
|
2012-07-05 20:34:20 +00:00
|
|
|
import Logs.Transfer
|
2012-07-07 16:50:20 +00:00
|
|
|
import Logs.Location
|
2012-07-05 20:34:20 +00:00
|
|
|
import Annex.Content
|
2012-07-07 16:50:20 +00:00
|
|
|
import qualified Remote
|
2013-03-19 00:34:56 +00:00
|
|
|
import qualified Types.Remote as Remote
|
|
|
|
import qualified Git
|
2013-04-23 15:38:52 +00:00
|
|
|
import Config.Files
|
2013-03-01 20:46:36 +00:00
|
|
|
import Assistant.Threads.TransferWatcher
|
2013-03-13 17:36:02 +00:00
|
|
|
import Annex.Wanted
|
2012-07-05 20:34:20 +00:00
|
|
|
|
2012-07-06 00:57:06 +00:00
|
|
|
{- Dispatches transfers from the queue. -}
|
2012-10-29 18:07:12 +00:00
|
|
|
transfererThread :: NamedThread
|
2013-01-26 06:09:33 +00:00
|
|
|
transfererThread = namedThread "Transferrer" $ do
|
2012-10-29 18:07:12 +00:00
|
|
|
program <- liftIO readProgramFile
|
2013-03-19 22:46:29 +00:00
|
|
|
forever $ inTransferSlot program $
|
|
|
|
maybe (return Nothing) (uncurry $ genTransfer)
|
2012-10-30 21:14:26 +00:00
|
|
|
=<< getNextTransfer notrunning
|
2012-10-29 18:07:12 +00:00
|
|
|
where
|
|
|
|
{- Skip transfers that are already running. -}
|
|
|
|
notrunning = isNothing . startedTime
|
2012-07-05 20:34:20 +00:00
|
|
|
|
2013-03-13 17:05:30 +00:00
|
|
|
{- By the time this is called, the daemonstatus's currentTransfers map should
|
2012-08-29 20:30:40 +00:00
|
|
|
- already have been updated to include the transfer. -}
|
2013-03-19 22:46:29 +00:00
|
|
|
genTransfer :: Transfer -> TransferInfo -> TransferGenerator
|
|
|
|
genTransfer t info = case (transferRemote info, associatedFile info) of
|
2013-03-19 00:34:56 +00:00
|
|
|
(Just remote, Just file)
|
|
|
|
| Git.repoIsLocalUnknown (Remote.repo remote) -> do
|
|
|
|
-- optimisation for removable drives not plugged in
|
|
|
|
liftAnnex $ recordFailedTransfer t info
|
2012-10-30 19:39:15 +00:00
|
|
|
void $ removeTransfer t
|
2012-08-29 20:30:40 +00:00
|
|
|
return Nothing
|
2013-03-19 00:34:56 +00:00
|
|
|
| otherwise -> ifM (liftAnnex $ shouldTransfer t info)
|
|
|
|
( do
|
|
|
|
debug [ "Transferring:" , describeTransfer t info ]
|
|
|
|
notifyTransfer
|
2013-03-19 22:46:29 +00:00
|
|
|
return $ Just (t, info, go remote file)
|
2013-03-19 00:34:56 +00:00
|
|
|
, do
|
|
|
|
debug [ "Skipping unnecessary transfer:",
|
|
|
|
describeTransfer t info ]
|
|
|
|
void $ removeTransfer t
|
|
|
|
finishedTransfer t (Just info)
|
|
|
|
return Nothing
|
|
|
|
)
|
2012-08-29 20:30:40 +00:00
|
|
|
_ -> return Nothing
|
2012-10-29 18:07:12 +00:00
|
|
|
where
|
|
|
|
direction = transferDirection t
|
|
|
|
isdownload = direction == Download
|
2012-07-07 16:50:20 +00:00
|
|
|
|
2013-03-19 22:46:29 +00:00
|
|
|
{- Alerts are only shown for successful transfers.
|
|
|
|
- Transfers can temporarily fail for many reasons,
|
|
|
|
- so there's no point in bothering the user about
|
|
|
|
- those. The assistant should recover.
|
|
|
|
-
|
|
|
|
- After a successful upload, handle dropping it from
|
|
|
|
- here, if desired. In this case, the remote it was
|
|
|
|
- uploaded to is known to have it.
|
|
|
|
-
|
|
|
|
- Also, after a successful transfer, the location
|
|
|
|
- log has changed. Indicate that a commit has been
|
|
|
|
- made, in order to queue a push of the git-annex
|
|
|
|
- branch out to remotes that did not participate
|
|
|
|
- in the transfer.
|
|
|
|
-
|
|
|
|
- If the process failed, it could have crashed,
|
|
|
|
- so remove the transfer from the list of current
|
|
|
|
- transfers, just in case it didn't stop
|
|
|
|
- in a way that lets the TransferWatcher do its
|
2013-03-28 19:16:45 +00:00
|
|
|
- usual cleanup. However, first check if something else is
|
|
|
|
- running the transfer, to avoid removing active transfers.
|
2013-03-19 22:46:29 +00:00
|
|
|
-}
|
|
|
|
go remote file transferrer = ifM (liftIO $ performTransfer transferrer t $ associatedFile info)
|
|
|
|
( do
|
|
|
|
void $ addAlert $ makeAlertFiller True $
|
|
|
|
transferFileAlert direction True file
|
|
|
|
unless isdownload $
|
|
|
|
handleDrops
|
|
|
|
("object uploaded to " ++ show remote)
|
|
|
|
True (transferKey t)
|
|
|
|
(associatedFile info)
|
|
|
|
(Just remote)
|
|
|
|
void $ recordCommit
|
2013-03-28 19:16:45 +00:00
|
|
|
, whenM (liftAnnex $ isNothing <$> checkTransfer t) $
|
|
|
|
void $ removeTransfer t
|
2013-03-19 22:46:29 +00:00
|
|
|
)
|
2012-08-29 20:30:40 +00:00
|
|
|
|
2013-03-13 17:36:02 +00:00
|
|
|
{- Called right before a transfer begins, this is a last chance to avoid
|
|
|
|
- unnecessary transfers.
|
|
|
|
-
|
|
|
|
- For downloads, we obviously don't need to download if the already
|
|
|
|
- have the object.
|
|
|
|
-
|
|
|
|
- Smilarly, for uploads, check if the remote is known to already have
|
|
|
|
- the object.
|
|
|
|
-
|
|
|
|
- Also, uploads get queued to all remotes, in order of cost.
|
|
|
|
- This may mean, for example, that an object is uploaded over the LAN
|
|
|
|
- to a locally paired client, and once that upload is done, a more
|
|
|
|
- expensive transfer remote no longer wants the object. (Since
|
|
|
|
- all the clients have it already.) So do one last check if this is still
|
|
|
|
- preferred content.
|
|
|
|
-
|
|
|
|
- We'll also do one last preferred content check for downloads. An
|
|
|
|
- example of a case where this could be needed is if a download is queued
|
|
|
|
- for a file that gets moved out of an archive directory -- but before
|
|
|
|
- that download can happen, the file is put back in the archive.
|
|
|
|
-}
|
2012-08-29 20:30:40 +00:00
|
|
|
shouldTransfer :: Transfer -> TransferInfo -> Annex Bool
|
|
|
|
shouldTransfer t info
|
|
|
|
| transferDirection t == Download =
|
2013-03-13 17:36:02 +00:00
|
|
|
(not <$> inAnnex key) <&&> wantGet True file
|
|
|
|
| transferDirection t == Upload = case transferRemote info of
|
|
|
|
Nothing -> return False
|
|
|
|
Just r -> notinremote r
|
|
|
|
<&&> wantSend True file (Remote.uuid r)
|
2012-08-29 20:30:40 +00:00
|
|
|
| otherwise = return False
|
2012-10-31 06:34:03 +00:00
|
|
|
where
|
|
|
|
key = transferKey t
|
2013-03-13 17:36:02 +00:00
|
|
|
file = associatedFile info
|
|
|
|
|
|
|
|
{- Trust the location log to check if the remote already has
|
|
|
|
- the key. This avoids a roundtrip to the remote. -}
|
|
|
|
notinremote r = notElem (Remote.uuid r) <$> loggedLocations key
|