Skip to content
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

mismi-s3: Multi-thread downloadRecursive #378

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 12 additions & 4 deletions mismi-s3/src/Mismi/S3/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,12 @@ hoistDownloadError e =
throwM $ DestinationNotDirectory f
DownloadInvariant a b ->
throwM $ Invariant (renderDownloadError $ DownloadInvariant a b)
DownloadAws a ->
throwM a
DownloadRunError (WorkerError a) ->
throwM a
DownloadRunError (BlowUpError a) ->
throwM a
MultipartError (WorkerError a) ->
throwM a
MultipartError (BlowUpError a) ->
Expand Down Expand Up @@ -734,15 +740,17 @@ downloadRecursiveWithMode mode src dest = do
Left _ -> pure ()
Right st -> unless (isDirectory st) . left $ DownloadDestinationNotDirectory dest
-- Real business starts here.
addrs <- lift $ listRecursively src
mapM_ drWorker addrs
e <- ask
bimapEitherT DownloadRunError id . void . newEitherT . liftIO $
(consume (sinkQueue e (listRecursively' src)) 1 (drWorker e))
where
drWorker :: Address -> EitherT DownloadError AWS ()
drWorker addr = do
drWorker :: Env -> Address -> IO (Either DownloadError ())
drWorker env addr = runEitherT . runAWST env DownloadAws $ do
fpdest <- hoistMaybe (DownloadInvariant addr src) $
((</>) dest) . T.unpack . unKey <$> removeCommonPrefix src addr
downloadWithMode mode addr fpdest


downloadRecursive :: Address -> FilePath -> EitherT DownloadError AWS ()
downloadRecursive =
downloadRecursiveWithMode Fail
Expand Down
8 changes: 8 additions & 0 deletions mismi-s3/src/Mismi/S3/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,13 @@ data DownloadError =
| DownloadDestinationExists FilePath
| DownloadDestinationNotDirectory FilePath
| DownloadInvariant Address Address
| DownloadAws Error
| DownloadRunError (RunError DownloadError)
| MultipartError (RunError Error)
deriving Show

instance Exception DownloadError

renderDownloadError :: DownloadError -> Text
renderDownloadError d =
case d of
Expand All @@ -145,6 +149,10 @@ renderDownloadError d =
"Remove common prefix invariant: " <>
"[" <> addressToText b <> "] is not a common prefix of " <>
"[" <> addressToText a <> "]"
DownloadAws e ->
"AWS failure during 'download': " <> renderError e
DownloadRunError r ->
"Download error: " <> renderRunError r renderDownloadError
MultipartError r ->
"Multipart download error: " <> renderRunError r renderError

Expand Down