-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from eigerco/feat/41/index_storage_scaffolding
feat(): index storage scaffolding & rocksdb implementation
- Loading branch information
Showing
11 changed files
with
652 additions
and
17 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ target/ | |
|
||
# reproducible local environment | ||
.direnv | ||
|
||
# Visual Studio Code | ||
.vscode/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
authors.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license-file.workspace = true | ||
name = "polka-index" | ||
repository.workspace = true | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
ciborium = { workspace = true } | ||
cid = { workspace = true, features = ["serde"] } | ||
rocksdb = { workspace = true } | ||
serde = { workspace = true } | ||
thiserror = { workspace = true } | ||
|
||
[dev-dependencies] | ||
tempfile = { workspace = true } | ||
|
||
[lints] | ||
workspace = true |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod piecestore; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# piecestore | ||
|
||
The piecestore module is a simple encapsulation of two data stores, one for `PieceInfo` and | ||
another for `CidInfo`. |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::collections::HashMap; | ||
|
||
use cid::Cid; | ||
use rocksdb::RocksDBError; | ||
use thiserror::Error; | ||
|
||
use self::types::{BlockLocation, CidInfo, DealInfo, PieceInfo}; | ||
|
||
pub mod rocksdb; | ||
pub mod types; | ||
|
||
pub trait PieceStore { | ||
/// Implementation-specific configuration. | ||
type Config; | ||
|
||
/// Initialize a new store. | ||
fn new(config: Self::Config) -> Result<Self, PieceStoreError> | ||
where | ||
Self: Sized; | ||
|
||
/// Store [`DealInfo`] in the PieceStore with key piece [`Cid`]. | ||
fn add_deal_for_piece( | ||
&self, | ||
piece_cid: &Cid, | ||
deal_info: DealInfo, | ||
) -> Result<(), PieceStoreError>; | ||
|
||
/// Store the map of [`BlockLocation`] in the [`PieceStore`]'s [`CidInfo`] store, with | ||
/// key piece [`Cid`]. | ||
/// | ||
/// Note: If a piece block location is already present in the [`CidInfo`], it | ||
/// will be ignored. | ||
fn add_piece_block_locations( | ||
&self, | ||
piece_cid: &Cid, | ||
block_locations: &HashMap<Cid, BlockLocation>, | ||
) -> Result<(), PieceStoreError>; | ||
|
||
/// List all piece [`Cid`]s stored in the [`PieceStore`]. | ||
fn list_piece_info_keys(&self) -> Result<Vec<Cid>, PieceStoreError>; | ||
|
||
/// List all [`CidInfo`]s keys stored in the [`PieceStore`]. | ||
fn list_cid_info_keys(&self) -> Result<Vec<Cid>, PieceStoreError>; | ||
|
||
/// Retrieve the [`PieceInfo`] for a given piece [`Cid`]. | ||
fn get_piece_info(&self, cid: &Cid) -> Result<Option<PieceInfo>, PieceStoreError>; | ||
|
||
/// Retrieve the [`CidInfo`] associated with piece [`Cid`]. | ||
fn get_cid_info(&self, cid: &Cid) -> Result<Option<CidInfo>, PieceStoreError>; | ||
} | ||
|
||
/// Error that can occur when interacting with the [`PieceStore`]. | ||
#[derive(Debug, Error)] | ||
pub enum PieceStoreError { | ||
#[error("Initialization error: {0}")] | ||
Initialization(String), | ||
|
||
#[error("Deal already exists")] | ||
DealExists, | ||
|
||
#[error("Serialization error: {0}")] | ||
Serialization(String), | ||
|
||
#[error("Deserialization error: {0}")] | ||
Deserialization(String), | ||
|
||
#[error(transparent)] | ||
StoreError(#[from] RocksDBError), | ||
} |
Oops, something went wrong.