Skip to content

Commit

Permalink
feat: Add a flag to allow for uploading chunks from the end of the li…
Browse files Browse the repository at this point in the history
…st (#335)

This adds a flag to the uploader binary to allow for choosing whether
the upload starts from the first chunk (default) or the last chunk. This
can be handy to speed up the upload of state since once can start two
instance in parallel, one uploading from the first chunk and the other
from the last one.
  • Loading branch information
dsarlis authored Oct 8, 2024
1 parent d134b13 commit 91683a4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion bootstrap/uploader/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ struct Args {
/// The canister to upload the state to.
#[clap(long)]
canister_id: Principal,

#[clap(long, default_value_t = false)]
upload_from_end: bool,
}

#[derive(CandidType)]
Expand Down Expand Up @@ -84,7 +87,15 @@ async fn main() {

// Upload the missing chunks.
let mut reader = BufReader::new(f);
for chunk_index in missing_chunk_indices {
// Compute the chunk indices in the order they should be uploaded
// either from the beginning or from the end, depending on the
// `upload_from_end` flag.
let chunk_indices: Vec<u64> = if args.upload_from_end {
missing_chunk_indices.into_iter().rev().collect()
} else {
missing_chunk_indices.into_iter().collect()
};
for chunk_index in chunk_indices {
let offset = chunk_index * PAGE_SIZE_IN_BYTES;
let mut buf = vec![0; CHUNK_SIZE_IN_BYTES as usize];
reader
Expand Down

0 comments on commit 91683a4

Please sign in to comment.