Skip to content

Commit

Permalink
Split to experimental and normal config for tree
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Jun 21, 2024
1 parent b04fc65 commit d5068ca
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
5 changes: 5 additions & 0 deletions core/lib/protobuf_config/src/proto/config/experimental.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ message DB {
optional uint64 processing_delay_ms = 4;
optional bool include_indices_and_filters_in_block_cache = 5;
}


message SnapshotRecovery {
optional uint64 tree_recovery_parallel_persistence_buffer = 1;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
syntax = "proto3";
import "zksync/config/object_store.proto";
import "zksync/config/experimental.proto";

package zksync.config.snapshot_recovery;

message Tree {
optional uint64 chunk_size = 1;
optional uint64 parallel_persistence_buffer = 2;
}

message Postgres {
Expand All @@ -16,4 +17,6 @@ message SnapshotRecovery {
optional Postgres postgres = 2;
optional Tree tree = 3;
optional uint32 l1_batch = 4;
optional config.object_store.ObjectStore object_store = 5;
optional experimental.SnapshotRecovery experimental = 6;
}
63 changes: 36 additions & 27 deletions core/lib/protobuf_config/src/snapshot_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,6 @@ use zksync_protobuf::ProtoRepr;

use crate::{proto::snapshot_recovery as proto, read_optional_repr};

impl ProtoRepr for proto::Tree {
type Type = TreeRecoveryConfig;

fn read(&self) -> anyhow::Result<Self::Type> {
Ok(Self::Type {
chunk_size: self.chunk_size,
parallel_persistence_buffer: self
.parallel_persistence_buffer
.and_then(|a| NonZeroUsize::new(a as usize)),
})
}

fn build(this: &Self::Type) -> Self {
Self {
chunk_size: this.chunk_size,
parallel_persistence_buffer: this.parallel_persistence_buffer.map(|a| a.get() as u64),
}
}
}

impl ProtoRepr for proto::Postgres {
type Type = PostgresRecoveryConfig;

Expand All @@ -52,11 +32,29 @@ impl ProtoRepr for proto::SnapshotRecovery {
type Type = SnapshotRecoveryConfig;

fn read(&self) -> anyhow::Result<Self::Type> {
let tree = self
.tree
.as_ref()
.map(|tree| {
let chunk_size = tree.chunk_size;
let parallel_persistence_buffer = self
.experimental
.as_ref()
.and_then(|a| {
a.tree_recovery_parallel_persistence_buffer
.map(|a| NonZeroUsize::new(a as usize))
})
.flatten();
TreeRecoveryConfig {
chunk_size,
parallel_persistence_buffer,
}
})
.unwrap_or_default();

Ok(Self::Type {
enabled: self.enabled.unwrap_or_default(),
tree: read_optional_repr(&self.tree)
.context("tree")?
.unwrap_or_default(),
tree,
postgres: read_optional_repr(&self.postgres)
.context("postgres")?
.unwrap_or_default(),
Expand All @@ -65,10 +63,20 @@ impl ProtoRepr for proto::SnapshotRecovery {
}

fn build(this: &Self::Type) -> Self {
let tree = if this.tree == TreeRecoveryConfig::default() {
None
let (tree, experimental) = if this.tree == TreeRecoveryConfig::default() {
(None, None)
} else {
Some(this.tree.clone())
(
Some(proto::Tree {
chunk_size: this.tree.chunk_size,
}),
Some(crate::proto::experimental::SnapshotRecovery {
tree_recovery_parallel_persistence_buffer: this
.tree
.parallel_persistence_buffer
.map(|a| a.get() as u64),
}),
)
};
let postgres = if this.postgres == PostgresRecoveryConfig::default() {
None
Expand All @@ -78,7 +86,8 @@ impl ProtoRepr for proto::SnapshotRecovery {
Self {
enabled: Some(this.enabled),
postgres: postgres.as_ref().map(ProtoRepr::build),
tree: tree.as_ref().map(ProtoRepr::build),
tree,
experimental,
l1_batch: this.l1_batch.map(|a| a.0),
}
}
Expand Down

0 comments on commit d5068ca

Please sign in to comment.