Skip to content

Commit 929d564

Browse files
committed
pkg/kgo: allow marking using an offset
Currently marking is only available via records, expose a new function, MarkCommitOffsets, to allow marking using offsets only.
1 parent a2d69ce commit 929d564

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

‎pkg/kgo/consumer_group.go‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,44 @@ func (cl *Client) MarkCommitRecords(rs ...*Record) {
24332433
}
24342434
}
24352435

2436+
// MarkCommitOffsets marks offsets to be available for autocommitting. This
2437+
// function is only useful if you use the AutoCommitMarks config option, see
2438+
// the documentation on that option for more details. This function does not
2439+
// allow rewinds.
2440+
func (cl *Client) MarkCommitOffsets(unmarked map[string]map[int32]EpochOffset) {
2441+
g := cl.consumer.g
2442+
if g == nil || !cl.cfg.autocommitMarks {
2443+
return
2444+
}
2445+
2446+
// protect g.uncommitted map
2447+
g.mu.Lock()
2448+
defer g.mu.Unlock()
2449+
2450+
if g.uncommitted == nil {
2451+
g.uncommitted = make(uncommitted)
2452+
}
2453+
2454+
for topic, partitions := range unmarked {
2455+
curPartitions := g.uncommitted[topic]
2456+
if curPartitions == nil {
2457+
curPartitions = make(map[int32]uncommit)
2458+
g.uncommitted[topic] = curPartitions
2459+
}
2460+
2461+
for partition, newHead := range partitions {
2462+
current := curPartitions[partition]
2463+
if current.head.Less(newHead) {
2464+
curPartitions[partition] = uncommit{
2465+
dirty: current.dirty,
2466+
committed: current.committed,
2467+
head: newHead,
2468+
}
2469+
}
2470+
}
2471+
}
2472+
}
2473+
24362474
// CommitUncommittedOffsets issues a synchronous offset commit for any
24372475
// partition that has been consumed from that has uncommitted offsets.
24382476
// Retryable errors are retried up to the configured retry limit, and any

0 commit comments

Comments
 (0)