mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2025-04-01 14:06:10 +00:00
add api of getting available file info by root
This commit is contained in:
parent
d43a616b56
commit
9c03e796ee
@ -63,7 +63,7 @@ pub trait Rpc {
|
||||
async fn check_file_finalized(&self, tx_seq_or_root: TxSeqOrRoot) -> RpcResult<Option<bool>>;
|
||||
|
||||
#[method(name = "getFileInfo")]
|
||||
async fn get_file_info(&self, data_root: DataRoot) -> RpcResult<Option<FileInfo>>;
|
||||
async fn get_file_info(&self, data_root: DataRoot, need_available: bool) -> RpcResult<Option<FileInfo>>;
|
||||
|
||||
#[method(name = "getFileInfoByTxSeq")]
|
||||
async fn get_file_info_by_tx_seq(&self, tx_seq: u64) -> RpcResult<Option<FileInfo>>;
|
||||
|
@ -95,7 +95,7 @@ impl RpcServer for RpcServerImpl {
|
||||
let tx_seq = try_option!(
|
||||
self.ctx
|
||||
.log_store
|
||||
.get_tx_seq_by_data_root(&data_root)
|
||||
.get_tx_seq_by_data_root(&data_root, true)
|
||||
.await?
|
||||
);
|
||||
|
||||
@ -121,7 +121,7 @@ impl RpcServer for RpcServerImpl {
|
||||
) -> RpcResult<Option<SegmentWithProof>> {
|
||||
info!(%data_root, %index, "zgs_downloadSegmentWithProof");
|
||||
|
||||
let tx = try_option!(self.ctx.log_store.get_tx_by_data_root(&data_root).await?);
|
||||
let tx = try_option!(self.ctx.log_store.get_tx_by_data_root(&data_root, true).await?);
|
||||
|
||||
self.get_segment_with_proof_by_tx(tx, index).await
|
||||
}
|
||||
@ -144,7 +144,7 @@ impl RpcServer for RpcServerImpl {
|
||||
let seq = match tx_seq_or_root {
|
||||
TxSeqOrRoot::TxSeq(v) => v,
|
||||
TxSeqOrRoot::Root(v) => {
|
||||
try_option!(self.ctx.log_store.get_tx_seq_by_data_root(&v).await?)
|
||||
try_option!(self.ctx.log_store.get_tx_seq_by_data_root(&v, false).await?)
|
||||
}
|
||||
};
|
||||
|
||||
@ -163,10 +163,10 @@ impl RpcServer for RpcServerImpl {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_file_info(&self, data_root: DataRoot) -> RpcResult<Option<FileInfo>> {
|
||||
async fn get_file_info(&self, data_root: DataRoot, need_available: bool) -> RpcResult<Option<FileInfo>> {
|
||||
debug!(%data_root, "zgs_getFileInfo");
|
||||
|
||||
let tx = try_option!(self.ctx.log_store.get_tx_by_data_root(&data_root).await?);
|
||||
let tx = try_option!(self.ctx.log_store.get_tx_by_data_root(&data_root, need_available).await?);
|
||||
|
||||
Ok(Some(self.get_file_info_by_tx(tx).await?))
|
||||
}
|
||||
@ -288,7 +288,7 @@ impl RpcServerImpl {
|
||||
let maybe_tx = self
|
||||
.ctx
|
||||
.log_store
|
||||
.get_tx_by_data_root(&segment.root)
|
||||
.get_tx_by_data_root(&segment.root, false)
|
||||
.await?;
|
||||
|
||||
self.put_segment_with_maybe_tx(segment, maybe_tx).await
|
||||
|
@ -59,15 +59,15 @@ impl Store {
|
||||
delegate!(fn get_proof_at_root(root: Option<DataRoot>, index: u64, length: u64) -> Result<FlowRangeProof>);
|
||||
delegate!(fn get_context() -> Result<(DataRoot, u64)>);
|
||||
|
||||
pub async fn get_tx_seq_by_data_root(&self, data_root: &DataRoot) -> Result<Option<u64>> {
|
||||
pub async fn get_tx_seq_by_data_root(&self, data_root: &DataRoot, need_available: bool) -> Result<Option<u64>> {
|
||||
let root = *data_root;
|
||||
self.spawn(move |store| store.get_tx_seq_by_data_root(&root))
|
||||
self.spawn(move |store| store.get_tx_seq_by_data_root(&root, need_available))
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_tx_by_data_root(&self, data_root: &DataRoot) -> Result<Option<Transaction>> {
|
||||
pub async fn get_tx_by_data_root(&self, data_root: &DataRoot, need_available: bool) -> Result<Option<Transaction>> {
|
||||
let root = *data_root;
|
||||
self.spawn(move |store| store.get_tx_by_data_root(&root))
|
||||
self.spawn(move |store| store.get_tx_by_data_root(&root, need_available))
|
||||
.await
|
||||
}
|
||||
|
||||
|
@ -511,7 +511,7 @@ impl LogStoreChunkRead for LogManager {
|
||||
index_start: usize,
|
||||
index_end: usize,
|
||||
) -> crate::error::Result<Option<ChunkArray>> {
|
||||
let tx_seq = try_option!(self.get_tx_seq_by_data_root(data_root)?);
|
||||
let tx_seq = try_option!(self.get_tx_seq_by_data_root(data_root, false)?);
|
||||
self.get_chunks_by_tx_and_index_range(tx_seq, index_start, index_end)
|
||||
}
|
||||
|
||||
@ -536,7 +536,7 @@ impl LogStoreRead for LogManager {
|
||||
self.tx_store.get_tx_by_seq_number(seq)
|
||||
}
|
||||
|
||||
fn get_tx_seq_by_data_root(&self, data_root: &DataRoot) -> crate::error::Result<Option<u64>> {
|
||||
fn get_tx_seq_by_data_root(&self, data_root: &DataRoot, need_available: bool) -> crate::error::Result<Option<u64>> {
|
||||
let seq_list = self.tx_store.get_tx_seq_list_by_data_root(data_root)?;
|
||||
for tx_seq in &seq_list {
|
||||
if self.tx_store.check_tx_completed(*tx_seq)? {
|
||||
@ -544,6 +544,9 @@ impl LogStoreRead for LogManager {
|
||||
return Ok(Some(*tx_seq));
|
||||
}
|
||||
}
|
||||
if need_available {
|
||||
return Ok(None);
|
||||
}
|
||||
// No tx is finalized, return the first one.
|
||||
Ok(seq_list.first().cloned())
|
||||
}
|
||||
|
@ -31,14 +31,14 @@ pub trait LogStoreRead: LogStoreChunkRead {
|
||||
fn get_tx_by_seq_number(&self, seq: u64) -> Result<Option<Transaction>>;
|
||||
|
||||
/// Get a transaction by the data root of its data.
|
||||
/// If all txs are not finalized, return the first one.
|
||||
/// If all txs are not finalized, return the first one if need available is false.
|
||||
/// Otherwise, return the first finalized tx.
|
||||
fn get_tx_seq_by_data_root(&self, data_root: &DataRoot) -> Result<Option<u64>>;
|
||||
fn get_tx_seq_by_data_root(&self, data_root: &DataRoot, need_available: bool) -> Result<Option<u64>>;
|
||||
|
||||
/// If all txs are not finalized, return the first one.
|
||||
/// If all txs are not finalized, return the first one if need available is false.
|
||||
/// Otherwise, return the first finalized tx.
|
||||
fn get_tx_by_data_root(&self, data_root: &DataRoot) -> Result<Option<Transaction>> {
|
||||
match self.get_tx_seq_by_data_root(data_root)? {
|
||||
fn get_tx_by_data_root(&self, data_root: &DataRoot, need_available: bool) -> Result<Option<Transaction>> {
|
||||
match self.get_tx_seq_by_data_root(data_root, need_available)? {
|
||||
Some(seq) => self.get_tx_by_seq_number(seq),
|
||||
None => Ok(None),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user