-
Notifications
You must be signed in to change notification settings - Fork 18
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
Error when chunk coordinates are invalid #395
Open
emacollins
wants to merge
8
commits into
earth-mover:main
Choose a base branch
from
emacollins:invalid-chunk-coordinates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
089307a
Add chunk indices check to ZarrMetadata
emacollins 107a72c
use iter logic in ZarrArrayMetadata impl, refactor set_chunk_ref
emacollins 4804bfa
clean up and add docs
emacollins 8b03ab2
Refactor chunk coordinate validation and add unit tests for max chunk…
emacollins d566e82
fix repositroy tests
emacollins 3742bf1
small fix test_valid_chunk_coord
emacollins a2d330e
add test for set_chunk_ref with invalid coords
emacollins 9e19403
add InvalidIndex error
emacollins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -424,9 +424,24 @@ impl Repository { | |
coord: ChunkIndices, | ||
data: Option<ChunkPayload>, | ||
) -> RepositoryResult<()> { | ||
self.get_array(&path) | ||
.await | ||
.map(|node| self.change_set.set_chunk_ref(node.id, coord, data)) | ||
|
||
let node_snapshot = self.get_array(&path).await?; | ||
|
||
if let NodeData::Array(zarr_metadata, _, ) = node_snapshot.node_data { | ||
if zarr_metadata.valid_chunk_coord(&coord) { | ||
self.change_set.set_chunk_ref(node_snapshot.id, coord, data); | ||
Ok(()) | ||
} else { | ||
Err(RepositoryError::FormatError(IcechunkFormatError::ChunkCoordinatesNotFound { coords: coord })) | ||
} | ||
|
||
} else { | ||
Err(RepositoryError::NotAnArray { | ||
node: node_snapshot, | ||
message: "getting an array".to_string(), | ||
}) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can add a test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
} | ||
|
||
pub async fn get_node(&self, path: &Path) -> RepositoryResult<NodeSnapshot> { | ||
|
@@ -1574,7 +1589,11 @@ mod tests { | |
let zarr_meta = ZarrArrayMetadata { | ||
shape: vec![1, 1, 2], | ||
data_type: DataType::Float16, | ||
chunk_shape: ChunkShape(vec![NonZeroU64::new(2).unwrap()]), | ||
chunk_shape: ChunkShape(vec![ | ||
NonZeroU64::new(2).unwrap(), | ||
NonZeroU64::new(2).unwrap(), | ||
NonZeroU64::new(1).unwrap(), | ||
]), | ||
chunk_key_encoding: ChunkKeyEncoding::Slash, | ||
fill_value: FillValue::Float16(f32::NEG_INFINITY), | ||
codecs: vec![Codec { name: "mycodec".to_string(), configuration: None }], | ||
|
@@ -1820,7 +1839,7 @@ mod tests { | |
let zarr_meta = ZarrArrayMetadata { | ||
shape: vec![5, 5], | ||
data_type: DataType::Float16, | ||
chunk_shape: ChunkShape(vec![NonZeroU64::new(2).unwrap()]), | ||
chunk_shape: ChunkShape(vec![NonZeroU64::new(2).unwrap(), NonZeroU64::new(2).unwrap()]), | ||
chunk_key_encoding: ChunkKeyEncoding::Slash, | ||
fill_value: FillValue::Float16(f32::NEG_INFINITY), | ||
codecs: vec![Codec { name: "mycodec".to_string(), configuration: None }], | ||
|
@@ -1975,9 +1994,13 @@ mod tests { | |
// add a new array and retrieve its node | ||
ds.add_group(Path::root()).await?; | ||
let zarr_meta = ZarrArrayMetadata { | ||
shape: vec![1, 1, 2], | ||
shape: vec![4, 2, 4], | ||
data_type: DataType::Int32, | ||
chunk_shape: ChunkShape(vec![NonZeroU64::new(2).unwrap()]), | ||
chunk_shape: ChunkShape(vec![ | ||
NonZeroU64::new(2).unwrap(), | ||
NonZeroU64::new(1).unwrap(), | ||
NonZeroU64::new(2).unwrap() | ||
]), | ||
chunk_key_encoding: ChunkKeyEncoding::Slash, | ||
fill_value: FillValue::Int32(0), | ||
codecs: vec![Codec { name: "mycodec".to_string(), configuration: None }], | ||
|
@@ -2009,6 +2032,12 @@ mod tests { | |
Some(ChunkPayload::Inline("hello".into())), | ||
) | ||
.await?; | ||
ds.set_chunk_ref( | ||
new_array_path.clone(), | ||
ChunkIndices(vec![0, 1, 0]), | ||
Some(ChunkPayload::Inline("hello".into())), | ||
) | ||
.await?; | ||
let snapshot_id = ds.flush("commit", SnapshotProperties::default()).await?; | ||
let ds = Repository::update(Arc::clone(&storage), snapshot_id).build(); | ||
let coords = ds | ||
|
@@ -2022,7 +2051,8 @@ mod tests { | |
vec![ | ||
ChunkIndices(vec![0, 0, 0]), | ||
ChunkIndices(vec![0, 0, 1]), | ||
ChunkIndices(vec![1, 0, 0]) | ||
ChunkIndices(vec![1, 0, 0]), | ||
ChunkIndices(vec![0, 1, 0]) | ||
] | ||
.into_iter() | ||
.collect() | ||
|
@@ -2067,7 +2097,11 @@ mod tests { | |
let zarr_meta = ZarrArrayMetadata { | ||
shape: vec![1, 1, 2], | ||
data_type: DataType::Int32, | ||
chunk_shape: ChunkShape(vec![NonZeroU64::new(2).unwrap()]), | ||
chunk_shape: ChunkShape(vec![ | ||
NonZeroU64::new(2).unwrap(), | ||
NonZeroU64::new(2).unwrap(), | ||
NonZeroU64::new(2).unwrap()], | ||
), | ||
chunk_key_encoding: ChunkKeyEncoding::Slash, | ||
fill_value: FillValue::Int32(0), | ||
codecs: vec![Codec { name: "mycodec".to_string(), configuration: None }], | ||
|
@@ -2159,6 +2193,64 @@ mod tests { | |
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_setting_w_invalid_coords() -> Result<(), Box<dyn Error>> { | ||
let in_mem_storage = | ||
Arc::new(ObjectStorage::new_in_memory_store(Some("prefix".into()))); | ||
let storage: Arc<dyn Storage + Send + Sync> = in_mem_storage.clone(); | ||
let mut ds = Repository::init(Arc::clone(&storage), false).await?.build(); | ||
|
||
ds.add_group(Path::root()).await?; | ||
let zarr_meta = ZarrArrayMetadata { | ||
shape: vec![5, 5], | ||
data_type: DataType::Float16, | ||
chunk_shape: ChunkShape(vec![NonZeroU64::new(2).unwrap(), NonZeroU64::new(2).unwrap()]), | ||
chunk_key_encoding: ChunkKeyEncoding::Slash, | ||
fill_value: FillValue::Float16(f32::NEG_INFINITY), | ||
codecs: vec![Codec { name: "mycodec".to_string(), configuration: None }], | ||
storage_transformers: None, | ||
dimension_names: None, | ||
}; | ||
|
||
let apath: Path = "/array1".try_into()?; | ||
|
||
ds.add_array(apath.clone(), zarr_meta.clone()).await?; | ||
|
||
ds.commit("main", "first commit", None).await?; | ||
|
||
// add 3 chunks | ||
// First 2 chunks are valid, third will be invalid chunk indices | ||
|
||
assert!( | ||
ds.set_chunk_ref( | ||
apath.clone(), | ||
ChunkIndices(vec![0, 0]), | ||
Some(ChunkPayload::Inline("hello".into())), | ||
).await.is_ok() | ||
); | ||
assert!( | ||
ds.set_chunk_ref( | ||
apath.clone(), | ||
ChunkIndices(vec![2, 2]), | ||
Some(ChunkPayload::Inline("hello".into())), | ||
).await.is_ok() | ||
); | ||
|
||
let bad_result = ds.set_chunk_ref( | ||
apath.clone(), | ||
ChunkIndices(vec![3, 0]), | ||
Some(ChunkPayload::Inline("hello".into())), | ||
).await; | ||
|
||
match bad_result { | ||
Err(RepositoryError::FormatError(IcechunkFormatError::ChunkCoordinatesNotFound { coords })) => { | ||
assert_eq!(coords, ChunkIndices(vec![3, 0])) | ||
}, | ||
_ => panic!("Expected Chunk Coordinates Not Found Error") | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod state_machine_test { | ||
use crate::format::snapshot::NodeData; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that i think about it, this is not really a
FormatError
but a user error. This deserves a new addition toRepositoryError
, something likeInvalidIndex
or something like that.