Skip to content

Commit

Permalink
feat(storage): remove block connections during blocks gc
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon authored and 0xdeafbeef committed Sep 2, 2024
1 parent da2ac2c commit 48a8833
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 97 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion block-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ bytes = { workspace = true }
everscale-types = { workspace = true, features = ["blake3", "rayon"] }
hex = { workspace = true }
parking_lot = { workspace = true }
smallvec = { workspace = true }
thiserror = { workspace = true }
tl-proto = { workspace = true }

Expand Down
34 changes: 0 additions & 34 deletions block-util/src/archive/entry_id.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::borrow::Borrow;
use std::hash::Hash;

use everscale_types::models::*;
use smallvec::SmallVec;

use crate::archive::proto::ArchiveEntryType;

Expand All @@ -14,8 +12,6 @@ pub struct ArchiveEntryId<T = BlockId> {
}

impl<T> ArchiveEntryId<T> {
pub const FILENAME_LEN: usize = 4 + 8 + 4 + 32 + 32 + 4;

pub fn block(block_id: T) -> Self {
Self {
block_id,
Expand All @@ -36,34 +32,4 @@ impl<T> ArchiveEntryId<T> {
ty: ArchiveEntryType::QueueDiff,
}
}

pub fn extract_type(data: &[u8]) -> Option<ArchiveEntryType> {
if data.len() < SERIALIZED_LEN {
return None;
}

ArchiveEntryType::from_byte(data[SERIALIZED_LEN - 1])
}
}

impl<I> ArchiveEntryId<I>
where
I: Borrow<BlockId>,
{
/// Constructs on-stack buffer with the serialized object
pub fn to_vec(&self) -> SmallVec<[u8; SERIALIZED_LEN]> {
let mut result = SmallVec::with_capacity(SERIALIZED_LEN);
let block_id: &BlockId = self.block_id.borrow();
let ty = self.ty as u8;

result.extend_from_slice(&block_id.shard.workchain().to_be_bytes());
result.extend_from_slice(&block_id.shard.prefix().to_be_bytes());
result.extend_from_slice(&block_id.seqno.to_be_bytes());
result.extend_from_slice(block_id.root_hash.as_slice());
result.push(ty);

result
}
}

const SERIALIZED_LEN: usize = 4 + 8 + 4 + 32 + 1;
6 changes: 6 additions & 0 deletions block-util/src/block/top_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ impl ShardHeights {
}
}

impl<const N: usize> From<[(ShardIdent, u32); N]> for ShardHeights {
fn from(value: [(ShardIdent, u32); N]) -> Self {
Self(FastHashMap::from_iter(value))
}
}

impl FromIterator<(ShardIdent, u32)> for ShardHeights {
#[inline]
fn from_iter<T: IntoIterator<Item = (ShardIdent, u32)>>(iter: T) -> Self {
Expand Down
5 changes: 5 additions & 0 deletions core/src/block_strider/subscriber/gc_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ impl GcSubscriber {
min_interval,
},
) => {
// TODO: Must be in sync with the largest possible archive size (in mc blocks).
const MIN_SAFE_DISTANCE: u32 = 100;

let safe_distance = std::cmp::max(safe_distance, MIN_SAFE_DISTANCE);

// Compute the target masterchain block seqno
let target_seqno = match tick.mc_block_id.seqno.checked_sub(safe_distance) {
// Skip GC for the first N blocks
Expand Down
1 change: 1 addition & 0 deletions storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ tycho-util = { workspace = true }
[dev-dependencies]
anyhow = { workspace = true, features = ["backtrace"] }
bytesize = { workspace = true }
rand = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true, features = ["full"] }

Expand Down
4 changes: 4 additions & 0 deletions storage/src/db/kv_db/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ impl ColumnFamilyOptions<Caches> for KeyBlocks {}
/// - Value: `Vec<u8>`
pub struct PackageEntries;

impl PackageEntries {
pub const KEY_LEN: usize = 4 + 8 + 4 + 32 + 1;
}

impl ColumnFamily for PackageEntries {
const NAME: &'static str = "package_entries";
}
Expand Down
16 changes: 9 additions & 7 deletions storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,15 @@ impl StorageBuilder {
mempool_storage,
});

spawn_metrics_loop(&inner, Duration::from_secs(5), |this| async move {
this.base_db.refresh_metrics();
if let Some(rpc_state) = this.rpc_state.as_ref() {
rpc_state.db().refresh_metrics();
}
this.mempool_storage.db.refresh_metrics();
});
if inner.config.rocksdb_enable_metrics {
spawn_metrics_loop(&inner, Duration::from_secs(5), |this| async move {
this.base_db.refresh_metrics();
if let Some(rpc_state) = this.rpc_state.as_ref() {
rpc_state.db().refresh_metrics();
}
this.mempool_storage.db.refresh_metrics();
});
}

Ok(Storage { inner })
}
Expand Down
Loading

0 comments on commit 48a8833

Please sign in to comment.