mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-20 11:32:19 +00:00
init:store
This commit is contained in:
+57
-5
@@ -1,7 +1,8 @@
|
||||
use futures::future::join_all;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
disk::{self, DiskAPI, DiskOption},
|
||||
disk::{self, DiskAPI, DiskError, DiskOption, FORMAT_CONFIG_FILE, RUSTFS_META_BUCKET},
|
||||
disks_layout::DisksLayout,
|
||||
endpoint::create_server_endpoints,
|
||||
format::FormatV3,
|
||||
@@ -43,13 +44,64 @@ impl ECStore {
|
||||
})
|
||||
}
|
||||
|
||||
async fn load_formats(
|
||||
disks: Vec<Option<impl DiskAPI>>,
|
||||
heal: bool,
|
||||
) -> (Vec<FormatV3>, Vec<Error>) {
|
||||
async fn init_format(disks: Vec<Option<impl DiskAPI>>) -> Result<FormatV3, Error> {
|
||||
let (formats, errs) = Self::load_format_all(&disks, false).await;
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
async fn load_format_all(
|
||||
disks: &Vec<Option<impl DiskAPI>>,
|
||||
heal: bool,
|
||||
) -> (Vec<Option<FormatV3>>, Vec<Option<Error>>) {
|
||||
let mut futures = Vec::with_capacity(disks.len());
|
||||
|
||||
for ep in disks.iter() {
|
||||
futures.push(Self::load_format(ep, heal));
|
||||
}
|
||||
|
||||
let mut datas = Vec::with_capacity(disks.len());
|
||||
let mut errors = Vec::with_capacity(disks.len());
|
||||
|
||||
let results = join_all(futures).await;
|
||||
for result in results {
|
||||
match result {
|
||||
Ok(s) => {
|
||||
datas.push(Some(s));
|
||||
errors.push(None);
|
||||
}
|
||||
Err(e) => {
|
||||
datas.push(None);
|
||||
errors.push(Some(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(datas, errors)
|
||||
}
|
||||
|
||||
async fn load_format(disk: &Option<impl DiskAPI>, heal: bool) -> Result<FormatV3, Error> {
|
||||
if disk.is_none() {
|
||||
return Err(Error::new(DiskError::DiskNotFound));
|
||||
}
|
||||
let disk = disk.as_ref().unwrap();
|
||||
|
||||
let data = disk
|
||||
.read_all(RUSTFS_META_BUCKET, FORMAT_CONFIG_FILE)
|
||||
.await
|
||||
.map_err(|e| match &e.downcast_ref::<DiskError>() {
|
||||
Some(DiskError::FileNotFound) => Error::new(DiskError::UnformattedDisk),
|
||||
Some(DiskError::DiskNotFound) => Error::new(DiskError::UnformattedDisk),
|
||||
Some(_) => e,
|
||||
None => e,
|
||||
})?;
|
||||
|
||||
let fm = FormatV3::try_from(data.as_slice())?;
|
||||
|
||||
// TODO: heal
|
||||
|
||||
Ok(fm)
|
||||
}
|
||||
|
||||
fn default_partiy_blocks(drive: usize) -> usize {
|
||||
match drive {
|
||||
1 => 0,
|
||||
|
||||
Reference in New Issue
Block a user