Skip to content

Commit e251abd

Browse files
committed
print snap-id during upload error
1 parent 1ae6234 commit e251abd

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

src/upload.rs

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ pub struct SnapshotUploader {
5151
ebs_client: EbsClient,
5252
}
5353

54+
struct SnapshotPrep {
55+
snapshot_id: String,
56+
file_size: i64,
57+
block_size: i32,
58+
}
59+
5460
impl SnapshotUploader {
5561
pub fn new(ebs_client: EbsClient) -> Self {
5662
SnapshotUploader { ebs_client }
@@ -70,7 +76,36 @@ impl SnapshotUploader {
7076
description: Option<&str>,
7177
progress_bar: Option<ProgressBar>,
7278
) -> Result<String> {
73-
let path = path.as_ref();
79+
let SnapshotPrep {
80+
snapshot_id,
81+
file_size,
82+
block_size,
83+
} = self
84+
.prepare_snapshot_upload(path.as_ref(), volume_size, description)
85+
.await?;
86+
87+
self.upload_blocks_from_file(
88+
path.as_ref(),
89+
progress_bar,
90+
file_size,
91+
block_size,
92+
&snapshot_id,
93+
)
94+
.await
95+
.map_err(|e| {
96+
eprintln!("Error during upload of {}", snapshot_id);
97+
e
98+
})?;
99+
100+
Ok(snapshot_id)
101+
}
102+
103+
async fn prepare_snapshot_upload(
104+
&self,
105+
path: &Path,
106+
volume_size: Option<i64>,
107+
description: Option<&str>,
108+
) -> Result<SnapshotPrep> {
74109
let description = description.map(|s| s.to_string()).unwrap_or_else(|| {
75110
path.file_name()
76111
.unwrap_or_else(|| OsStr::new(""))
@@ -104,6 +139,20 @@ impl SnapshotUploader {
104139
// Start the snapshot, which gives us the ID and block size we need.
105140
debug!("Uploading {}G to snapshot...", volume_size);
106141
let (snapshot_id, block_size) = self.start_snapshot(volume_size, description).await?;
142+
Ok(SnapshotPrep {
143+
snapshot_id,
144+
file_size,
145+
block_size,
146+
})
147+
}
148+
async fn upload_blocks_from_file(
149+
&self,
150+
path: &Path,
151+
progress_bar: Option<ProgressBar>,
152+
file_size: i64,
153+
block_size: i32,
154+
snapshot_id: &str,
155+
) -> Result<()> {
107156
let file_blocks = (file_size + i64::from(block_size - 1)) / i64::from(block_size);
108157
let file_blocks =
109158
i32::try_from(file_blocks).with_context(|_| error::ConvertNumberSnafu {
@@ -158,7 +207,7 @@ impl SnapshotUploader {
158207
data_length,
159208
block_index: i,
160209
block_size,
161-
snapshot_id: snapshot_id.clone(),
210+
snapshot_id: snapshot_id.to_string(),
162211
changed_blocks_count: Arc::clone(&changed_blocks_count),
163212
block_digests: Arc::clone(&block_digests),
164213
block_errors: Arc::clone(&block_errors),
@@ -212,7 +261,7 @@ impl SnapshotUploader {
212261
let error_report: String = block_errors.values().map(|e| e.to_string()).collect();
213262
error::PutSnapshotBlocksSnafu {
214263
error_count: block_errors_count,
215-
snapshot_id: snapshot_id.clone(),
264+
snapshot_id,
216265
error_report,
217266
}
218267
.fail()?;
@@ -236,7 +285,7 @@ impl SnapshotUploader {
236285
self.complete_snapshot(&snapshot_id, changed_blocks_count, &full_hash)
237286
.await?;
238287

239-
Ok(snapshot_id)
288+
Ok(())
240289
}
241290

242291
/// Find the size of a file.

0 commit comments

Comments
 (0)