Skip to content

Commit

Permalink
Serializable store, session, and repo
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiannucci committed Dec 10, 2024
1 parent 91253dc commit 455cec2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions icechunk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod storage;
pub mod store;
#[cfg(test)]
pub mod strategies;
pub mod utils;
pub mod zarr;

pub use repo::RepositoryConfig;
Expand Down
2 changes: 2 additions & 0 deletions icechunk/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
use bytes::Bytes;
use chrono::Utc;
use futures::{FutureExt, Stream, StreamExt, TryStreamExt};
use serde::{Deserialize, Serialize};
use thiserror::Error;

use crate::{
Expand Down Expand Up @@ -46,6 +47,7 @@ pub enum SessionError {

pub type SessionResult<T> = Result<T, SessionError>;

#[derive(Serialize, Deserialize)]
pub struct Session {
config: RepositoryConfig,
storage: Arc<dyn Storage + Send + Sync>,
Expand Down
6 changes: 4 additions & 2 deletions icechunk/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use crate::{
}, metadata::{
ArrayShape, ChunkKeyEncoding, ChunkShape, Codec, DataType, DimensionNames,
FillValue, StorageTransformer, UserAttributes,
}, refs::RefError, repository::{get_chunk, ChunkPayload, RepositoryError, ZarrArrayMetadata}, session::{Session, SessionError}
}, refs::RefError, repository::{get_chunk, ChunkPayload, RepositoryError, ZarrArrayMetadata}, session::{Session, SessionError},
utils::serde::arc_rwlock_serde,
};

#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
Expand Down Expand Up @@ -99,8 +100,9 @@ impl Default for StoreOptions {
}
}


#[derive(Serialize, Deserialize)]
pub struct Store {
#[serde(with = "arc_rwlock_serde")]
session: Arc<RwLock<Session>>,
config: StoreOptions,
read_only: bool,
Expand Down
1 change: 1 addition & 0 deletions icechunk/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod serde;
23 changes: 23 additions & 0 deletions icechunk/src/utils/serde.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pub mod arc_rwlock_serde {
use serde::de::Deserializer;
use serde::ser::Serializer;

Check failure on line 3 in icechunk/src/utils/serde.rs

View workflow job for this annotation

GitHub Actions / Check for spelling errors

ser ==> set
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tokio::sync::RwLock;

pub fn serialize<S, T>(val: &Arc<RwLock<T>>, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: Serialize,
{
T::serialize(&*val.blocking_read(), s)
}

pub fn deserialize<'de, D, T>(d: D) -> Result<Arc<RwLock<T>>, D::Error>
where
D: Deserializer<'de>,
T: Deserialize<'de>,
{
Ok(Arc::new(RwLock::new(T::deserialize(d)?)))
}
}

0 comments on commit 455cec2

Please sign in to comment.