0g-storage-node/node/sync/src/controllers/mod.rs
Bo QIU 9b4b0436c3
Supports to sync partial chunks (#4)
* refactor p2p signed message

* add new pubsub messages in network layer to find chunks

* handle find chunks pubsub message in router

* Supports to sync partial chunks

* add admin rpc to sync chunks

* limit number of chunks to sync at a time

* refactor code to sync file and chunks

* add more switches to trigger file sync

* fix ut failure

* refactor code
2024-01-19 14:04:59 +08:00

50 lines
1.2 KiB
Rust

mod peers;
mod serial;
use serde::{Deserialize, Serialize};
pub use serial::{FailureReason, SerialSyncController, SyncState, MAX_CHUNKS_TO_REQUEST};
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FileSyncGoal {
/// File chunks in total.
pub num_chunks: u64,
/// Chunk index to sync from (starts from 0, inclusive).
pub index_start: u64,
/// Chunk index to sync to (exclusive).
pub index_end: u64,
}
impl FileSyncGoal {
pub fn new(num_chunks: u64, index_start: u64, index_end: u64) -> Self {
assert!(
index_start < index_end && index_end <= num_chunks,
"invalid index_end"
);
Self {
num_chunks,
index_start,
index_end,
}
}
pub fn new_file(num_chunks: u64) -> Self {
Self::new(num_chunks, 0, num_chunks)
}
pub fn is_all_chunks(&self) -> bool {
self.index_start == 0 && self.index_end == self.num_chunks
}
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FileSyncInfo {
pub elapsed_secs: u64,
pub peers: usize,
pub goal: FileSyncGoal,
pub next_chunks: u64,
pub state: String,
}