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:
Joel Liu 2024-04-07 11:03:11 +08:00 committed by GitHub
parent b07e6e776a
commit 72e3e0a019
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 9 deletions

View File

@ -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))
}
}
}

View File

@ -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,