forked from ipfs-force-community/droplet
-
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 ipfs-force-community#74 from ipfs-force-community/…
…feat/dtynn/support_multiple_attached_stores Feat/dtynn/support multiple attached stores
- Loading branch information
Showing
9 changed files
with
268 additions
and
48 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
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
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,53 @@ | ||
//! manages multiple attached stores | ||
use std::collections::HashMap; | ||
|
||
use anyhow::{anyhow, Result}; | ||
|
||
use super::ObjectStore; | ||
|
||
/// manages all attached stores | ||
pub struct AttachedManager { | ||
stores: HashMap<String, Box<dyn ObjectStore>>, | ||
} | ||
|
||
impl AttachedManager { | ||
/// init AttachedManager with given stores | ||
pub fn init(attached: Vec<Box<dyn ObjectStore>>) -> Result<Self> { | ||
let mut stores = HashMap::new(); | ||
for astore in attached { | ||
if let Some(prev) = stores.insert(astore.instance(), astore) { | ||
return Err(anyhow!("duplicate instance name {}", prev.instance())); | ||
}; | ||
} | ||
|
||
Ok(AttachedManager { stores }) | ||
} | ||
|
||
/// get a named store instance | ||
pub fn get(&self, instance: &str) -> Option<&dyn ObjectStore> { | ||
self.stores.get(instance).map(|b| b.as_ref()) | ||
} | ||
|
||
/// acquire an available store for sector persistence | ||
pub fn acquire_persist( | ||
&self, | ||
_size: u64, | ||
prev_instance: Option<String>, | ||
) -> Option<&dyn ObjectStore> { | ||
if let Some(ins) = prev_instance | ||
.as_ref() | ||
.and_then(|name| self.stores.get(name)) | ||
{ | ||
if !ins.readonly() { | ||
return Some(ins.as_ref()); | ||
} | ||
}; | ||
|
||
// TODO: depends on the free space | ||
self.stores | ||
.values() | ||
.find(|s| !s.readonly()) | ||
.map(|ins| ins.as_ref()) | ||
} | ||
} |
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
Oops, something went wrong.