You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fluss.apache.org by "spoon-lz (via GitHub)" <gi...@apache.org> on 2026/10/12 08:46:10 UTC

[PR] [rust] Return decoded scan batches before later errors [fluss]

spoon-lz opened a new pull request, #4606:
URL: https://github.com/apache/fluss/pull/4606

   ### Purpose
   
   Fixes #4605.
   
   Preserve successfully decoded Arrow batches when a later batch fails to decode during the same poll.
   
   This aligns the partial-result delivery policy with Java's Arrow batch scanner and prevents subscription offsets from advancing past successful data that was never delivered to the caller.
   
   ### Brief change log
   
   - Retain a decoding error after collecting successful batches and report it on the next poll.
   - Preserve partial results both within one completed fetch and across completed fetches.
   - Report errors immediately when no successful batches are available.
   - Use existing subscription and offset checks to discard stale deferred errors.
   - Document the batch poll behavior and add regression tests.
   
   ### Tests
   
   - The same collector regression fails on the community baseline with an Arrow parse error and passes with this change.
   - Rust workspace unit-test gate: 855 tests passed.
   - Two final regression tests passed after test refactoring; the collector test covers 18 scenarios.
   - Workspace Clippy and Rustdoc with warnings denied: passed.
   - Formatting and diff checks: passed.
   
   Coverage includes immediate errors, multiple successful batches, same-fetch and cross-fetch failures, empty fetches, offset continuity, recovery, unsubscribe, and subscription offset changes.
   
   Compatibility with timestamp PR #4575 was also checked: after resolving one overlapping batch-read-loop conflict, 857 workspace tests passed. This PR does not contain timestamp changes.
   
   No live Fluss-cluster, OSS, or Python/C++ runtime integration tests were run.
   
   ### API and Format
   
   No public API signature, configuration, protocol, or storage-format changes.
   
   Arrow batch poll error ordering changes: successfully decoded batches are returned before a later decoding error. Fetch-response initialization and authorization errors remain outside this change.
   
   ### Documentation
   
   Updated the Rust `RecordBatchLogScanner::poll` API comment to describe partial-result delivery and deferred errors.
   
   ### Generative AI disclosure
   
   Yes — Codex was used to prepare the implementation, tests, and documentation.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "spoon-lz (via GitHub)" <gi...@apache.org>.
spoon-lz commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4411901680


