Skip to content

Commit

Permalink
add a lighter way to check whether a block exists in the Bigtable (so…
Browse files Browse the repository at this point in the history
…lana-labs#28308)

* add does_row_key_exist

* add does_confirmed_block_exist

* lint

* Update storage-bigtable/src/bigtable.rs

Co-authored-by: Tyera Eulberg <[email protected]>

* 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 <[email protected]>

Co-authored-by: Tyera Eulberg <[email protected]>
  • Loading branch information
yihau and CriesofCarrots authored Oct 18, 2022
1 parent 5361b4b commit d949f4f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions storage-bigtable/src/bigtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions storage-bigtable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {:?}",
Expand Down

0 comments on commit d949f4f

Please sign in to comment.