Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 8720d2e

Browse files
committed
deduplicate read_change_counter
1 parent 43d035f commit 8720d2e

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

bottomless/src/replicator.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,9 @@ impl Replicator {
607607
return Ok(());
608608
}
609609
tracing::debug!("Snapshotting {}", self.db_path);
610-
let change_counter = match self.use_compression {
610+
611+
let mut reader = tokio::fs::File::open(&self.db_path).await?;
612+
match self.use_compression {
611613
CompressionKind::None => {
612614
self.client
613615
.put_object()
@@ -616,11 +618,8 @@ impl Replicator {
616618
.body(ByteStream::from_path(&self.db_path).await?)
617619
.send()
618620
.await?;
619-
let mut reader = tokio::fs::File::open(&self.db_path).await?;
620-
Self::read_change_counter(&mut reader).await?
621621
}
622622
CompressionKind::Gzip => {
623-
let mut reader = tokio::fs::File::open(&self.db_path).await?;
624623
let buf_reader = tokio::io::BufReader::new(reader.try_clone().await?);
625624
let gzip_reader = async_compression::tokio::bufread::GzipEncoder::new(buf_reader);
626625

@@ -630,8 +629,6 @@ impl Replicator {
630629
// the whole snapshot in memory because S3 requires the `Content-Length` header
631630
// to be set.
632631
upload_s3_multipart(&self.client, &key, &self.bucket, gzip_reader).await?;
633-
634-
Self::read_change_counter(&mut reader).await?
635632
}
636633
};
637634

@@ -641,6 +638,7 @@ impl Replicator {
641638
** incremented on each transaction in WAL mode."
642639
** Instead, we need to consult WAL checksums.
643640
*/
641+
let change_counter = Self::read_change_counter(&mut reader).await?;
644642
let change_counter_key = format!("{}-{}/.changecounter", self.db_name, self.generation);
645643
self.client
646644
.put_object()

0 commit comments

Comments
 (0)