add a lighter way to check whether a block exists in the Bigtable (#28308)

* add does_row_key_exist

* add does_confirmed_block_exist

* lint

* Update storage-bigtable/src/bigtable.rs

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>

* rename does_row_key_exist -> row_key_exists

* rename does_confirmed_block_exist -> confirmed_block_exists

* Update storage-bigtable/src/lib.rs

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
This commit is contained in:
Yihau Chen 2022-10-18 14:34:26 +08:00 committed by GitHub
parent 5361b4bc84
commit d949f4f42f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -458,6 +458,31 @@ impl<F: FnMut(Request<()>) -> InterceptedRequestResult> BigTable<F> {
Ok(rows.into_iter().map(|r| r.0).collect())
}
/// Check whether a row key exists in a `table`
pub async fn row_key_exists(&mut self, table_name: &str, row_key: RowKey) -> Result<bool> {
self.refresh_access_token().await;
let response = self
.client
.read_rows(ReadRowsRequest {
table_name: format!("{}{}", self.table_prefix, table_name),
app_profile_id: self.app_profile_id.clone(),
rows_limit: 1,
rows: Some(RowSet {
row_keys: vec![row_key.into_bytes()],
row_ranges: vec![],
}),
filter: Some(RowFilter {
filter: Some(row_filter::Filter::StripValueTransformer(true)),
}),
})
.await?
.into_inner();
let rows = self.decode_read_rows_response(response).await?;
Ok(!rows.is_empty())
}
/// Get latest data from `table`.
///
/// All column families are accepted, and only the latest version of each column cell will be

View File

@ -535,6 +535,22 @@ impl LedgerStorage {
})
}
/// Does the confirmed block exist in the Bigtable
pub async fn confirmed_block_exists(&self, slot: Slot) -> Result<bool> {
debug!(
"LedgerStorage::confirmed_block_exists request received: {:?}",
slot
);
inc_new_counter_debug!("storage-bigtable-query", 1);
let mut bigtable = self.connection.client();
let block_exists = bigtable
.row_key_exists("blocks", slot_to_blocks_key(slot))
.await?;
Ok(block_exists)
}
pub async fn get_signature_status(&self, signature: &Signature) -> Result<TransactionStatus> {
debug!(
"LedgerStorage::get_signature_status request received: {:?}",