You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "david-streamlio (via GitHub)" <gi...@apache.org> on 2026/07/09 22:44:36 UTC

[PR] [fix][io] Do not drop files when the work queue rejects an offer [pulsar-connectors]

david-streamlio opened a new pull request, #81:
URL: https://github.com/apache/pulsar-connectors/pull/81

   Fixes #80
   
   ### Motivation
   
   `FileListingThread` records a file as offered **before** checking that the work queue accepted it:
   
   ```java
   for (File f : listing) {
       if (alreadyOffered.add(f)) {
           workQueue.offer(f);      // return value ignored
       }
   }
   ```
   
   Ignoring `offer()`'s result is safe only while `workQueue` is unbounded, which it is today. The moment it is bounded, `offer()` returns `false` when the queue is full — the file is already in `alreadyOffered`, and the prune step only forgets files that have **left the disk**. The file is never enqueued, never retried, and never processed.
   
   This is not theoretical: #28 ("Prevent OOM in FileSource by bounding internal queues") does exactly that. It is green and conflicts with nothing, because it touches different files — so the loss would have merged silently. Worse, the failure triggers precisely under the backlog #28 exists to survive.
   
   Reproduced against current master with a bounded `workQueue` of capacity 1 and 3 files on disk:
   
   ```
   WORKQUEUE_SIZE=1
   FILES_ON_DISK=3
   AFTER_DRAIN_REOFFERED=0     <-- the other 2 files are never re-offered
   ```
   
   The assumption is mine, introduced in #41. This PR removes it so #28 can land safely.
   
   ### Modifications
   
   Track a file only once the queue has accepted it:
   
   ```java
   for (File f : listing) {
       if (!alreadyOffered.contains(f) && workQueue.offer(f)) {
           alreadyOffered.add(f);
       }
   }
   ```
   
   A rejected file is simply retried on the next listing pass — the lister slows to the consumer's rate rather than discarding work, which is the back-pressure behavior a bounded queue is meant to produce. The `keepFile=true` branch re-checks `workQueue.contains(f)` each pass and is unaffected.
   
   ### Tests
   
   `FileListingThreadBoundedQueueTest` bounds the queue itself, so it holds regardless of what `FileSource` constructs today and guards the invariant ahead of #28:
   
   - `rejectedFilesAreRetriedOnceTheQueueDrains` — 3 files, queue capacity 1; every file must reach the queue as it drains.
   - `filesAreNotOfferedTwiceWhileTheyRemainOnDisk` — the exactly-once property from #41 must survive the new retry path.
   
   ### Verifying this change
   
   The regression test genuinely catches the bug. Reverting `FileListingThread` to master's version:
   
   ```
   rejectedFilesAreRetriedOnceTheQueueDrains FAILED
       org.awaitility.core.ConditionTimeoutException: Condition ... was not fulfilled within 30 seconds.
   filesAreNotOfferedTwiceWhileTheyRemainOnDisk PASSED
   ```
   
   The second test passes either way, as it should — it pins the property the bug never broke.
   
   With the fix applied, the full `:file:test` suite is green (`BUILD SUCCESSFUL in 1m 58s`), including the previously flaky `ProcessedFileThreadTest`.
   
   ### Suggested merge order
   
   1. this PR
   2. #28 — rebase; its bounded queues then cannot drop files


-- 
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: commits-unsubscribe@pulsar.apache.org

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


Re: [PR] [fix][io] Do not drop files when the work queue rejects an offer [pulsar-connectors]

Posted by "david-streamlio (via GitHub)" <gi...@apache.org>.
david-streamlio merged PR #81:
URL: https://github.com/apache/pulsar-connectors/pull/81


-- 
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: commits-unsubscribe@pulsar.apache.org

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


Re: [PR] [fix][io] Do not drop files when the work queue rejects an offer [pulsar-connectors]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #81:
URL: https://github.com/apache/pulsar-connectors/pull/81#discussion_r3555285148


##########
kafka/src/test/java/org/apache/pulsar/io/kafka/KafkaConnectorIntegrationTest.java:
##########
@@ -0,0 +1,321 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.io.kafka;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.clients.consumer.ConsumerRecords;
+import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.Producer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.serialization.ByteArrayDeserializer;
+import org.apache.kafka.common.serialization.ByteArraySerializer;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.apache.pulsar.functions.api.Record;
+import org.apache.pulsar.io.core.SinkContext;
+import org.apache.pulsar.io.core.SourceContext;
+import org.awaitility.Awaitility;
+import org.mockito.Mockito;
+import org.testcontainers.kafka.KafkaContainer;
+import org.testcontainers.utility.DockerImageName;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * Integration tests for the Kafka source and sink connectors, exercised against a real Kafka
+ * broker via Testcontainers.
+ *
+ * <p>Unlike the other Kafka unit tests in this module (which mock the broker), these tests wire

Review Comment:
   The PR description/title is focused on the file connector (#80), but this change set also adds a Docker/Testcontainers-based Kafka integration test (and new testcontainers deps). This looks unrelated to the stated fix; if it’s intentional, please update the PR scope/description, otherwise consider splitting it into a separate PR.
   
   Also note this test will run as part of the regular `:kafka:test` suite and will fail in environments without Docker; if that’s not intended, move it to a dedicated `integrationTest` source set/task (as done in `mqtt/build.gradle.kts`) or otherwise gate/segregate Docker-dependent tests.



-- 
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: commits-unsubscribe@pulsar.apache.org

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


Re: [PR] [fix][io] Do not drop files when the work queue rejects an offer [pulsar-connectors]

Posted by "david-streamlio (via GitHub)" <gi...@apache.org>.
david-streamlio commented on PR #81:
URL: https://github.com/apache/pulsar-connectors/pull/81#issuecomment-4930486562

   Good catch — the Kafka files were unintentional. The branch had been cut before #76 merged and carried its commit along; #14's rename of `FileListingThread` → `FileListingTask` then put it in conflict with master as well.
   
   Rebuilt the branch on current master. The diff is now exactly two files:
   
   ```
   file/src/main/java/org/apache/pulsar/io/file/FileListingTask.java
   file/src/test/java/org/apache/pulsar/io/file/FileListingTaskBoundedQueueTest.java
   ```
   
   The fix is ported to the renamed `FileListingTask`, and the regression test still earns its place: reverting `FileListingTask` to master's version makes `rejectedFilesAreRetriedOnceTheQueueDrains` fail with a `ConditionTimeoutException`, while `filesAreNotOfferedTwiceWhileTheyRemainOnDisk` passes either way — it pins the exactly-once property that the bug never broke. Full `:file:test` suite green.


-- 
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: commits-unsubscribe@pulsar.apache.org

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