Skip to content

Commit

Permalink
tweak(snapshot): export progress messages (#80)
Browse files Browse the repository at this point in the history
* tweak(snapshot): export progress messages

* chore: report total number of logs and chunks
  • Loading branch information
zeapoz authored Apr 3, 2024
1 parent 476621c commit 5f4a203
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/processor/snapshot/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ impl SnapshotExporter {
}

fn export_factory_deps(&self, header: &mut SnapshotHeader) -> Result<()> {
tracing::info!("Exporting factory dependencies...");

let mut buf = BytesMut::new();

let storage_logs = self.database.cf_handle(database::FACTORY_DEPS).unwrap();
Expand Down Expand Up @@ -101,13 +103,21 @@ impl SnapshotExporter {
encoder.write_all(&buf)?;
encoder.finish()?;

tracing::info!("All factory dependencies were successfully serialized!");
Ok(())
}

fn export_storage_logs(&self, chunk_size: u64, header: &mut SnapshotHeader) -> Result<()> {
tracing::info!("Exporting storage logs...");

let mut buf = BytesMut::new();
let mut chunk_id = 0;

let num_logs = self.database.get_last_repeated_key_index()?;
tracing::info!("Found {num_logs} logs.");

let total_num_chunks = (num_logs / chunk_size) + 1;

let index_to_key_map = self.database.cf_handle(database::INDEX_TO_KEY_MAP).unwrap();
let mut iterator = self
.database
Expand All @@ -116,6 +126,8 @@ impl SnapshotExporter {
let mut has_more = true;

while has_more {
tracing::info!("Serializing chunk {}/{}...", chunk_id + 1, total_num_chunks);

let mut chunk = protobuf::SnapshotStorageLogsChunk {
storage_logs: vec![],
};
Expand Down Expand Up @@ -151,7 +163,6 @@ impl SnapshotExporter {
"snapshot_l1_batch_{}_storage_logs_part_{:0>4}.proto.gzip",
header.l1_batch_number, chunk_id
));
chunk_id += 1;

header
.storage_logs_chunks
Expand Down Expand Up @@ -180,8 +191,12 @@ impl SnapshotExporter {

// Clear $tmp buffer.
buf.truncate(0);

tracing::info!("Chunk {} was successfully serialized!", chunk_id + 1);
chunk_id += 1;
}

tracing::info!("All storage logs were successfully serialized!");
Ok(())
}
}

0 comments on commit 5f4a203

Please sign in to comment.