Skip to content

Commit c47e6e2

Browse files
piodulwprzytula
andcommitted
iterator: introduce poll_next_page
This commit refactors the part responsible for acquiring the next page by the LegacyRowIterator to a different function. This change is a preparation necessary to support the new deserialization interface - there will be a method that can return deserialized type that borrows from the current iterator, and - for "lifetimes reasons" - acquiring the next page must be put into a separate method. Co-authored-by: Wojciech Przytuła <[email protected]>
1 parent f9ab0bc commit c47e6e2

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

scylla/src/transport/iterator.rs

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,41 +89,56 @@ impl LegacyRowIterator {
8989
mut self: Pin<&mut Self>,
9090
cx: &mut Context<'_>,
9191
) -> Poll<Option<Result<Row, QueryError>>> {
92-
let mut s = self.as_mut();
93-
94-
if s.is_current_page_exhausted() {
95-
let received_page = ready_some_ok!(Pin::new(&mut s.page_receiver).poll_recv(cx));
96-
let rows = match received_page
97-
.rows
98-
// As RowIteratorWorker manages paging itself, the paging state response
99-
// returned to the user is always NoMorePages. It used to be so before
100-
// the deserialization refactor, too.
101-
.into_legacy_rows(PagingStateResponse::NoMorePages)
102-
{
103-
Ok(rows) => rows,
104-
Err(err) => return Poll::Ready(Some(Err(err.into()))),
105-
};
106-
s.current_page = rows;
107-
s.current_row_idx = 0;
108-
109-
if let Some(tracing_id) = received_page.tracing_id {
110-
s.tracing_ids.push(tracing_id);
111-
}
92+
if self.as_ref().is_current_page_exhausted() {
93+
ready_some_ok!(self.as_mut().poll_next_page(cx));
11294
}
11395

96+
let mut s = self.as_mut();
97+
11498
let idx = s.current_row_idx;
11599
if idx < s.current_page.rows.len() {
116100
let row = mem::take(&mut s.current_page.rows[idx]);
117101
s.current_row_idx += 1;
118102
return Poll::Ready(Some(Ok(row)));
119103
}
120-
121104
// We probably got a zero-sized page
122105
// Yield, but tell that we are ready
123106
cx.waker().wake_by_ref();
124107
Poll::Pending
125108
}
126109

110+
/// Makes an attempt to acquire the next page (which may be empty).
111+
///
112+
/// On success, returns Some(Ok()).
113+
/// On failure, returns Some(Err()).
114+
/// If there are no more pages, returns None.
115+
fn poll_next_page<'r>(
116+
mut self: Pin<&'r mut Self>,
117+
cx: &mut Context<'_>,
118+
) -> Poll<Option<Result<(), QueryError>>> {
119+
let mut s = self.as_mut();
120+
121+
let received_page = ready_some_ok!(Pin::new(&mut s.page_receiver).poll_recv(cx));
122+
let rows = match received_page
123+
.rows
124+
// As RowIteratorWorker manages paging itself, the paging state response
125+
// returned to the user is always NoMorePages. It used to be so before
126+
// the deserialization refactor, too.
127+
.into_legacy_rows(PagingStateResponse::NoMorePages)
128+
{
129+
Ok(rows) => rows,
130+
Err(err) => return Poll::Ready(Some(Err(err.into()))),
131+
};
132+
s.current_page = rows;
133+
s.current_row_idx = 0;
134+
135+
if let Some(tracing_id) = received_page.tracing_id {
136+
s.tracing_ids.push(tracing_id);
137+
}
138+
139+
Poll::Ready(Some(Ok(())))
140+
}
141+
127142
/// Converts this iterator into an iterator over rows parsed as given type
128143
pub fn into_typed<RowT: FromRow>(self) -> LegacyTypedRowIterator<RowT> {
129144
LegacyTypedRowIterator {

0 commit comments

Comments
 (0)