Skip to content

Commit

Permalink
chore: Add tracing to all datastore iterators (#349)
Browse files Browse the repository at this point in the history
Fixes #347.
  • Loading branch information
joshua-spacetime authored Oct 3, 2023
1 parent ba3e21d commit 8f9ff27
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/core/src/db/datastore/locking_tx_datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ impl TxState {
}
}

#[tracing::instrument(skip_all)]
pub fn get_row_op(&self, table_id: &TableId, row_id: &RowId) -> RowState {
if let Some(true) = self.delete_tables.get(table_id).map(|set| set.contains(row_id)) {
return RowState::Delete;
Expand All @@ -290,6 +291,7 @@ impl TxState {
.unwrap_or(RowState::Absent)
}

#[tracing::instrument(skip_all)]
pub fn get_row(&self, table_id: &TableId, row_id: &RowId) -> Option<&ProductValue> {
if Some(true) == self.delete_tables.get(table_id).map(|set| set.contains(row_id)) {
return None;
Expand Down Expand Up @@ -1731,10 +1733,13 @@ enum ScanStage<'a> {

impl Iterator for Iter<'_> {
type Item = DataRef;

#[tracing::instrument(skip_all)]
fn next(&mut self) -> Option<Self::Item> {
loop {
match &mut self.stage {
ScanStage::Start => {
let _span = tracing::debug_span!("ScanStage::Start").entered();
if let Some(table) = self.inner.committed_state.tables.get(&self.table_id) {
self.stage = ScanStage::Committed {
iter: table.rows.iter(),
Expand All @@ -1747,6 +1752,7 @@ impl Iterator for Iter<'_> {
};
}
ScanStage::Committed { iter } => {
let _span = tracing::debug_span!("ScanStage::Committed").entered();
for (row_id, row) in iter {
match self
.inner
Expand Down Expand Up @@ -1779,6 +1785,7 @@ impl Iterator for Iter<'_> {
}
}
ScanStage::CurrentTx { iter } => {
let _span = tracing::debug_span!("ScanStage::CurrentTx").entered();
if let Some((id, row)) = iter.next() {
return Some(DataRef::new(id.0, row.clone()));
}
Expand All @@ -1800,6 +1807,8 @@ pub struct IndexSeekIterInner<'a> {

impl Iterator for IndexSeekIterInner<'_> {
type Item = DataRef;

#[tracing::instrument(skip_all)]
fn next(&mut self) -> Option<Self::Item> {
if let Some(row_id) = self.inserted_rows.next() {
return Some(DataRef::new(
Expand Down Expand Up @@ -1834,6 +1843,7 @@ pub struct CommittedIndexIter<'a> {
impl Iterator for CommittedIndexIter<'_> {
type Item = DataRef;

#[tracing::instrument(skip_all)]
fn next(&mut self) -> Option<Self::Item> {
if let Some(row_id) = self.committed_rows.find(|row_id| {
!self
Expand All @@ -1851,6 +1861,7 @@ impl Iterator for CommittedIndexIter<'_> {

/// Retrieve a commited row. Panics if `table_id` and `row_id` do not identify an actually
/// present row.
#[tracing::instrument(skip_all)]
fn get_committed_row(state: &CommittedState, table_id: &TableId, row_id: &RowId) -> DataRef {
DataRef::new(
row_id.0,
Expand Down Expand Up @@ -1878,6 +1889,7 @@ pub enum IterByColRange<'a, R: RangeBounds<AlgebraicValue>> {
impl<R: RangeBounds<AlgebraicValue>> Iterator for IterByColRange<'_, R> {
type Item = DataRef;

#[tracing::instrument(skip_all)]
fn next(&mut self) -> Option<Self::Item> {
match self {
IterByColRange::Scan(range) => range.next(),
Expand All @@ -1896,6 +1908,7 @@ pub struct ScanIterByColRange<'a, R: RangeBounds<AlgebraicValue>> {
impl<R: RangeBounds<AlgebraicValue>> Iterator for ScanIterByColRange<'_, R> {
type Item = DataRef;

#[tracing::instrument(skip_all)]
fn next(&mut self) -> Option<Self::Item> {
for data_ref in &mut self.scan_iter {
let row = data_ref.view();
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/db/datastore/locking_tx_datastore/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl Table {
Some(row)
}

#[tracing::instrument(skip_all)]
pub(crate) fn get_row(&self, row_id: &RowId) -> Option<&ProductValue> {
self.rows.get(row_id)
}
Expand Down

0 comments on commit 8f9ff27

Please sign in to comment.