##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -2791,6 +2813,484 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn batch_poll_returns_buffered_data_before_metadata_refresh_error() -> Result<()> {
+        let table_path = TablePath::new("db", "tbl");
+        let table_info = build_table_info(table_path.clone(), 1, 1);
+        // No servers or bootstrap address: refreshing metadata fails without network I/O.
+        let metadata = Arc::new(Metadata::new_for_test(Default::default()));
+        let rpc_client = Arc::new(RpcClient::new());
+        let admin = Arc::new(crate::client::admin::FlussAdmin::new(
+            rpc_client.clone(),
+            metadata.clone(),
+        ));
+        let inner = Arc::new(LogScannerInner::new(
+            &table_info,
+            metadata,
+            rpc_client,
+            &Config::default(),
+            None,
+            false,
+            None,
+            admin,
+        )?);
+        let scanner = RecordBatchLogScanner { inner };
+        let bucket = TableBucket::new(1, 0);
+        scanner
+            .inner
+            .log_scanner_status
+            .assign_scan_bucket(bucket.clone(), 0);
+        let data = build_records(&table_info, Arc::new(table_path))?;
+        let size = data.len();
+        scanner
+            .inner
+            .log_fetcher
+            .log_fetch_buffer
+            .add(Box::new(DefaultCompletedFetch::new(
+                bucket.clone(),
+                LogRecordsBatches::new(data),
+                size,
+                test_resolver(&table_info),
+                false,
+                0,
+                0,
+            )));
+
+        let batches = scanner.poll(Duration::ZERO).await?;
+        assert_eq!(batches.len(), 1);
+        assert_eq!(batches[0].bucket(), &bucket);
+        assert_eq!(batches[0].base_offset(), 0);
+        assert_eq!(batches[0].batch().num_rows(), 1);
+        assert_eq!(
+            scanner.inner.log_scanner_status.get_bucket_offset(&bucket),
+            Some(1)
+        );
+
+        // The next poll has no buffered data, so it attempts metadata refresh.
+        let error = scanner.poll(Duration::ZERO).await.unwrap_err();
+        assert!(
+            error
+                .to_string()
+                .contains("No bootstrap servers configured")
+        );
+        assert_eq!(
+            scanner.inner.log_scanner_status.get_bucket_offset(&bucket),
+            Some(1)
+        );
+        scanner.unsubscribe(0).await?;
+        assert!(scanner.poll(Duration::ZERO).await?.is_empty());
+        Ok(())
+    }
+
+    #[tokio::test]
+    async fn collect_batches_preserves_pending_fetch_errors() -> Result<()> {
+        for (preceding_data, subscription_change) in [(false, 0), (true, 0), (true, 1), (true, 2)] {
+            for same_bucket in [false, true] {
+                for cancelled in [false, true] {
+                    check_pending_fetch_error(
+                        preceding_data,
+                        same_bucket,
+                        cancelled,
+                        subscription_change,
+                    )
+                    .await?;
+                }
+            }
+        }
+        Ok(())
+    }
+
+    async fn check_pending_fetch_error(
+        preceding_data: bool,
+        same_bucket: bool,
+        cancelled: bool,
+        subscription_change: u8,
+    ) -> Result<()> {
+        use crate::client::table::remote_log::{RemoteLogDownloadFuture, RemoteLogSegment};

Review Comment:
   Done, moved the remote-log imports to the test module's imports.



##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -2791,6 +2813,484 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn batch_poll_returns_buffered_data_before_metadata_refresh_error() -> Result<()> {
+        let table_path = TablePath::new("db", "tbl");
+        let table_info = build_table_info(table_path.clone(), 1, 1);
+        // No servers or bootstrap address: refreshing metadata fails without network I/O.
+        let metadata = Arc::new(Metadata::new_for_test(Default::default()));
+        let rpc_client = Arc::new(RpcClient::new());
+        let admin = Arc::new(crate::client::admin::FlussAdmin::new(
+            rpc_client.clone(),
+            metadata.clone(),
+        ));
+        let inner = Arc::new(LogScannerInner::new(
+            &table_info,
+            metadata,
+            rpc_client,
+            &Config::default(),
+            None,
+            false,
+            None,
+            admin,
+        )?);
+        let scanner = RecordBatchLogScanner { inner };
+        let bucket = TableBucket::new(1, 0);
+        scanner
+            .inner
+            .log_scanner_status
+            .assign_scan_bucket(bucket.clone(), 0);
+        let data = build_records(&table_info, Arc::new(table_path))?;
+        let size = data.len();
+        scanner
+            .inner
+            .log_fetcher
+            .log_fetch_buffer
+            .add(Box::new(DefaultCompletedFetch::new(
+                bucket.clone(),
+                LogRecordsBatches::new(data),
+                size,
+                test_resolver(&table_info),
+                false,
+                0,
+                0,
+            )));
+
+        let batches = scanner.poll(Duration::ZERO).await?;
+        assert_eq!(batches.len(), 1);
+        assert_eq!(batches[0].bucket(), &bucket);
+        assert_eq!(batches[0].base_offset(), 0);
+        assert_eq!(batches[0].batch().num_rows(), 1);
+        assert_eq!(
+            scanner.inner.log_scanner_status.get_bucket_offset(&bucket),
+            Some(1)
+        );
+
+        // The next poll has no buffered data, so it attempts metadata refresh.
+        let error = scanner.poll(Duration::ZERO).await.unwrap_err();
+        assert!(
+            error
+                .to_string()
+                .contains("No bootstrap servers configured")
+        );
+        assert_eq!(
+            scanner.inner.log_scanner_status.get_bucket_offset(&bucket),
+            Some(1)
+        );
+        scanner.unsubscribe(0).await?;
+        assert!(scanner.poll(Duration::ZERO).await?.is_empty());
+        Ok(())
+    }
+
+    #[tokio::test]
+    async fn collect_batches_preserves_pending_fetch_errors() -> Result<()> {
+        for (preceding_data, subscription_change) in [(false, 0), (true, 0), (true, 1), (true, 2)] {
+            for same_bucket in [false, true] {
+                for cancelled in [false, true] {
+                    check_pending_fetch_error(
+                        preceding_data,
+                        same_bucket,
+                        cancelled,
+                        subscription_change,
+                    )
+                    .await?;
+                }
+            }
+        }
+        Ok(())
+    }
+
+    async fn check_pending_fetch_error(
+        preceding_data: bool,
+        same_bucket: bool,
+        cancelled: bool,
+        subscription_change: u8,
+    ) -> Result<()> {
+        use crate::client::table::remote_log::{RemoteLogDownloadFuture, RemoteLogSegment};
+
+        let table_path = TablePath::new("db", "tbl");
+        let table_info = build_table_info(table_path.clone(), 1, 2);
+        let metadata = Arc::new(Metadata::new_for_test(build_cluster_arc(&table_path, 1, 2)));
+        let status = Arc::new(LogScannerStatus::new());
+        let fetcher = LogFetcher::new(
+            table_info.clone(),
+            Arc::new(RpcClient::new()),
+            metadata.clone(),
+            status.clone(),
+            &Config::default(),
+            None,
+            false,
+            None,
+            test_scanner_metrics(&table_path),
+            test_schema_getter(&table_info, &metadata),
+        )?;
+        let data_bucket = TableBucket::new(1, 0);
+        let error_bucket = TableBucket::new(1, i32::from(!same_bucket));
+        let error_offset = if same_bucket {
+            i64::from(preceding_data)
+        } else {
+            5
+        };
+        status.assign_scan_bucket(error_bucket.clone(), error_offset);
+        if preceding_data {
+            status.assign_scan_bucket(data_bucket.clone(), 0);
+            let data = build_records(&table_info, Arc::new(table_path))?;
+            let size = data.len();
+            fetcher
+                .log_fetch_buffer
+                .add(Box::new(DefaultCompletedFetch::new(
+                    data_bucket.clone(),
+                    LogRecordsBatches::new(data),
+                    size,
+                    test_resolver(&table_info),
+                    false,
+                    0,
+                    0,
+                )));
+        }
+        let (sender, receiver) = tokio::sync::oneshot::channel();
+        let download = RemoteLogDownloadFuture::new(receiver);
+        let completed = Arc::new(tokio::sync::Notify::new());
+        let notification = completed.clone();
+        download.on_complete(move || notification.notify_one());
+        fetcher
+            .log_fetch_buffer
+            .pend(Box::new(RemotePendingFetch::new(
+                RemoteLogSegment {
+                    segment_id: "failed-download".to_string(),
+                    start_offset: 0,
+                    end_offset: 10,
+                    size_in_bytes: 0,
+                    table_bucket: error_bucket.clone(),
+                    max_timestamp: 0,
+                },
+                download,
+                0,
+                error_offset,
+                10,
+                test_resolver(&table_info),
+            )));
+        if cancelled {
+            drop(sender);
+        } else {
+            assert!(
+                sender
+                    .send(Err(Error::UnexpectedError {
+                        message: "download failed".to_string(),
+                        source: None,
+                    }))
+                    .is_ok()
+            );
+        }
+        completed.notified().await;
+        fetcher.log_fetch_buffer.try_complete(&error_bucket);
+
+        if preceding_data {
+            let batches = fetcher.collect_batches().await?;
+            assert_eq!(batches.len(), 1);
+            assert_eq!(batches[0].bucket(), &data_bucket);
+            assert_eq!(batches[0].base_offset(), 0);
+            assert_eq!(batches[0].batch().num_rows(), 1);
+            assert_eq!(status.get_bucket_offset(&data_bucket), Some(1));
+        }
+        assert_eq!(status.get_bucket_offset(&error_bucket), Some(error_offset));
+        // Subscription changes apply after an error has been deferred.
+        if preceding_data && subscription_change == 1 {
+            status.unassign_scan_buckets(std::slice::from_ref(&error_bucket));
+        } else if preceding_data && subscription_change == 2 {
+            status.update_offset(&error_bucket, error_offset + 1);
+        } else {
+            let error = fetcher.collect_batches().await.unwrap_err();
+            let expected = if cancelled {
+                "future cancelled"
+            } else {
+                "download failed"
+            };
+            assert!(matches!(error, Error::IoUnexpectedError { message, .. }
+                if message.contains(expected)));
+            assert_eq!(status.get_bucket_offset(&error_bucket), Some(error_offset));
+        }
+        assert!(fetcher.collect_batches().await?.is_empty());
+        Ok(())
+    }
+
+    #[tokio::test]
+    async fn collect_batches_preserves_data_across_schema_errors() -> Result<()> {
+        use crate::record::SCHEMA_ID_OFFSET;

Review Comment:
   Done, moved SCHEMA_ID_OFFSET to the test module's imports.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "spoon-lz (via GitHub)" <gi...@apache.org>.
spoon-lz commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4420994434


##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -1143,6 +1146,9 @@ impl LogScanner {
 // Implementation for RecordBatchLogScanner (batches mode)
 impl RecordBatchLogScanner {
     /// Poll for batches with metadata (bucket and offset information).
+    /// If a later fetch fails to initialize or decode, already decoded batches are returned first.
+    /// The error is reported by the next poll, unless the bucket is unsubscribed

Review Comment:
   Fixed. Both poll paths now refresh missing leaders in the background while returning data immediately. Refresh tasks are deduplicated, retryable after failure, and cancelled on scanner drop. Added regression coverage for recovery while another partition stays busy.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "naivedogger (via GitHub)" <gi...@apache.org>.
naivedogger commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4282773546


##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -2230,8 +2233,23 @@ impl LogFetcher {
 
                 match next_in_line {
                     Some(mut next_fetch) if !next_fetch.is_consumed() => {
-                        let fetch_result =
-                            self.fetch_batches_from_fetch(&mut next_fetch, batches_remaining)?;
+                        if !result.is_empty() && next_fetch.has_pending_error() {
+                            self.log_fetch_buffer
+                                .set_next_in_line_fetch(Some(next_fetch));
+                            return Ok(result);
+                        }
+                        let fetch_result = match self
+                            .fetch_batches_from_fetch(&mut next_fetch, batches_remaining)
+                        {
+                            Ok(fetch_result) => fetch_result,
+                            Err(error) if !result.is_empty() => {
+                                next_fetch.defer_error(error);

Review Comment:
   If a valid batch from bucket A is followed by an authorization error from bucket B, [the initialization error branch](https://github.com/apache/fluss/blob/cbaf15770e0209ce2aede535e16597d588a492c2/fluss-rust/crates/fluss/src/client/table/scanner.rs#L2304) returns an error after A's offset has advanced, without delivering A's batch. Could we return the collected batches first, retain the error for the next poll, and add a regression test for this path?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "spoon-lz (via GitHub)" <gi...@apache.org>.
spoon-lz commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4420994434


##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -1143,6 +1146,9 @@ impl LogScanner {
 // Implementation for RecordBatchLogScanner (batches mode)
 impl RecordBatchLogScanner {
     /// Poll for batches with metadata (bucket and offset information).
+    /// If a later fetch fails to initialize or decode, already decoded batches are returned first.
+    /// The error is reported by the next poll, unless the bucket is unsubscribed

Review Comment:
   Fixed. Both poll paths now refresh missing leaders in the background while returning data immediately. Refresh tasks are deduplicated, retryable after failure, and cancelled on scanner drop. Added regression coverage for recovery while another partition stays busy.



##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -1143,6 +1146,9 @@ impl LogScanner {
 // Implementation for RecordBatchLogScanner (batches mode)
 impl RecordBatchLogScanner {
     /// Poll for batches with metadata (bucket and offset information).
+    /// If a later fetch fails to initialize or decode, already decoded batches are returned first.
+    /// The error is reported by the next poll, unless the bucket is unsubscribed

Review Comment:
   Agreed. Let's track this separately for both Java and Rust: expose structured bucket/offset information and, where reliably available, the offset after the failed batch. Offset + 1 is not sufficient for multi-record batches. I'll keep this out of the current PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "spoon-lz (via GitHub)" <gi...@apache.org>.
spoon-lz commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4322298184


##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -2230,8 +2233,23 @@ impl LogFetcher {
 
                 match next_in_line {
                     Some(mut next_fetch) if !next_fetch.is_consumed() => {
-                        let fetch_result =
-                            self.fetch_batches_from_fetch(&mut next_fetch, batches_remaining)?;
+                        if !result.is_empty() && next_fetch.has_pending_error() {
+                            self.log_fetch_buffer
+                                .set_next_in_line_fetch(Some(next_fetch));
+                            return Ok(result);
+                        }
+                        let fetch_result = match self
+                            .fetch_batches_from_fetch(&mut next_fetch, batches_remaining)
+                        {
+                            Ok(fetch_result) => fetch_result,
+                            Err(error) if !result.is_empty() => {
+                                next_fetch.defer_error(error);

Review Comment:
   Fixed by preserving the original fetch offset when a pending fetch fails. Added regression tests verifying that valid batches are returned first and the download error is reported on the next poll.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "fresh-borzoni (via GitHub)" <gi...@apache.org>.
fresh-borzoni commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4414398782


##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -712,7 +712,7 @@ impl LogScannerInner {
             if !fetch_result.is_empty() {
                 // We have data, send next round of fetches and return
                 // This enables pipelining while user processes the data
-                self.log_fetcher.send_fetches().await?;
+                self.log_fetcher.send_fetches_without_metadata_refresh();

Review Comment:
   My earlier suggestion broke something here. On a partitioned table, if a's leader moves to another server (say, during a rebalance), the client forgets where a lives. Data polls don't refresh metadata anymore, so a gets nothing until the other partitions run out of data.
   
   Shall we start the refresh in the background when a bucket has no leader, here and at :1064?



##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -1143,6 +1146,9 @@ impl LogScanner {
 // Implementation for RecordBatchLogScanner (batches mode)
 impl RecordBatchLogScanner {
     /// Poll for batches with metadata (bucket and offset information).
+    /// If a later fetch fails to initialize or decode, already decoded batches are returned first.
+    /// The error is reported by the next poll, unless the bucket is unsubscribed

Review Comment:
   In order to get past a bad batch, callers have to parse the bucket and offset out of the message. Kafka returns RecordDeserializationException with topicPartition() and offset() for this. 
   Since we decode whole batches, our error would also need the offset after the bad batch, because offset + 1 lands in the same batch. That needs Java too, so a follow-up issue for both clients?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "spoon-lz (via GitHub)" <gi...@apache.org>.
spoon-lz commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4420997224


##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -712,7 +712,7 @@ impl LogScannerInner {
             if !fetch_result.is_empty() {
                 // We have data, send next round of fetches and return
                 // This enables pipelining while user processes the data
-                self.log_fetcher.send_fetches().await?;
+                self.log_fetcher.send_fetches_without_metadata_refresh();

Review Comment:
   Fixed. Both poll paths now refresh missing leaders in the background while returning data immediately. Refresh tasks are deduplicated, retryable after failure, and cancelled on scanner drop. Added regression coverage for recovery while another partition stays busy.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "naivedogger (via GitHub)" <gi...@apache.org>.
naivedogger commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4282773546


##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -2230,8 +2233,23 @@ impl LogFetcher {
 
                 match next_in_line {
                     Some(mut next_fetch) if !next_fetch.is_consumed() => {
-                        let fetch_result =
-                            self.fetch_batches_from_fetch(&mut next_fetch, batches_remaining)?;
+                        if !result.is_empty() && next_fetch.has_pending_error() {
+                            self.log_fetch_buffer
+                                .set_next_in_line_fetch(Some(next_fetch));
+                            return Ok(result);
+                        }
+                        let fetch_result = match self
+                            .fetch_batches_from_fetch(&mut next_fetch, batches_remaining)
+                        {
+                            Ok(fetch_result) => fetch_result,
+                            Err(error) if !result.is_empty() => {
+                                next_fetch.defer_error(error);

Review Comment:
   Could we preserve partial results for initialization errors too? I reproduced a valid batch from bucket A followed by an authorization error from bucket B: [the initialization error branch](https://github.com/apache/fluss/blob/cbaf15770e0209ce2aede535e16597d588a492c2/fluss-rust/crates/fluss/src/client/table/scanner.rs#L2304) returns an error after A's offset has advanced, without delivering A's batch. Please return the collected batches first and retain the error for the next poll, with a regression test covering this path.



##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -2791,6 +2810,132 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn collect_batches_preserves_partial_results_and_error_order() -> Result<()> {
+        // Cover failures within one fetch and in the next fetch, including no preceding data.
+        let cases = [
+            (false, 0, 0),
+            (false, 0, 1),
+            (false, 0, 2),
+            (false, 1, 0),
+            (false, 1, 1),
+            (false, 1, 2),
+            (false, 2, 0),
+            (false, 2, 1),
+            (false, 2, 2),
+            (true, 0, 0),
+            (true, 0, 1),
+            (true, 0, 2),
+            (true, 1, 0),
+            (true, 1, 1),
+            (true, 1, 2),
+            (true, 2, 0),
+            (true, 2, 1),
+            (true, 2, 2),
+        ];
+        for (same_fetch, good_batches, subscription_change) in cases {
+            let table_path = TablePath::new("db", "tbl");
+            let table_info = build_table_info(table_path.clone(), 1, 1);
+            let metadata = Arc::new(Metadata::new_for_test(build_cluster_arc(&table_path, 1, 1)));
+            let status = Arc::new(LogScannerStatus::new());
+            let fetcher = LogFetcher::new(
+                table_info.clone(),
+                Arc::new(RpcClient::new()),
+                metadata.clone(),
+                status.clone(),
+                &Config::default(),
+                None,
+                false,
+                None,
+                test_scanner_metrics(&table_path),
+                test_schema_getter(&table_info, &metadata),
+            )?;
+            let bucket = TableBucket::new(1, 0);
+            status.assign_scan_bucket(bucket.clone(), 0);
+            let data = build_records(&table_info, Arc::new(table_path))?;
+            let make_fetch = |data: Vec<u8>, offset| {
+                let mut fetch = DefaultCompletedFetch::new(
+                    bucket.clone(),
+                    LogRecordsBatches::new(data.clone()),
+                    data.len(),
+                    test_resolver(&table_info),
+                    false,
+                    offset,
+                    0,
+                );
+                fetch.set_initialized();

Review Comment:
   Could we also test an uninitialized fetch with an authorization error and no preceding data? [The zero-size response check](https://github.com/apache/fluss/blob/cbaf15770e0209ce2aede535e16597d588a492c2/fluss-rust/crates/fluss/src/client/table/scanner.rs#L2301-L2302) currently discards the error and returns an empty result. Please propagate the error immediately; calling `set_initialized()` here bypasses that path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "fresh-borzoni (via GitHub) via issues" <is...@fluss.apache.org>.
fresh-borzoni merged PR #4606:
URL: https://github.com/apache/fluss/pull/4606


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "spoon-lz (via GitHub)" <gi...@apache.org>.
spoon-lz commented on PR #4606:
URL: https://github.com/apache/fluss/pull/4606#issuecomment-6495785347

   @fresh-borzoni Fixed for LogScanner::poll() as well. Both paths now return collected data before later errors while preserving pipelining. Decode errors remain cached until seek or unsubscribe, while transient failures remain retryable. Added regression coverage for both paths.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "naivedogger (via GitHub)" <gi...@apache.org>.
naivedogger commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4293149432


##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -2230,8 +2233,23 @@ impl LogFetcher {
 
                 match next_in_line {
                     Some(mut next_fetch) if !next_fetch.is_consumed() => {
-                        let fetch_result =
-                            self.fetch_batches_from_fetch(&mut next_fetch, batches_remaining)?;
+                        if !result.is_empty() && next_fetch.has_pending_error() {
+                            self.log_fetch_buffer
+                                .set_next_in_line_fetch(Some(next_fetch));
+                            return Ok(result);
+                        }
+                        let fetch_result = match self
+                            .fetch_batches_from_fetch(&mut next_fetch, batches_remaining)
+                        {
+                            Ok(fetch_result) => fetch_result,
+                            Err(error) if !result.is_empty() => {
+                                next_fetch.defer_error(error);

Review Comment:
   Thanks for the update. There seems to be one remaining case: remote download failures are wrapped with offset `-1` in `LogFetchBuffer::try_complete()`. If deferred after valid batches, the error is discarded on the next poll because `fetch_batches_from_fetch()` treats the offset mismatch as a stale response.
   
   Could we preserve the original fetch offset for these failures and add a regression test with valid data followed by a failed pending fetch?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "naivedogger (via GitHub)" <gi...@apache.org>.
naivedogger commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4282773546


##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -2230,8 +2233,23 @@ impl LogFetcher {
 
                 match next_in_line {
                     Some(mut next_fetch) if !next_fetch.is_consumed() => {
-                        let fetch_result =
-                            self.fetch_batches_from_fetch(&mut next_fetch, batches_remaining)?;
+                        if !result.is_empty() && next_fetch.has_pending_error() {
+                            self.log_fetch_buffer
+                                .set_next_in_line_fetch(Some(next_fetch));
+                            return Ok(result);
+                        }
+                        let fetch_result = match self
+                            .fetch_batches_from_fetch(&mut next_fetch, batches_remaining)
+                        {
+                            Ok(fetch_result) => fetch_result,
+                            Err(error) if !result.is_empty() => {
+                                next_fetch.defer_error(error);

Review Comment:
   If a valid batch from bucket A is followed by an authorization error from bucket B, the `initialize_fetch()` error branch returns an error after A's offset has advanced, without delivering A's batch. Could we return the collected batches first, retain the error for the next poll, and add a regression test for this path?



##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -2791,6 +2810,132 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn collect_batches_preserves_partial_results_and_error_order() -> Result<()> {
+        // Cover failures within one fetch and in the next fetch, including no preceding data.
+        let cases = [
+            (false, 0, 0),
+            (false, 0, 1),
+            (false, 0, 2),
+            (false, 1, 0),
+            (false, 1, 1),
+            (false, 1, 2),
+            (false, 2, 0),
+            (false, 2, 1),
+            (false, 2, 2),
+            (true, 0, 0),
+            (true, 0, 1),
+            (true, 0, 2),
+            (true, 1, 0),
+            (true, 1, 1),
+            (true, 1, 2),
+            (true, 2, 0),
+            (true, 2, 1),
+            (true, 2, 2),
+        ];
+        for (same_fetch, good_batches, subscription_change) in cases {
+            let table_path = TablePath::new("db", "tbl");
+            let table_info = build_table_info(table_path.clone(), 1, 1);
+            let metadata = Arc::new(Metadata::new_for_test(build_cluster_arc(&table_path, 1, 1)));
+            let status = Arc::new(LogScannerStatus::new());
+            let fetcher = LogFetcher::new(
+                table_info.clone(),
+                Arc::new(RpcClient::new()),
+                metadata.clone(),
+                status.clone(),
+                &Config::default(),
+                None,
+                false,
+                None,
+                test_scanner_metrics(&table_path),
+                test_schema_getter(&table_info, &metadata),
+            )?;
+            let bucket = TableBucket::new(1, 0);
+            status.assign_scan_bucket(bucket.clone(), 0);
+            let data = build_records(&table_info, Arc::new(table_path))?;
+            let make_fetch = |data: Vec<u8>, offset| {
+                let mut fetch = DefaultCompletedFetch::new(
+                    bucket.clone(),
+                    LogRecordsBatches::new(data.clone()),
+                    data.len(),
+                    test_resolver(&table_info),
+                    false,
+                    offset,
+                    0,
+                );
+                fetch.set_initialized();

Review Comment:
   Could we also test an uninitialized fetch with an authorization error and no preceding data? The `result.is_empty() && size_in_bytes == 0` check currently discards the error and returns an empty result. Please propagate the error immediately; calling `set_initialized()` here bypasses that path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "spoon-lz (via GitHub)" <gi...@apache.org>.
spoon-lz commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4411899041


##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -1060,7 +1060,7 @@ impl LogScannerInner {
             let batches = self.poll_for_batches().await?;
 
             if !batches.is_empty() {
-                self.log_fetcher.send_fetches().await?;
+                // Do not await after collecting data whose offsets have already advanced.

Review Comment:
   Fixed. Both poll paths now schedule the next fetches before returning data, without awaiting metadata refresh. Added regression coverage for pipelining with known and missing leaders.



##########
fluss-rust/crates/fluss/src/client/table/log_fetch_buffer.rs:
##########
@@ -798,7 +818,18 @@ impl CompletedFetch for DefaultCompletedFetch {
         let mut batches = Vec::with_capacity(max_batches.min(16));
 
         for _ in 0..max_batches {
-            match self.next_fetched_batch()? {
+            let step = match self.next_fetched_batch() {
+                Ok(step) => step,
+                Err(error) => {
+                    if batches.is_empty() {
+                        self.drain();
+                        return Err(error);
+                    }
+                    self.defer_error(error);

Review Comment:
   Fixed. Decode errors now include the bucket and offset and preserve the original cause. Added assertions for this context.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "spoon-lz (via GitHub)" <gi...@apache.org>.
spoon-lz commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4291903584


##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -2230,8 +2233,23 @@ impl LogFetcher {
 
                 match next_in_line {
                     Some(mut next_fetch) if !next_fetch.is_consumed() => {
-                        let fetch_result =
-                            self.fetch_batches_from_fetch(&mut next_fetch, batches_remaining)?;
+                        if !result.is_empty() && next_fetch.has_pending_error() {
+                            self.log_fetch_buffer
+                                .set_next_in_line_fetch(Some(next_fetch));
+                            return Ok(result);
+                        }
+                        let fetch_result = match self
+                            .fetch_batches_from_fetch(&mut next_fetch, batches_remaining)
+                        {
+                            Ok(fetch_result) => fetch_result,
+                            Err(error) if !result.is_empty() => {
+                                next_fetch.defer_error(error);

Review Comment:
   Fixed. Collected batches are now returned first, with the initialization error deferred to the next poll. Added a cross-bucket authorization-error regression test.



##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -2791,6 +2810,132 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn collect_batches_preserves_partial_results_and_error_order() -> Result<()> {
+        // Cover failures within one fetch and in the next fetch, including no preceding data.
+        let cases = [
+            (false, 0, 0),
+            (false, 0, 1),
+            (false, 0, 2),
+            (false, 1, 0),
+            (false, 1, 1),
+            (false, 1, 2),
+            (false, 2, 0),
+            (false, 2, 1),
+            (false, 2, 2),
+            (true, 0, 0),
+            (true, 0, 1),
+            (true, 0, 2),
+            (true, 1, 0),
+            (true, 1, 1),
+            (true, 1, 2),
+            (true, 2, 0),
+            (true, 2, 1),
+            (true, 2, 2),
+        ];
+        for (same_fetch, good_batches, subscription_change) in cases {
+            let table_path = TablePath::new("db", "tbl");
+            let table_info = build_table_info(table_path.clone(), 1, 1);
+            let metadata = Arc::new(Metadata::new_for_test(build_cluster_arc(&table_path, 1, 1)));
+            let status = Arc::new(LogScannerStatus::new());
+            let fetcher = LogFetcher::new(
+                table_info.clone(),
+                Arc::new(RpcClient::new()),
+                metadata.clone(),
+                status.clone(),
+                &Config::default(),
+                None,
+                false,
+                None,
+                test_scanner_metrics(&table_path),
+                test_schema_getter(&table_info, &metadata),
+            )?;
+            let bucket = TableBucket::new(1, 0);
+            status.assign_scan_bucket(bucket.clone(), 0);
+            let data = build_records(&table_info, Arc::new(table_path))?;
+            let make_fetch = |data: Vec<u8>, offset| {
+                let mut fetch = DefaultCompletedFetch::new(
+                    bucket.clone(),
+                    LogRecordsBatches::new(data.clone()),
+                    data.len(),
+                    test_resolver(&table_info),
+                    false,
+                    offset,
+                    0,
+                );
+                fetch.set_initialized();

Review Comment:
   Fixed. Zero-byte authorization errors are now propagated immediately when no data is available. Added a regression using an uninitialized fetch, without calling set_initialized().



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "spoon-lz (via GitHub)" <gi...@apache.org>.
spoon-lz commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4411904317


##########
fluss-rust/crates/fluss/src/client/table/log_fetch_buffer.rs:
##########
@@ -1183,6 +1283,73 @@ mod tests {
         assert!(matches!(result, Err(Error::WakeupError { .. })));
     }
 
+    #[tokio::test]
+    async fn pending_file_open_failure_preserves_offset_and_releases_permit() -> Result<()> {
+        use crate::client::table::remote_log::{

Review Comment:
   Done, moved these imports to the test module's imports.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [rust] Return decoded scan batches before later errors [fluss]

Posted by "fresh-borzoni (via GitHub)" <gi...@apache.org>.
fresh-borzoni commented on code in PR #4606:
URL: https://github.com/apache/fluss/pull/4606#discussion_r4402895060


##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -1060,7 +1060,7 @@ impl LogScannerInner {
             let batches = self.poll_for_batches().await?;
 
             if !batches.is_empty() {
-                self.log_fetcher.send_fetches().await?;
+                // Do not await after collecting data whose offsets have already advanced.

Review Comment:
   This drops the pipelined send_fetches() that main and Java do before returning data. 
   Locally that made a scan 55% slower (455 vs 295 ms). Only the metadata refresh can fail or wait here, and with all leaders known send_fetches() does neither. 
   
   Shall we keep pipelining and just skip the refresh on this path?



##########
fluss-rust/crates/fluss/src/client/table/log_fetch_buffer.rs:
##########
@@ -1183,6 +1283,73 @@ mod tests {
         assert!(matches!(result, Err(Error::WakeupError { .. })));
     }
 
+    #[tokio::test]
+    async fn pending_file_open_failure_preserves_offset_and_releases_permit() -> Result<()> {
+        use crate::client::table::remote_log::{

Review Comment:
   ditto



##########
fluss-rust/crates/fluss/src/client/table/log_fetch_buffer.rs:
##########
@@ -798,7 +818,18 @@ impl CompletedFetch for DefaultCompletedFetch {
         let mut batches = Vec::with_capacity(max_batches.min(16));
 
         for _ in 0..max_batches {
-            match self.next_fetched_batch()? {
+            let step = match self.next_fetched_batch() {
+                Ok(step) => step,
+                Err(error) => {
+                    if batches.is_empty() {
+                        self.drain();
+                        return Err(error);
+                    }
+                    self.defer_error(error);

Review Comment:
   The deferred error doesn't say which bucket failed. All the caller sees is Parser error: Invalid continuation marker: 0, a poll later. 
   
   Could we wrap it with the bucket and offset, like records mode and Java do?



##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -2791,6 +2813,484 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn batch_poll_returns_buffered_data_before_metadata_refresh_error() -> Result<()> {
+        let table_path = TablePath::new("db", "tbl");
+        let table_info = build_table_info(table_path.clone(), 1, 1);
+        // No servers or bootstrap address: refreshing metadata fails without network I/O.
+        let metadata = Arc::new(Metadata::new_for_test(Default::default()));
+        let rpc_client = Arc::new(RpcClient::new());
+        let admin = Arc::new(crate::client::admin::FlussAdmin::new(
+            rpc_client.clone(),
+            metadata.clone(),
+        ));
+        let inner = Arc::new(LogScannerInner::new(
+            &table_info,
+            metadata,
+            rpc_client,
+            &Config::default(),
+            None,
+            false,
+            None,
+            admin,
+        )?);
+        let scanner = RecordBatchLogScanner { inner };
+        let bucket = TableBucket::new(1, 0);
+        scanner
+            .inner
+            .log_scanner_status
+            .assign_scan_bucket(bucket.clone(), 0);
+        let data = build_records(&table_info, Arc::new(table_path))?;
+        let size = data.len();
+        scanner
+            .inner
+            .log_fetcher
+            .log_fetch_buffer
+            .add(Box::new(DefaultCompletedFetch::new(
+                bucket.clone(),
+                LogRecordsBatches::new(data),
+                size,
+                test_resolver(&table_info),
+                false,
+                0,
+                0,
+            )));
+
+        let batches = scanner.poll(Duration::ZERO).await?;
+        assert_eq!(batches.len(), 1);
+        assert_eq!(batches[0].bucket(), &bucket);
+        assert_eq!(batches[0].base_offset(), 0);
+        assert_eq!(batches[0].batch().num_rows(), 1);
+        assert_eq!(
+            scanner.inner.log_scanner_status.get_bucket_offset(&bucket),
+            Some(1)
+        );
+
+        // The next poll has no buffered data, so it attempts metadata refresh.
+        let error = scanner.poll(Duration::ZERO).await.unwrap_err();
+        assert!(
+            error
+                .to_string()
+                .contains("No bootstrap servers configured")
+        );
+        assert_eq!(
+            scanner.inner.log_scanner_status.get_bucket_offset(&bucket),
+            Some(1)
+        );
+        scanner.unsubscribe(0).await?;
+        assert!(scanner.poll(Duration::ZERO).await?.is_empty());
+        Ok(())
+    }
+
+    #[tokio::test]
+    async fn collect_batches_preserves_pending_fetch_errors() -> Result<()> {
+        for (preceding_data, subscription_change) in [(false, 0), (true, 0), (true, 1), (true, 2)] {
+            for same_bucket in [false, true] {
+                for cancelled in [false, true] {
+                    check_pending_fetch_error(
+                        preceding_data,
+                        same_bucket,
+                        cancelled,
+                        subscription_change,
+                    )
+                    .await?;
+                }
+            }
+        }
+        Ok(())
+    }
+
+    async fn check_pending_fetch_error(
+        preceding_data: bool,
+        same_bucket: bool,
+        cancelled: bool,
+        subscription_change: u8,
+    ) -> Result<()> {
+        use crate::client::table::remote_log::{RemoteLogDownloadFuture, RemoteLogSegment};

Review Comment:
   use inside the function body. Hoist it to the module top?



##########
fluss-rust/crates/fluss/src/client/table/scanner.rs:
##########
@@ -2791,6 +2813,484 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn batch_poll_returns_buffered_data_before_metadata_refresh_error() -> Result<()> {
+        let table_path = TablePath::new("db", "tbl");
+        let table_info = build_table_info(table_path.clone(), 1, 1);
+        // No servers or bootstrap address: refreshing metadata fails without network I/O.
+        let metadata = Arc::new(Metadata::new_for_test(Default::default()));
+        let rpc_client = Arc::new(RpcClient::new());
+        let admin = Arc::new(crate::client::admin::FlussAdmin::new(
+            rpc_client.clone(),
+            metadata.clone(),
+        ));
+        let inner = Arc::new(LogScannerInner::new(
+            &table_info,
+            metadata,
+            rpc_client,
+            &Config::default(),
+            None,
+            false,
+            None,
+            admin,
+        )?);
+        let scanner = RecordBatchLogScanner { inner };
+        let bucket = TableBucket::new(1, 0);
+        scanner
+            .inner
+            .log_scanner_status
+            .assign_scan_bucket(bucket.clone(), 0);
+        let data = build_records(&table_info, Arc::new(table_path))?;
+        let size = data.len();
+        scanner
+            .inner
+            .log_fetcher
+            .log_fetch_buffer
+            .add(Box::new(DefaultCompletedFetch::new(
+                bucket.clone(),
+                LogRecordsBatches::new(data),
+                size,
+                test_resolver(&table_info),
+                false,
+                0,
+                0,
+            )));
+
+        let batches = scanner.poll(Duration::ZERO).await?;
+        assert_eq!(batches.len(), 1);
+        assert_eq!(batches[0].bucket(), &bucket);
+        assert_eq!(batches[0].base_offset(), 0);
+        assert_eq!(batches[0].batch().num_rows(), 1);
+        assert_eq!(
+            scanner.inner.log_scanner_status.get_bucket_offset(&bucket),
+            Some(1)
+        );
+
+        // The next poll has no buffered data, so it attempts metadata refresh.
+        let error = scanner.poll(Duration::ZERO).await.unwrap_err();
+        assert!(
+            error
+                .to_string()
+                .contains("No bootstrap servers configured")
+        );
+        assert_eq!(
+            scanner.inner.log_scanner_status.get_bucket_offset(&bucket),
+            Some(1)
+        );
+        scanner.unsubscribe(0).await?;
+        assert!(scanner.poll(Duration::ZERO).await?.is_empty());
+        Ok(())
+    }
+
+    #[tokio::test]
+    async fn collect_batches_preserves_pending_fetch_errors() -> Result<()> {
+        for (preceding_data, subscription_change) in [(false, 0), (true, 0), (true, 1), (true, 2)] {
+            for same_bucket in [false, true] {
+                for cancelled in [false, true] {
+                    check_pending_fetch_error(
+                        preceding_data,
+                        same_bucket,
+                        cancelled,
+                        subscription_change,
+                    )
+                    .await?;
+                }
+            }
+        }
+        Ok(())
+    }
+
+    async fn check_pending_fetch_error(
+        preceding_data: bool,
+        same_bucket: bool,
+        cancelled: bool,
+        subscription_change: u8,
+    ) -> Result<()> {
+        use crate::client::table::remote_log::{RemoteLogDownloadFuture, RemoteLogSegment};
+
+        let table_path = TablePath::new("db", "tbl");
+        let table_info = build_table_info(table_path.clone(), 1, 2);
+        let metadata = Arc::new(Metadata::new_for_test(build_cluster_arc(&table_path, 1, 2)));
+        let status = Arc::new(LogScannerStatus::new());
+        let fetcher = LogFetcher::new(
+            table_info.clone(),
+            Arc::new(RpcClient::new()),
+            metadata.clone(),
+            status.clone(),
+            &Config::default(),
+            None,
+            false,
+            None,
+            test_scanner_metrics(&table_path),
+            test_schema_getter(&table_info, &metadata),
+        )?;
+        let data_bucket = TableBucket::new(1, 0);
+        let error_bucket = TableBucket::new(1, i32::from(!same_bucket));
+        let error_offset = if same_bucket {
+            i64::from(preceding_data)
+        } else {
+            5
+        };
+        status.assign_scan_bucket(error_bucket.clone(), error_offset);
+        if preceding_data {
+            status.assign_scan_bucket(data_bucket.clone(), 0);
+            let data = build_records(&table_info, Arc::new(table_path))?;
+            let size = data.len();
+            fetcher
+                .log_fetch_buffer
+                .add(Box::new(DefaultCompletedFetch::new(
+                    data_bucket.clone(),
+                    LogRecordsBatches::new(data),
+                    size,
+                    test_resolver(&table_info),
+                    false,
+                    0,
+                    0,
+                )));
+        }
+        let (sender, receiver) = tokio::sync::oneshot::channel();
+        let download = RemoteLogDownloadFuture::new(receiver);
+        let completed = Arc::new(tokio::sync::Notify::new());
+        let notification = completed.clone();
+        download.on_complete(move || notification.notify_one());
+        fetcher
+            .log_fetch_buffer
+            .pend(Box::new(RemotePendingFetch::new(
+                RemoteLogSegment {
+                    segment_id: "failed-download".to_string(),
+                    start_offset: 0,
+                    end_offset: 10,
+                    size_in_bytes: 0,
+                    table_bucket: error_bucket.clone(),
+                    max_timestamp: 0,
+                },
+                download,
+                0,
+                error_offset,
+                10,
+                test_resolver(&table_info),
+            )));
+        if cancelled {
+            drop(sender);
+        } else {
+            assert!(
+                sender
+                    .send(Err(Error::UnexpectedError {
+                        message: "download failed".to_string(),
+                        source: None,
+                    }))
+                    .is_ok()
+            );
+        }
+        completed.notified().await;
+        fetcher.log_fetch_buffer.try_complete(&error_bucket);
+
+        if preceding_data {
+            let batches = fetcher.collect_batches().await?;
+            assert_eq!(batches.len(), 1);
+            assert_eq!(batches[0].bucket(), &data_bucket);
+            assert_eq!(batches[0].base_offset(), 0);
+            assert_eq!(batches[0].batch().num_rows(), 1);
+            assert_eq!(status.get_bucket_offset(&data_bucket), Some(1));
+        }
+        assert_eq!(status.get_bucket_offset(&error_bucket), Some(error_offset));
+        // Subscription changes apply after an error has been deferred.
+        if preceding_data && subscription_change == 1 {
+            status.unassign_scan_buckets(std::slice::from_ref(&error_bucket));
+        } else if preceding_data && subscription_change == 2 {
+            status.update_offset(&error_bucket, error_offset + 1);
+        } else {
+            let error = fetcher.collect_batches().await.unwrap_err();
+            let expected = if cancelled {
+                "future cancelled"
+            } else {
+                "download failed"
+            };
+            assert!(matches!(error, Error::IoUnexpectedError { message, .. }
+                if message.contains(expected)));
+            assert_eq!(status.get_bucket_offset(&error_bucket), Some(error_offset));
+        }
+        assert!(fetcher.collect_batches().await?.is_empty());
+        Ok(())
+    }
+
+    #[tokio::test]
+    async fn collect_batches_preserves_data_across_schema_errors() -> Result<()> {
+        use crate::record::SCHEMA_ID_OFFSET;

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org