Skip to content

Commit

Permalink
Add Array::{async_}erase_metadata() and `storage::{async_}erase_met…
Browse files Browse the repository at this point in the history
…adata()`
  • Loading branch information
LDeakin committed Mar 2, 2024
1 parent 81b0e1a commit 1fe8c47
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Implement `Deserialize` for `DataType`
- A convenience for `zarrs` consumers. `ArrayMetadata` continues to use `Metadata` to parse unknown data types.
- Add `Array::{async_}erase_metadata()` and `storage::{async_}erase_metadata()`

### Fixed
- Fixed various errors in storage docs
Expand Down
10 changes: 10 additions & 0 deletions src/array/array_async_writable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ impl<TStorage: ?Sized + AsyncWritableStorageTraits + 'static> Array<TStorage> {
.await
}

/// Async variant of [`erase_metadata`](Array::erase_metadata).
#[allow(clippy::missing_errors_doc)]
pub async fn async_erase_metadata(&self) -> Result<(), StorageError> {
let storage_handle = Arc::new(StorageHandle::new(self.storage.clone()));
let storage_transformer = self
.storage_transformers()
.create_async_writable_transformer(storage_handle);
crate::storage::async_erase_metadata(&*storage_transformer, self.path()).await
}

/// Async variant of [`erase_chunk`](Array::erase_chunk).
#[allow(clippy::missing_errors_doc)]
pub async fn async_erase_chunk(&self, chunk_indices: &[u64]) -> Result<(), StorageError> {
Expand Down
14 changes: 12 additions & 2 deletions src/array/array_sync_writable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,19 @@ impl<TStorage: ?Sized + WritableStorageTraits + 'static> Array<TStorage> {
self.store_chunks_ndarray_opt(chunks, chunks_array, &CodecOptions::default())
}

/// Erase the chunk at `chunk_indices`.
/// Erase the metadata.
///
/// Succeeds if the chunk does not exist.
/// # Errors
/// Returns a [`StorageError`] if there is an underlying store error.
pub fn erase_metadata(&self) -> Result<(), StorageError> {
let storage_handle = Arc::new(StorageHandle::new(self.storage.clone()));
let storage_transformer = self
.storage_transformers()
.create_writable_transformer(storage_handle);
crate::storage::erase_metadata(&*storage_transformer, self.path())
}

/// Erase the chunk at `chunk_indices`.
///
/// # Errors
/// Returns a [`StorageError`] if there is an underlying store error.
Expand Down
18 changes: 9 additions & 9 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ pub use store_prefix::{StorePrefix, StorePrefixError, StorePrefixes};
#[cfg(feature = "async")]
pub use self::storage_async::{
async_create_array, async_create_group, async_discover_children, async_discover_nodes,
async_erase_chunk, async_erase_node, async_get_child_nodes, async_node_exists,
async_node_exists_listable, async_retrieve_chunk, async_retrieve_partial_values,
async_store_chunk, async_store_set_partial_values, AsyncListableStorageTraits,
AsyncReadableListableStorageTraits, AsyncReadableStorageTraits,
async_erase_chunk, async_erase_metadata, async_erase_node, async_get_child_nodes,
async_node_exists, async_node_exists_listable, async_retrieve_chunk,
async_retrieve_partial_values, async_store_chunk, async_store_set_partial_values,
AsyncListableStorageTraits, AsyncReadableListableStorageTraits, AsyncReadableStorageTraits,
AsyncReadableWritableListableStorageTraits, AsyncReadableWritableStorageTraits,
AsyncWritableStorageTraits,
};

pub use self::storage_sync::{
create_array, create_group, discover_children, discover_nodes, erase_chunk, erase_node,
get_child_nodes, node_exists, node_exists_listable, retrieve_chunk, retrieve_partial_values,
store_chunk, store_set_partial_values, ListableStorageTraits, ReadableListableStorageTraits,
ReadableStorageTraits, ReadableWritableListableStorageTraits, ReadableWritableStorageTraits,
WritableStorageTraits,
create_array, create_group, discover_children, discover_nodes, erase_chunk, erase_metadata,
erase_node, get_child_nodes, node_exists, node_exists_listable, retrieve_chunk,
retrieve_partial_values, store_chunk, store_set_partial_values, ListableStorageTraits,
ReadableListableStorageTraits, ReadableStorageTraits, ReadableWritableListableStorageTraits,
ReadableWritableStorageTraits, WritableStorageTraits,
};
pub use self::storage_transformer::StorageTransformerChain;

Expand Down
11 changes: 11 additions & 0 deletions src/storage/storage_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,17 @@ pub async fn async_retrieve_chunk(
.await
}

/// Asynchronously erase metadata.
///
/// # Errors
/// Returns a [`StorageError`] if there is an underlying error with the store.
pub async fn async_erase_metadata(
storage: &dyn AsyncWritableStorageTraits,
array_path: &NodePath,
) -> Result<(), StorageError> {
storage.erase(&meta_key(array_path)).await
}

/// Asynchronously erase a chunk.
///
/// # Errors
Expand Down
11 changes: 11 additions & 0 deletions src/storage/storage_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,17 @@ pub fn erase_chunk(
))
}

/// Erase metadata.
///
/// # Errors
/// Returns a [`StorageError`] if there is an underlying error with the store.
pub fn erase_metadata(
storage: &dyn WritableStorageTraits,
array_path: &NodePath,
) -> Result<(), StorageError> {
storage.erase(&meta_key(array_path))
}

/// Retrieve byte ranges from a chunk.
///
/// Returns [`None`] where keys are not found.
Expand Down

0 comments on commit 1fe8c47

Please sign in to comment.