Skip to content

Commit

Permalink
ref(proguard): Use existing chunked upload logic
Browse files Browse the repository at this point in the history
Use the existing chunked upload logic (already used for DIFs) when chunked-uploading Proguard mappings.

Closes #2195, #2196
  • Loading branch information
szokeasaurusrex committed Dec 18, 2024
1 parent 3fd0566 commit 086d139
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/commands/upload_proguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
})
})?;

proguard::chunk_upload(&mappings, &chunk_upload_options, &org, &project)?;
proguard::chunk_upload(&mappings, chunk_upload_options, &org, &project)?;
} else {
if mappings.is_empty() && matches.get_flag("require_one") {
println!();
Expand Down
5 changes: 4 additions & 1 deletion src/utils/chunks/upload.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{collections::BTreeMap, fmt::Display, thread, time::Instant};
use std::collections::BTreeMap;
use std::fmt::Display;
use std::thread;
use std::time::Instant;

use anyhow::Result;
use indicatif::ProgressStyle;
Expand Down
7 changes: 7 additions & 0 deletions src/utils/proguard/mapping.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::borrow::Cow;
use std::fmt::{Display, Formatter, Result as FmtResult};

use symbolic::common::{ByteView, DebugId};
use thiserror::Error;
Expand Down Expand Up @@ -76,3 +77,9 @@ impl Assemblable for ProguardMapping<'_> {
None
}
}

impl Display for ProguardMapping<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(f, "{} (Proguard mapping)", self.uuid)
}
}
62 changes: 11 additions & 51 deletions src/utils/proguard/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
//! Proguard mappings, while we work on a more permanent solution, which will
//! work for all different types of debug files.
use std::thread;
use std::time::{Duration, Instant};
use std::time::Duration;

use anyhow::Result;
use indicatif::ProgressStyle;

use crate::api::{Api, ChunkServerOptions, ChunkedFileState};
use crate::utils::chunks;
use crate::utils::chunks::Chunked;
use crate::api::ChunkServerOptions;
use crate::utils::chunks::{upload_chunked_objects, ChunkOptions, Chunked};
use crate::utils::proguard::ProguardMapping;

/// How often to poll the server for the status of the assembled mappings.
const ASSEMBLE_POLL_INTERVAL: Duration = Duration::from_secs(1);

/// How long to wait for the server to assemble the mappings before giving up.
// 120 seconds was chosen somewhat arbitrarily, but in my testing, assembly
// usually was almost instantaneous, so this should probably be enough time.
Expand All @@ -28,7 +22,7 @@ const ASSEMBLE_POLL_TIMEOUT: Duration = Duration::from_secs(120);
/// Returns an error if the mappings fail to assemble, or if the timeout is reached.
pub fn chunk_upload(
mappings: &[ProguardMapping<'_>],
chunk_upload_options: &ChunkServerOptions,
chunk_upload_options: ChunkServerOptions,
org: &str,
project: &str,
) -> Result<()> {
Expand All @@ -37,48 +31,14 @@ pub fn chunk_upload(
.map(|mapping| Chunked::from(mapping, chunk_upload_options.chunk_size as usize))
.collect::<Result<Vec<_>>>()?;

let progress_style = ProgressStyle::default_bar().template(
"Uploading Proguard mappings...\
\n{wide_bar} {bytes}/{total_bytes} ({eta})",
);

let chunks = chunked_mappings
.iter()
.flat_map(|mapping| mapping.iter_chunks());

chunks::upload_chunks(
&chunks.collect::<Vec<_>>(),
chunk_upload_options,
progress_style,
)?;
let options =
ChunkOptions::new(chunk_upload_options, org, project).with_max_wait(ASSEMBLE_POLL_TIMEOUT);

println!("Waiting for server to assemble uploaded mappings...");
let (_, has_processing_errors) = upload_chunked_objects(&chunked_mappings, options)?;

let assemble_request = chunked_mappings.iter().collect();
let start = Instant::now();
while Instant::now().duration_since(start) < ASSEMBLE_POLL_TIMEOUT {
let all_assembled = Api::current()
.authenticated()?
.assemble_difs(org, project, &assemble_request)?
.values()
.map(|response| match response.state {
ChunkedFileState::Error => anyhow::bail!("Error: {response:?}"),
ChunkedFileState::NotFound => anyhow::bail!("File not found: {response:?}"),
ChunkedFileState::Ok | ChunkedFileState::Created | ChunkedFileState::Assembling => {
Ok(response)
}
})
.collect::<Result<Vec<_>>>()?
.iter()
.all(|response| matches!(response.state, ChunkedFileState::Ok));

if all_assembled {
println!("Server finished assembling mappings.");
return Ok(());
}

thread::sleep(ASSEMBLE_POLL_INTERVAL);
if has_processing_errors {
Err(anyhow::anyhow!("Some symbols did not process correctly"))
} else {
Ok(())
}

anyhow::bail!("Timed out waiting for server to assemble uploaded mappings.")
}

0 comments on commit 086d139

Please sign in to comment.