Line data Source code
1 : //! Helper functions to download files from remote storage with a RemoteStorage
2 : //!
3 : //! The functions in this module retry failed operations automatically, according
4 : //! to the FAILED_DOWNLOAD_RETRIES constant.
5 :
6 : use std::collections::HashSet;
7 : use std::future::Future;
8 : use std::str::FromStr;
9 :
10 : use anyhow::{anyhow, Context};
11 : use camino::{Utf8Path, Utf8PathBuf};
12 : use pageserver_api::shard::TenantShardId;
13 : use tokio::fs::{self, File, OpenOptions};
14 : use tokio::io::{AsyncSeekExt, AsyncWriteExt};
15 : use tokio_util::io::StreamReader;
16 : use tokio_util::sync::CancellationToken;
17 : use tracing::warn;
18 : use utils::backoff;
19 :
20 : use crate::config::PageServerConf;
21 : use crate::context::RequestContext;
22 : use crate::span::debug_assert_current_span_has_tenant_and_timeline_id;
23 : use crate::tenant::remote_timeline_client::{remote_layer_path, remote_timelines_path};
24 : use crate::tenant::storage_layer::layer::local_layer_path;
25 : use crate::tenant::storage_layer::LayerName;
26 : use crate::tenant::Generation;
27 : use crate::virtual_file::{on_fatal_io_error, MaybeFatalIo, VirtualFile};
28 : use crate::TEMP_FILE_SUFFIX;
29 : use remote_storage::{DownloadError, GenericRemoteStorage, ListingMode, RemotePath};
30 : use utils::crashsafe::path_with_suffix_extension;
31 : use utils::id::{TenantId, TimelineId};
32 :
33 : use super::index::{IndexPart, LayerFileMetadata};
34 : use super::{
35 : parse_remote_index_path, remote_index_path, remote_initdb_archive_path,
36 : remote_initdb_preserved_archive_path, remote_tenant_path, FAILED_DOWNLOAD_WARN_THRESHOLD,
37 : FAILED_REMOTE_OP_RETRIES, INITDB_PATH,
38 : };
39 :
40 : ///
41 : /// If 'metadata' is given, we will validate that the downloaded file's size matches that
42 : /// in the metadata. (In the future, we might do more cross-checks, like CRC validation)
43 : ///
44 : /// Returns the size of the downloaded file.
45 : #[allow(clippy::too_many_arguments)]
46 6 : pub async fn download_layer_file<'a>(
47 6 : conf: &'static PageServerConf,
48 6 : storage: &'a GenericRemoteStorage,
49 6 : tenant_shard_id: TenantShardId,
50 6 : timeline_id: TimelineId,
51 6 : layer_file_name: &'a LayerName,
52 6 : layer_metadata: &'a LayerFileMetadata,
53 6 : cancel: &CancellationToken,
54 6 : ctx: &RequestContext,
55 6 : ) -> Result<u64, DownloadError> {
56 6 : debug_assert_current_span_has_tenant_and_timeline_id();
57 6 :
58 6 : let timeline_path = conf.timeline_path(&tenant_shard_id, &timeline_id);
59 6 : let local_path = local_layer_path(
60 6 : conf,
61 6 : &tenant_shard_id,
62 6 : &timeline_id,
63 6 : layer_file_name,
64 6 : &layer_metadata.generation,
65 6 : );
66 6 :
67 6 : let remote_path = remote_layer_path(
68 6 : &tenant_shard_id.tenant_id,
69 6 : &timeline_id,
70 6 : layer_metadata.shard,
71 6 : layer_file_name,
72 6 : layer_metadata.generation,
73 6 : );
74 6 :
75 6 : // Perform a rename inspired by durable_rename from file_utils.c.
76 6 : // The sequence:
77 6 : // write(tmp)
78 6 : // fsync(tmp)
79 6 : // rename(tmp, new)
80 6 : // fsync(new)
81 6 : // fsync(parent)
82 6 : // For more context about durable_rename check this email from postgres mailing list:
83 6 : // https://www.postgresql.org/message-id/56583BDD.9060302@2ndquadrant.com
84 6 : // If pageserver crashes the temp file will be deleted on startup and re-downloaded.
85 6 : let temp_file_path = path_with_suffix_extension(&local_path, TEMP_DOWNLOAD_EXTENSION);
86 :
87 6 : let bytes_amount = download_retry(
88 73 : || async { download_object(storage, &remote_path, &temp_file_path, cancel, ctx).await },
89 6 : &format!("download {remote_path:?}"),
90 6 : cancel,
91 6 : )
92 73 : .await?;
93 :
94 6 : let expected = layer_metadata.file_size();
95 6 : if expected != bytes_amount {
96 0 : return Err(DownloadError::Other(anyhow!(
97 0 : "According to layer file metadata should have downloaded {expected} bytes but downloaded {bytes_amount} bytes into file {temp_file_path:?}",
98 0 : )));
99 6 : }
100 6 :
101 6 : fail::fail_point!("remote-storage-download-pre-rename", |_| {
102 0 : Err(DownloadError::Other(anyhow!(
103 0 : "remote-storage-download-pre-rename failpoint triggered"
104 0 : )))
105 6 : });
106 :
107 6 : fs::rename(&temp_file_path, &local_path)
108 6 : .await
109 6 : .with_context(|| format!("rename download layer file to {local_path}"))
110 6 : .map_err(DownloadError::Other)?;
111 :
112 : // We use fatal_err() below because the after the rename above,
113 : // the in-memory state of the filesystem already has the layer file in its final place,
114 : // and subsequent pageserver code could think it's durable while it really isn't.
115 6 : let work = async move {
116 6 : let timeline_dir = VirtualFile::open(&timeline_path)
117 3 : .await
118 6 : .fatal_err("VirtualFile::open for timeline dir fsync");
119 6 : timeline_dir
120 6 : .sync_all()
121 3 : .await
122 6 : .fatal_err("VirtualFile::sync_all timeline dir");
123 6 : };
124 6 : crate::virtual_file::io_engine::get()
125 6 : .spawn_blocking_and_block_on_if_std(work)
126 9 : .await;
127 :
128 6 : tracing::debug!("download complete: {local_path}");
129 :
130 6 : Ok(bytes_amount)
131 6 : }
132 :
133 : /// Download the object `src_path` in the remote `storage` to local path `dst_path`.
134 : ///
135 : /// If Ok() is returned, the download succeeded and the inode & data have been made durable.
136 : /// (Note that the directory entry for the inode is not made durable.)
137 : /// The file size in bytes is returned.
138 : ///
139 : /// If Err() is returned, there was some error. The file at `dst_path` has been unlinked.
140 : /// The unlinking has _not_ been made durable.
141 6 : async fn download_object<'a>(
142 6 : storage: &'a GenericRemoteStorage,
143 6 : src_path: &RemotePath,
144 6 : dst_path: &Utf8PathBuf,
145 6 : cancel: &CancellationToken,
146 6 : #[cfg_attr(target_os = "macos", allow(unused_variables))] ctx: &RequestContext,
147 6 : ) -> Result<u64, DownloadError> {
148 6 : let res = match crate::virtual_file::io_engine::get() {
149 0 : crate::virtual_file::io_engine::IoEngine::NotSet => panic!("unset"),
150 : crate::virtual_file::io_engine::IoEngine::StdFs => {
151 3 : async {
152 3 : let destination_file = tokio::fs::File::create(dst_path)
153 3 : .await
154 3 : .with_context(|| format!("create a destination file for layer '{dst_path}'"))
155 3 : .map_err(DownloadError::Other)?;
156 :
157 6 : let download = storage.download(src_path, cancel).await?;
158 :
159 3 : let mut buf_writer =
160 3 : tokio::io::BufWriter::with_capacity(super::BUFFER_SIZE, destination_file);
161 3 :
162 3 : let mut reader = tokio_util::io::StreamReader::new(download.download_stream);
163 :
164 24 : let bytes_amount = tokio::io::copy_buf(&mut reader, &mut buf_writer).await?;
165 3 : buf_writer.flush().await?;
166 :
167 3 : let mut destination_file = buf_writer.into_inner();
168 3 :
169 3 : // Tokio doc here: https://docs.rs/tokio/1.17.0/tokio/fs/struct.File.html states that:
170 3 : // A file will not be closed immediately when it goes out of scope if there are any IO operations
171 3 : // that have not yet completed. To ensure that a file is closed immediately when it is dropped,
172 3 : // you should call flush before dropping it.
173 3 : //
174 3 : // From the tokio code I see that it waits for pending operations to complete. There shouldt be any because
175 3 : // we assume that `destination_file` file is fully written. I e there is no pending .write(...).await operations.
176 3 : // But for additional safety lets check/wait for any pending operations.
177 3 : destination_file
178 3 : .flush()
179 0 : .await
180 3 : .with_context(|| format!("flush source file at {dst_path}"))
181 3 : .map_err(DownloadError::Other)?;
182 :
183 : // not using sync_data because it can lose file size update
184 3 : destination_file
185 3 : .sync_all()
186 3 : .await
187 3 : .with_context(|| format!("failed to fsync source file at {dst_path}"))
188 3 : .map_err(DownloadError::Other)?;
189 :
190 3 : Ok(bytes_amount)
191 3 : }
192 36 : .await
193 : }
194 : #[cfg(target_os = "linux")]
195 : crate::virtual_file::io_engine::IoEngine::TokioEpollUring => {
196 : use crate::virtual_file::owned_buffers_io::{self, util::size_tracking_writer};
197 : use bytes::BytesMut;
198 3 : async {
199 3 : let destination_file = VirtualFile::create(dst_path)
200 3 : .await
201 3 : .with_context(|| format!("create a destination file for layer '{dst_path}'"))
202 3 : .map_err(DownloadError::Other)?;
203 :
204 6 : let mut download = storage.download(src_path, cancel).await?;
205 :
206 : // TODO: use vectored write (writev) once supported by tokio-epoll-uring.
207 : // There's chunks_vectored() on the stream.
208 3 : let (bytes_amount, destination_file) = async {
209 3 : let size_tracking = size_tracking_writer::Writer::new(destination_file);
210 3 : let mut buffered = owned_buffers_io::write::BufferedWriter::<BytesMut, _>::new(
211 3 : size_tracking,
212 3 : BytesMut::with_capacity(super::BUFFER_SIZE),
213 3 : );
214 18 : while let Some(res) =
215 21 : futures::StreamExt::next(&mut download.download_stream).await
216 : {
217 18 : let chunk = match res {
218 18 : Ok(chunk) => chunk,
219 0 : Err(e) => return Err(e),
220 : };
221 18 : buffered
222 18 : .write_buffered(tokio_epoll_uring::BoundedBuf::slice_full(chunk), ctx)
223 0 : .await?;
224 : }
225 3 : let size_tracking = buffered.flush_and_into_inner(ctx).await?;
226 3 : Ok(size_tracking.into_inner())
227 3 : }
228 24 : .await?;
229 :
230 : // not using sync_data because it can lose file size update
231 3 : destination_file
232 3 : .sync_all()
233 4 : .await
234 3 : .with_context(|| format!("failed to fsync source file at {dst_path}"))
235 3 : .map_err(DownloadError::Other)?;
236 :
237 3 : Ok(bytes_amount)
238 3 : }
239 37 : .await
240 : }
241 : };
242 :
243 : // in case the download failed, clean up
244 6 : match res {
245 6 : Ok(bytes_amount) => Ok(bytes_amount),
246 0 : Err(e) => {
247 0 : if let Err(e) = tokio::fs::remove_file(dst_path).await {
248 0 : if e.kind() != std::io::ErrorKind::NotFound {
249 0 : on_fatal_io_error(&e, &format!("Removing temporary file {dst_path}"));
250 0 : }
251 0 : }
252 0 : Err(e)
253 : }
254 : }
255 6 : }
256 :
257 : const TEMP_DOWNLOAD_EXTENSION: &str = "temp_download";
258 :
259 0 : pub(crate) fn is_temp_download_file(path: &Utf8Path) -> bool {
260 0 : let extension = path.extension();
261 0 : match extension {
262 0 : Some(TEMP_DOWNLOAD_EXTENSION) => true,
263 0 : Some(_) => false,
264 0 : None => false,
265 : }
266 0 : }
267 :
268 118 : async fn list_identifiers<T>(
269 118 : storage: &GenericRemoteStorage,
270 118 : prefix: RemotePath,
271 118 : cancel: CancellationToken,
272 118 : ) -> anyhow::Result<(HashSet<T>, HashSet<String>)>
273 118 : where
274 118 : T: FromStr + Eq + std::hash::Hash,
275 118 : {
276 118 : let listing = download_retry_forever(
277 118 : || storage.list(Some(&prefix), ListingMode::WithDelimiter, None, &cancel),
278 118 : &format!("list identifiers in prefix {prefix}"),
279 118 : &cancel,
280 118 : )
281 454 : .await?;
282 :
283 118 : let mut parsed_ids = HashSet::new();
284 118 : let mut other_prefixes = HashSet::new();
285 :
286 124 : for id_remote_storage_key in listing.prefixes {
287 6 : let object_name = id_remote_storage_key.object_name().ok_or_else(|| {
288 0 : anyhow::anyhow!("failed to get object name for key {id_remote_storage_key}")
289 6 : })?;
290 :
291 6 : match object_name.parse::<T>() {
292 6 : Ok(t) => parsed_ids.insert(t),
293 0 : Err(_) => other_prefixes.insert(object_name.to_string()),
294 : };
295 : }
296 :
297 118 : for key in listing.keys {
298 0 : let object_name = key
299 0 : .object_name()
300 0 : .ok_or_else(|| anyhow::anyhow!("object name for key {key}"))?;
301 0 : other_prefixes.insert(object_name.to_string());
302 : }
303 :
304 118 : Ok((parsed_ids, other_prefixes))
305 118 : }
306 :
307 : /// List shards of given tenant in remote storage
308 0 : pub(crate) async fn list_remote_tenant_shards(
309 0 : storage: &GenericRemoteStorage,
310 0 : tenant_id: TenantId,
311 0 : cancel: CancellationToken,
312 0 : ) -> anyhow::Result<(HashSet<TenantShardId>, HashSet<String>)> {
313 0 : let remote_path = remote_tenant_path(&TenantShardId::unsharded(tenant_id));
314 0 : list_identifiers::<TenantShardId>(storage, remote_path, cancel).await
315 0 : }
316 :
317 : /// List timelines of given tenant shard in remote storage
318 118 : pub async fn list_remote_timelines(
319 118 : storage: &GenericRemoteStorage,
320 118 : tenant_shard_id: TenantShardId,
321 118 : cancel: CancellationToken,
322 118 : ) -> anyhow::Result<(HashSet<TimelineId>, HashSet<String>)> {
323 118 : fail::fail_point!("storage-sync-list-remote-timelines", |_| {
324 0 : anyhow::bail!("storage-sync-list-remote-timelines");
325 118 : });
326 :
327 118 : let remote_path = remote_timelines_path(&tenant_shard_id).add_trailing_slash();
328 454 : list_identifiers::<TimelineId>(storage, remote_path, cancel).await
329 118 : }
330 :
331 34 : async fn do_download_index_part(
332 34 : storage: &GenericRemoteStorage,
333 34 : tenant_shard_id: &TenantShardId,
334 34 : timeline_id: &TimelineId,
335 34 : index_generation: Generation,
336 34 : cancel: &CancellationToken,
337 34 : ) -> Result<(IndexPart, Generation), DownloadError> {
338 34 : let remote_path = remote_index_path(tenant_shard_id, timeline_id, index_generation);
339 :
340 34 : let index_part_bytes = download_retry_forever(
341 34 : || async {
342 48 : let download = storage.download(&remote_path, cancel).await?;
343 34 :
344 34 : let mut bytes = Vec::new();
345 20 :
346 20 : let stream = download.download_stream;
347 20 : let mut stream = StreamReader::new(stream);
348 20 :
349 37 : tokio::io::copy_buf(&mut stream, &mut bytes).await?;
350 34 :
351 34 : Ok(bytes)
352 34 : },
353 34 : &format!("download {remote_path:?}"),
354 34 : cancel,
355 34 : )
356 85 : .await?;
357 :
358 20 : let index_part: IndexPart = serde_json::from_slice(&index_part_bytes)
359 20 : .with_context(|| format!("deserialize index part file at {remote_path:?}"))
360 20 : .map_err(DownloadError::Other)?;
361 :
362 20 : Ok((index_part, index_generation))
363 34 : }
364 :
365 : /// index_part.json objects are suffixed with a generation number, so we cannot
366 : /// directly GET the latest index part without doing some probing.
367 : ///
368 : /// In this function we probe for the most recent index in a generation <= our current generation.
369 : /// See "Finding the remote indices for timelines" in docs/rfcs/025-generation-numbers.md
370 40 : #[tracing::instrument(skip_all, fields(generation=?my_generation))]
371 : pub(crate) async fn download_index_part(
372 : storage: &GenericRemoteStorage,
373 : tenant_shard_id: &TenantShardId,
374 : timeline_id: &TimelineId,
375 : my_generation: Generation,
376 : cancel: &CancellationToken,
377 : ) -> Result<(IndexPart, Generation), DownloadError> {
378 : debug_assert_current_span_has_tenant_and_timeline_id();
379 :
380 : if my_generation.is_none() {
381 : // Operating without generations: just fetch the generation-less path
382 : return do_download_index_part(
383 : storage,
384 : tenant_shard_id,
385 : timeline_id,
386 : my_generation,
387 : cancel,
388 : )
389 : .await;
390 : }
391 :
392 : // Stale case: If we were intentionally attached in a stale generation, there may already be a remote
393 : // index in our generation.
394 : //
395 : // This is an optimization to avoid doing the listing for the general case below.
396 : let res =
397 : do_download_index_part(storage, tenant_shard_id, timeline_id, my_generation, cancel).await;
398 : match res {
399 : Ok(index_part) => {
400 : tracing::debug!(
401 : "Found index_part from current generation (this is a stale attachment)"
402 : );
403 : return Ok(index_part);
404 : }
405 : Err(DownloadError::NotFound) => {}
406 : Err(e) => return Err(e),
407 : };
408 :
409 : // Typical case: the previous generation of this tenant was running healthily, and had uploaded
410 : // and index part. We may safely start from this index without doing a listing, because:
411 : // - We checked for current generation case above
412 : // - generations > my_generation are to be ignored
413 : // - any other indices that exist would have an older generation than `previous_gen`, and
414 : // we want to find the most recent index from a previous generation.
415 : //
416 : // This is an optimization to avoid doing the listing for the general case below.
417 : let res = do_download_index_part(
418 : storage,
419 : tenant_shard_id,
420 : timeline_id,
421 : my_generation.previous(),
422 : cancel,
423 : )
424 : .await;
425 : match res {
426 : Ok(index_part) => {
427 : tracing::debug!("Found index_part from previous generation");
428 : return Ok(index_part);
429 : }
430 : Err(DownloadError::NotFound) => {
431 : tracing::debug!(
432 : "No index_part found from previous generation, falling back to listing"
433 : );
434 : }
435 : Err(e) => {
436 : return Err(e);
437 : }
438 : }
439 :
440 : // General case/fallback: if there is no index at my_generation or prev_generation, then list all index_part.json
441 : // objects, and select the highest one with a generation <= my_generation. Constructing the prefix is equivalent
442 : // to constructing a full index path with no generation, because the generation is a suffix.
443 : let index_prefix = remote_index_path(tenant_shard_id, timeline_id, Generation::none());
444 :
445 : let indices = download_retry(
446 6 : || async {
447 6 : storage
448 6 : .list(Some(&index_prefix), ListingMode::NoDelimiter, None, cancel)
449 6 : .await
450 6 : },
451 : "list index_part files",
452 : cancel,
453 : )
454 : .await?
455 : .keys;
456 :
457 : // General case logic for which index to use: the latest index whose generation
458 : // is <= our own. See "Finding the remote indices for timelines" in docs/rfcs/025-generation-numbers.md
459 : let max_previous_generation = indices
460 : .into_iter()
461 : .filter_map(parse_remote_index_path)
462 12 : .filter(|g| g <= &my_generation)
463 : .max();
464 :
465 : match max_previous_generation {
466 : Some(g) => {
467 : tracing::debug!("Found index_part in generation {g:?}");
468 : do_download_index_part(storage, tenant_shard_id, timeline_id, g, cancel).await
469 : }
470 : None => {
471 : // Migration from legacy pre-generation state: we have a generation but no prior
472 : // attached pageservers did. Try to load from a no-generation path.
473 : tracing::debug!("No index_part.json* found");
474 : do_download_index_part(
475 : storage,
476 : tenant_shard_id,
477 : timeline_id,
478 : Generation::none(),
479 : cancel,
480 : )
481 : .await
482 : }
483 : }
484 : }
485 :
486 2 : pub(crate) async fn download_initdb_tar_zst(
487 2 : conf: &'static PageServerConf,
488 2 : storage: &GenericRemoteStorage,
489 2 : tenant_shard_id: &TenantShardId,
490 2 : timeline_id: &TimelineId,
491 2 : cancel: &CancellationToken,
492 2 : ) -> Result<(Utf8PathBuf, File), DownloadError> {
493 2 : debug_assert_current_span_has_tenant_and_timeline_id();
494 2 :
495 2 : let remote_path = remote_initdb_archive_path(&tenant_shard_id.tenant_id, timeline_id);
496 2 :
497 2 : let remote_preserved_path =
498 2 : remote_initdb_preserved_archive_path(&tenant_shard_id.tenant_id, timeline_id);
499 2 :
500 2 : let timeline_path = conf.timelines_path(tenant_shard_id);
501 2 :
502 2 : if !timeline_path.exists() {
503 0 : tokio::fs::create_dir_all(&timeline_path)
504 0 : .await
505 0 : .with_context(|| format!("timeline dir creation {timeline_path}"))
506 0 : .map_err(DownloadError::Other)?;
507 2 : }
508 2 : let temp_path = timeline_path.join(format!(
509 2 : "{INITDB_PATH}.download-{timeline_id}.{TEMP_FILE_SUFFIX}"
510 2 : ));
511 :
512 2 : let file = download_retry(
513 2 : || async {
514 2 : let file = OpenOptions::new()
515 2 : .create(true)
516 2 : .truncate(true)
517 2 : .read(true)
518 2 : .write(true)
519 2 : .open(&temp_path)
520 2 : .await
521 2 : .with_context(|| format!("tempfile creation {temp_path}"))
522 2 : .map_err(DownloadError::Other)?;
523 2 :
524 4 : let download = match storage.download(&remote_path, cancel).await {
525 2 : Ok(dl) => dl,
526 2 : Err(DownloadError::NotFound) => {
527 2 : storage.download(&remote_preserved_path, cancel).await?
528 2 : }
529 2 : Err(other) => Err(other)?,
530 2 : };
531 2 : let mut download = tokio_util::io::StreamReader::new(download.download_stream);
532 2 : let mut writer = tokio::io::BufWriter::with_capacity(super::BUFFER_SIZE, file);
533 2 :
534 696 : tokio::io::copy_buf(&mut download, &mut writer).await?;
535 2 :
536 2 : let mut file = writer.into_inner();
537 2 :
538 2 : file.seek(std::io::SeekFrom::Start(0))
539 2 : .await
540 2 : .with_context(|| format!("rewinding initdb.tar.zst at: {remote_path:?}"))
541 2 : .map_err(DownloadError::Other)?;
542 2 :
543 2 : Ok(file)
544 2 : },
545 2 : &format!("download {remote_path}"),
546 2 : cancel,
547 2 : )
548 704 : .await
549 2 : .map_err(|e| {
550 : // Do a best-effort attempt at deleting the temporary file upon encountering an error.
551 : // We don't have async here nor do we want to pile on any extra errors.
552 0 : if let Err(e) = std::fs::remove_file(&temp_path) {
553 0 : if e.kind() != std::io::ErrorKind::NotFound {
554 0 : warn!("error deleting temporary file {temp_path}: {e}");
555 0 : }
556 0 : }
557 0 : e
558 2 : })?;
559 :
560 2 : Ok((temp_path, file))
561 2 : }
562 :
563 : /// Helper function to handle retries for a download operation.
564 : ///
565 : /// Remote operations can fail due to rate limits (S3), spurious network
566 : /// problems, or other external reasons. Retry FAILED_DOWNLOAD_RETRIES times,
567 : /// with backoff.
568 : ///
569 : /// (See similar logic for uploads in `perform_upload_task`)
570 14 : pub(super) async fn download_retry<T, O, F>(
571 14 : op: O,
572 14 : description: &str,
573 14 : cancel: &CancellationToken,
574 14 : ) -> Result<T, DownloadError>
575 14 : where
576 14 : O: FnMut() -> F,
577 14 : F: Future<Output = Result<T, DownloadError>>,
578 14 : {
579 14 : backoff::retry(
580 14 : op,
581 14 : DownloadError::is_permanent,
582 14 : FAILED_DOWNLOAD_WARN_THRESHOLD,
583 14 : FAILED_REMOTE_OP_RETRIES,
584 14 : description,
585 14 : cancel,
586 14 : )
587 782 : .await
588 14 : .ok_or_else(|| DownloadError::Cancelled)
589 14 : .and_then(|x| x)
590 14 : }
591 :
592 152 : async fn download_retry_forever<T, O, F>(
593 152 : op: O,
594 152 : description: &str,
595 152 : cancel: &CancellationToken,
596 152 : ) -> Result<T, DownloadError>
597 152 : where
598 152 : O: FnMut() -> F,
599 152 : F: Future<Output = Result<T, DownloadError>>,
600 152 : {
601 152 : backoff::retry(
602 152 : op,
603 152 : DownloadError::is_permanent,
604 152 : FAILED_DOWNLOAD_WARN_THRESHOLD,
605 152 : u32::MAX,
606 152 : description,
607 152 : cancel,
608 152 : )
609 539 : .await
610 152 : .ok_or_else(|| DownloadError::Cancelled)
611 152 : .and_then(|x| x)
612 152 : }
|