Skip to content

Commit 92bcfa0

Browse files
committed
mismi-s3: Multi-thread downloadRecursive
1 parent c3c6997 commit 92bcfa0

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

mismi-s3/src/Mismi/S3/Commands.hs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,12 @@ hoistDownloadError e =
619619
throwM $ DestinationNotDirectory f
620620
DownloadInvariant a b ->
621621
throwM $ Invariant (renderDownloadError $ DownloadInvariant a b)
622+
DownloadAws a ->
623+
throwM a
624+
DownloadRunError (WorkerError a) ->
625+
throwM a
626+
DownloadRunError (BlowUpError a) ->
627+
throwM a
622628
MultipartError (WorkerError a) ->
623629
throwM a
624630
MultipartError (BlowUpError a) ->
@@ -700,15 +706,17 @@ downloadRecursiveWithMode mode src dest = do
700706
Left _ -> pure ()
701707
Right st -> unless (isDirectory st) . left $ DownloadDestinationNotDirectory dest
702708
-- Real business starts here.
703-
addrs <- lift $ listRecursively src
704-
mapM_ drWorker addrs
709+
e <- ask
710+
bimapEitherT DownloadRunError id . void . newEitherT . liftIO $
711+
(consume (sinkQueue e (listRecursively' src)) 1 (drWorker e))
705712
where
706-
drWorker :: Address -> EitherT DownloadError AWS ()
707-
drWorker addr = do
713+
drWorker :: Env -> Address -> IO (Either DownloadError ())
714+
drWorker env addr = runEitherT . runAWST env DownloadAws $ do
708715
fpdest <- hoistMaybe (DownloadInvariant addr src) $
709716
((</>) dest) . T.unpack . unKey <$> removeCommonPrefix src addr
710717
downloadWithMode mode addr fpdest
711718

719+
712720
downloadRecursive :: Address -> FilePath -> EitherT DownloadError AWS ()
713721
downloadRecursive =
714722
downloadRecursiveWithMode Fail

mismi-s3/src/Mismi/S3/Data.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,13 @@ data DownloadError =
129129
| DownloadDestinationExists FilePath
130130
| DownloadDestinationNotDirectory FilePath
131131
| DownloadInvariant Address Address
132+
| DownloadAws Error
133+
| DownloadRunError (RunError DownloadError)
132134
| MultipartError (RunError Error)
133135
deriving Show
134136

137+
instance Exception DownloadError
138+
135139
renderDownloadError :: DownloadError -> Text
136140
renderDownloadError d =
137141
case d of
@@ -145,6 +149,10 @@ renderDownloadError d =
145149
"Remove common prefix invariant: " <>
146150
"[" <> addressToText b <> "] is not a common prefix of " <>
147151
"[" <> addressToText a <> "]"
152+
DownloadAws e ->
153+
"AWS failure during 'download': " <> renderError e
154+
DownloadRunError r ->
155+
"Download error: " <> renderRunError r renderDownloadError
148156
MultipartError r ->
149157
"Multipart download error: " <> renderRunError r renderError
150158

0 commit comments

Comments
 (0)