Skip to content

Commit

Permalink
chore: add hybrid storage (#354)
Browse files Browse the repository at this point in the history
* chore: create hybrid structure

* fix: hybrid database

* lint

* chore: get removed code back

* lint
  • Loading branch information
renancloudwalk authored Mar 14, 2024
1 parent c30b327 commit d01b589
Show file tree
Hide file tree
Showing 10 changed files with 579 additions and 0 deletions.

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

9 changes: 9 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::eth::primitives::BlockNumber;
use crate::eth::primitives::BlockSelection;
#[cfg(feature = "dev")]
use crate::eth::primitives::StoragePointInTime;
use crate::eth::storage::HybridPermanentStorage;
use crate::eth::storage::InMemoryPermanentStorage;
use crate::eth::storage::InMemoryTemporaryStorage;
use crate::eth::storage::PermanentStorage;
Expand Down Expand Up @@ -335,6 +336,9 @@ pub enum StorageConfig {

#[strum(serialize = "postgres")]
Postgres { url: String },

#[strum(serialize = "hybrid")]
Hybrid { url: String },
}

impl StorageConfig {
Expand All @@ -345,6 +349,7 @@ impl StorageConfig {
let perm: Arc<dyn PermanentStorage> = match self {
Self::InMemory => Arc::new(InMemoryPermanentStorage::default()),
Self::Postgres { url } => Arc::new(Postgres::new(url, common_config.storage_max_connections, common_config.storage_acquire_timeout).await?),
Self::Hybrid { url } => Arc::new(HybridPermanentStorage::new(url).await?),
};
Ok(Arc::new(StratusStorage::new(temp, perm)))
}
Expand All @@ -357,6 +362,10 @@ impl FromStr for StorageConfig {
match s {
"inmemory" => Ok(Self::InMemory),
s if s.starts_with("postgres://") => Ok(Self::Postgres { url: s.to_string() }),
s if s.starts_with("hybrid://") => {
let s = s.replace("hybrid", "postgres"); //TODO there is a better way to do this
Ok(Self::Hybrid { url: s.to_string() })
}
s => Err(anyhow!("unknown storage: {}", s)),
}
}
Expand Down
Loading

0 comments on commit d01b589

Please sign in to comment.