[improve][io] JDBC sink: replace synchronized queue with LinkedBlockingDeque for proper back-pressure#17
Open
harangozop wants to merge 1 commit intoapache:masterfrom
Conversation
…ngDeque for proper back-pressure Replaces manual `synchronized(incomingList)` blocks with JDK's `LinkedBlockingDeque` for proper blocking back-pressure instead of the nack/redeliver storm caused by `record.fail()`. Key changes: - Use `offer(record, 1s timeout)` in write() to block the Pulsar IO thread when queue is full, stopping message consumption naturally - Use `drainTo()` in flush() for non-blocking atomic batch drain - Replace recursive flush() with iterative while loop - Move isFlushing.set(false) to finally block - Drain remaining records in close() for clean shutdown Follows the established pattern used by Aerospike, HDFS, Kinesis, and DynamoDB connectors in this repository. Fixes apache#16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Follow-up to #9. The
record.fail()back-pressure introduced in #9 causes a nack/redeliver storm under sustained load — the consumer delivers messages, the sink immediately fails them, they get redelivered, repeating endlessly. This wastes CP time.Modifications
Replace
LinkedList+synchronizedwithLinkedBlockingDeque:write():offer(record, 1, TimeUnit.SECONDS)blocks the Pulsar IO thread when queue is full — this IS the back-pressure (stops consumption). At most 1 nack/second on timeout vs. thousands/second before.flush():drainTo(swapList, batchSize)— non-blocking atomic drain, no synchronized blocks. Automatically wakes blockedoffer()calls by making space.flush()uses awhileloop instead of recursive self-calls.isFlushinginfinally: prevents stuck flag after exceptions.close()drains queue: fails remaining records for clean shutdown.Follows the pattern already used by Aerospike (
LinkedBlockingDeque), HDFS, Kinesis, and DynamoDB (LinkedBlockingQueue) connectors in this repo.Verifying this change
testBoundedQueueBackPressuremay need timeout adjustment (6th write now blocks 1s instead of failing instantly)Fixes #16