mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2024-12-26 00:05:17 +00:00
set uploaded_seg_num in FileInfo for rpc (#36)
* set uploaded_seg_num in FileInfo for rpc * fix lint * segments is 0 when not finalized * refine code
This commit is contained in:
parent
b07e6e776a
commit
72e3e0a019
@ -336,15 +336,16 @@ impl MemoryChunkPool {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_uploaded_seg_num(&self, root: &DataRoot) -> (usize, bool) {
|
||||
pub async fn get_uploaded_seg_num(&self, root: &DataRoot) -> Option<(usize, bool)> {
|
||||
let inner = self.inner.lock().await;
|
||||
|
||||
if let Some(file) = inner.segment_cache.get_file(root) {
|
||||
(file.cached_chunk_num, true)
|
||||
} else if let Some(file) = inner.write_control.get_file(root) {
|
||||
(file.uploaded_seg_num(), false)
|
||||
Some((file.segments.len(), true))
|
||||
} else {
|
||||
(0, false)
|
||||
inner
|
||||
.write_control
|
||||
.get_file(root)
|
||||
.map(|file| (file.uploaded_seg_num(), false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -183,13 +183,28 @@ impl RpcServerImpl {
|
||||
}
|
||||
|
||||
async fn get_file_info_by_tx(&self, tx: Transaction) -> RpcResult<FileInfo> {
|
||||
let (uploaded_seg_num, is_cached) = self
|
||||
let finalized = self.ctx.log_store.check_tx_completed(tx.seq).await?;
|
||||
let (uploaded_seg_num, is_cached) = match self
|
||||
.ctx
|
||||
.chunk_pool
|
||||
.get_uploaded_seg_num(&tx.data_merkle_root)
|
||||
.await;
|
||||
|
||||
let finalized = self.ctx.log_store.check_tx_completed(tx.seq).await?;
|
||||
.await
|
||||
{
|
||||
Some(v) => v,
|
||||
_ => (
|
||||
if finalized {
|
||||
let chunks_per_segment = self.ctx.config.chunks_per_segment;
|
||||
let (num_segments, _) = SegmentWithProof::split_file_into_segments(
|
||||
tx.size as usize,
|
||||
chunks_per_segment,
|
||||
)?;
|
||||
num_segments
|
||||
} else {
|
||||
0
|
||||
},
|
||||
false,
|
||||
),
|
||||
};
|
||||
|
||||
Ok(FileInfo {
|
||||
tx,
|
||||
|
Loading…
Reference in New Issue
Block a user