MCPcopy Create free account
hub / github.com/IBM/sarama / constructRequestFor

Method constructRequestFor

offset_manager.go:361–399  ·  view source on GitHub ↗

constructRequestFor also returns the version of each POM it took an offset from

(targets partitionTargets)

Source from the content-addressed store, hash-verified

359
360// constructRequestFor also returns the version of each POM it took an offset from
361func (om *offsetManager) constructRequestFor(targets partitionTargets) (*OffsetCommitRequest, map[*partitionOffsetManager]uint64) {
362 r := NewOffsetCommitRequest(om.conf, om.group)
363 r.ConsumerID = om.memberID
364 // om.generation is read under generationLock, held by flushToBrokerFor
365 r.ConsumerGroupGeneration = om.generation
366 r.GroupInstanceId = om.groupInstanceId
367
368 // commit timestamp was only briefly supported in V1 where we set it to
369 // ReceiveTime (-1) to tell the broker to set it to the time when the commit
370 // request was received
371 var commitTimestamp int64
372 if r.Version == 1 {
373 commitTimestamp = ReceiveTime
374 }
375
376 om.pomsLock.RLock()
377 defer om.pomsLock.RUnlock()
378
379 versions := make(map[*partitionOffsetManager]uint64)
380 for topic, topicManagers := range om.poms {
381 for partition, pom := range topicManagers {
382 if !targets.covers(topic, partition) {
383 continue
384 }
385 pom.lock.Lock()
386 if pom.dirty {
387 r.AddBlockWithLeaderEpoch(pom.topic, pom.partition, pom.offset, pom.leaderEpoch, commitTimestamp, pom.metadata)
388 versions[pom] = pom.version
389 }
390 pom.lock.Unlock()
391 }
392 }
393
394 if len(r.blocks) > 0 {
395 return r, versions
396 }
397
398 return nil, nil
399}
400
401func (om *offsetManager) handleResponse(broker *Broker, req *OffsetCommitRequest, resp *OffsetCommitResponse, versions map[*partitionOffsetManager]uint64) {
402 // release coordinator after dropping pomsLock to avoid lock inversion (#3191)

Callers 2

flushToBrokerForMethod · 0.95

Calls 3

NewOffsetCommitRequestFunction · 0.85
coversMethod · 0.80

Tested by 1