From d5eec5d528363c2ab6587f08ffa5ea72e7bb8a75 Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Thu, 11 May 2023 14:11:10 +0200 Subject: [PATCH] cursor: add MVCCScanCursorPosition --- core/mvcc/bindings/c/include/mvcc.h | 2 ++ core/mvcc/bindings/c/src/lib.rs | 9 ++++++++- core/mvcc/mvcc-rs/src/cursor.rs | 9 ++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/mvcc/bindings/c/include/mvcc.h b/core/mvcc/bindings/c/include/mvcc.h index 5c3a94cfc..bd6aaa4d8 100644 --- a/core/mvcc/bindings/c/include/mvcc.h +++ b/core/mvcc/bindings/c/include/mvcc.h @@ -39,6 +39,8 @@ MVCCError MVCCScanCursorRead(MVCCScanCursorRef cursor, uint8_t **value_ptr, int6 int MVCCScanCursorNext(MVCCScanCursorRef cursor); +uint64_t MVCCScanCursorPosition(MVCCScanCursorRef cursor); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/core/mvcc/bindings/c/src/lib.rs b/core/mvcc/bindings/c/src/lib.rs index 21dbe4315..16254194a 100644 --- a/core/mvcc/bindings/c/src/lib.rs +++ b/core/mvcc/bindings/c/src/lib.rs @@ -200,7 +200,7 @@ pub unsafe extern "C" fn MVCCScanCursorRead( // TODO: deduplicate with MVCCDatabaseRead() match runtime.block_on(async move { - let maybe_row = cursor.current().await?; + let maybe_row = cursor.current_row().await?; match maybe_row { Some(row) => { tracing::debug!("Found row {row:?}"); @@ -243,3 +243,10 @@ pub unsafe extern "C" fn MVCCScanCursorNext(cursor: MVCCScanCursorRef) -> std::f 0 } } + +#[no_mangle] +pub unsafe extern "C" fn MVCCScanCursorPosition(cursor: MVCCScanCursorRef) -> u64 { + let cursor_ctx = unsafe { &mut *cursor.ptr }; + let cursor = &mut cursor_ctx.cursor; + cursor.current_row_id().unwrap_or(0) +} \ No newline at end of file diff --git a/core/mvcc/mvcc-rs/src/cursor.rs b/core/mvcc/mvcc-rs/src/cursor.rs index cced5df5a..856ce1dbc 100644 --- a/core/mvcc/mvcc-rs/src/cursor.rs +++ b/core/mvcc/mvcc-rs/src/cursor.rs @@ -36,7 +36,14 @@ impl< }) } - pub async fn current(&self) -> Result> { + pub fn current_row_id(&self) -> Option { + if self.index >= self.row_ids.len() { + return None; + } + Some(self.row_ids[self.index]) + } + + pub async fn current_row(&self) -> Result> { if self.index >= self.row_ids.len() { return Ok(None); }