MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / scan

Method scan

src/persist/src/postgres.rs:623–654  ·  view source on GitHub ↗
(
        &self,
        key: &str,
        from: SeqNo,
        limit: usize,
    )

Source from the content-addressed store, hash-verified

621 }
622
623 async fn scan(
624 &self,
625 key: &str,
626 from: SeqNo,
627 limit: usize,
628 ) -> Result<Vec<VersionedData>, ExternalError> {
629 let q = "SELECT sequence_number, data FROM consensus
630 WHERE shard = $1 AND sequence_number >= $2
631 ORDER BY sequence_number ASC LIMIT $3";
632 let Ok(limit) = i64::try_from(limit) else {
633 return Err(ExternalError::from(anyhow!(
634 "limit must be [0, i64::MAX]. was: {:?}",
635 limit
636 )));
637 };
638 let rows = {
639 let client = self.get_connection().await?;
640 let statement = client.prepare_cached(q).await?;
641 pg_query_prepared(&client, &statement, &[&key, &from, &limit]).await?
642 };
643 let mut results = Vec::with_capacity(rows.len());
644
645 for row in rows {
646 let seqno: SeqNo = row.try_get("sequence_number")?;
647 let data: Vec<u8> = row.try_get("data")?;
648 results.push(VersionedData {
649 seqno,
650 data: Bytes::from(data),
651 });
652 }
653 Ok(results)
654 }
655
656 async fn truncate(&self, key: &str, seqno: SeqNo) -> Result<Option<usize>, ExternalError> {
657 // `sequence_number >= 0` keeps the seqno -1 sentinel (see `compare_and_set`); it is a no-op

Callers

nothing calls this directly

Calls 4

pg_query_preparedFunction · 0.85
get_connectionMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected