-
-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent the consumption of messages for topics paused while fetch is in-flight #397
Changes from 2 commits
f72fb14
e25f31c
ab3cd54
78a521d
abf0838
b7a99b0
3e6319a
4117828
3cf303d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -609,6 +609,57 @@ describe('Consumer', () => { | |
}) | ||
}) | ||
|
||
it('discards messages received when pausing while fetch is in-flight', async () => { | ||
consumer = createConsumer({ | ||
cluster: createCluster(), | ||
groupId, | ||
maxWaitTimeInMs: 1000, | ||
logger: newLogger(), | ||
}) | ||
|
||
const messages = Array(10) | ||
.fill() | ||
.map(() => { | ||
const value = secureRandom() | ||
return { key: `key-${value}`, value: `value-${value}` } | ||
}) | ||
await producer.connect() | ||
await producer.send({ acks: 1, topic: topicName, messages }) | ||
|
||
await consumer.connect() | ||
|
||
await consumer.subscribe({ topic: topicName, fromBeginning: true }) | ||
|
||
const sleep = value => waitFor(delay => delay >= value) | ||
let offsetsConsumed = [] | ||
|
||
const eachBatch = async ({ batch, heartbeat }) => { | ||
for (const message of batch.messages) { | ||
offsetsConsumed.push(message.offset) | ||
} | ||
|
||
await heartbeat() | ||
} | ||
|
||
consumer.run({ | ||
eachBatch, | ||
}) | ||
|
||
await waitForConsumerToJoinGroup(consumer) | ||
|
||
await waitFor(() => offsetsConsumed.length === messages.length, { delay: 50 }) | ||
await sleep(50) | ||
|
||
// Hope that we're now in an active fetch state? Something like FETCH_START might help | ||
const seekedOffset = offsetsConsumed[Math.floor(messages.length / 2)] | ||
JaapRood marked this conversation as resolved.
Show resolved
Hide resolved
|
||
consumer.pause([{ topic: topicName }]) | ||
await producer.send({ acks: 1, topic: topicName, messages }) // trigger completion of fetch | ||
|
||
await sleep(200) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than sleeping an arbitrary amount and hoping we've consumed the message by then, use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point is that no message has been consumed, that nothing has happened, so that makes a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I should have read it more properly. Perhaps there's an event you could wait for having happened, such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ended up going with |
||
|
||
expect(offsetsConsumed.length).toEqual(messages.length) | ||
}) | ||
|
||
describe('transactions', () => { | ||
testIfKafka_0_11('accepts messages from an idempotent producer', async () => { | ||
cluster = createCluster({ allowExperimentalV011: true }) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it's gonna be extremely flaky. We should indeed add a new instrumentation event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An instrumentation event would definitely be better, however in all past test runs since the first version of this was introduced (in #367) I haven't found a trace of failing once. That said, if Kafka responds a bunch slower through doing some compaction or whatever, the timing is most likely hosed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These things tend to become an issue in CI, even if they're reasonably reliable locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added
FETCH_START
, so far without a payload, as the only use case for it now doesn't require one to function. It's mirrored afterGROUP_JOIN
, with subject first, action second. Was a bit of a judgement call, as the BATCH ones do list the verb first. I reckoned subject first should help group them nicely when listing them, which seems as good a reason for something rather arbitrary as any other :)