Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manifests shrink when there are fewer chunk references #202

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion icechunk/src/format/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use futures::{pin_mut, Stream, TryStreamExt};
use itertools::Itertools;
use std::{collections::BTreeMap, ops::Bound, sync::Arc};
use thiserror::Error;
Expand Down Expand Up @@ -136,13 +137,29 @@ impl Manifest {
}
}

pub async fn from_stream<E>(
chunks: impl Stream<Item = Result<ChunkInfo, E>>,
) -> Result<Self, E> {
let mut chunk_map = BTreeMap::new();
pin_mut!(chunks);
while let Some(chunk) = chunks.try_next().await? {
chunk_map.insert((chunk.node, chunk.coord), chunk.payload);
}
Ok(Self::new(chunk_map))
}

pub fn chunks(&self) -> &BTreeMap<(NodeId, ChunkIndices), ChunkPayload> {
&self.chunks
}

pub fn size(&self) -> usize {
pub fn len(&self) -> usize {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

self.chunks.len()
}

#[must_use]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}

impl FromIterator<ChunkInfo> for Manifest {
Expand Down
7 changes: 6 additions & 1 deletion icechunk/src/format/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,14 @@ impl Snapshot {
.map(move |ix| self.short_term_history[ix].clone())
}

pub fn size(&self) -> usize {
pub fn len(&self) -> usize {
self.nodes.len()
}

#[must_use]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}

// We need this complex dance because Rust makes it really hard to put together an object and a
Expand Down
Loading