Skip to content

Commit

Permalink
fix: resolve and commit offsets from partial aborts
Browse files Browse the repository at this point in the history
  • Loading branch information
julienvincent committed Dec 19, 2021
1 parent 1fe29b0 commit 0480ed5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/consumer/__tests__/instrumentationEvents.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ describe('Consumer > Instrumentation Events', () => {
batchSize: 0,
firstOffset: '0',
lastOffset: '1',
duration: 0,
duration: expect.any(Number),
},
})
})
Expand Down
24 changes: 19 additions & 5 deletions src/consumer/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,27 @@ module.exports = class Runner extends EventEmitter {
}

/**
* If the batch contained control records but no otherwise processable records then we
* still need to emit START|END batch instrumentation events to allow any listeners
* keeping track of offsets to know about the latest point of consumption
* If the batch contained only control records or only aborted messages then we still
* need to resolve and auto-commit to ensure the consumer can move forward.
*
* We also need to emit batch instrumentation events to allow any listeners keeping
* track of offsets to know about the latest point of consumption.
*/
if (batch.isEmptyControlRecord()) {
if (batch.isEmpty() && !batch.isEmptyIncludingFiltered()) {
this.instrumentationEmitter.emit(START_BATCH_PROCESS, payload)
this.instrumentationEmitter.emit(END_BATCH_PROCESS, { ...payload, duration: 0 })

this.consumerGroup.resolveOffset({
topic: batch.topic,
partition: batch.partition,
offset: batch.lastOffset(),
})
await this.autoCommitOffsetsIfNecessary()

this.instrumentationEmitter.emit(END_BATCH_PROCESS, {
...payload,
duration: Date.now() - startBatchProcess,
})
return
}

if (batch.isEmpty()) {
Expand Down

0 comments on commit 0480ed5

Please sign in to comment.