Skip to content
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

Ensure ordering of offset commit requests #2941

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions offset_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type offsetManager struct {
poms map[string]map[int32]*partitionOffsetManager
pomsLock sync.RWMutex

commitLock sync.Mutex

closeOnce sync.Once
closing chan none
closed chan none
Expand Down Expand Up @@ -251,17 +253,19 @@ func (om *offsetManager) Commit() {
}

func (om *offsetManager) flushToBroker() {
req := om.constructRequest()
if req == nil {
return
}

broker, err := om.coordinator()
if err != nil {
om.handleError(err)
return
}

om.commitLock.Lock()
defer om.commitLock.Unlock()
req := om.constructRequest()
if req == nil {
return
}

resp, err := broker.CommitOffset(req)
if err != nil {
om.handleError(err)
Expand Down
3 changes: 3 additions & 0 deletions offset_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func TestNewOffsetManager(t *testing.T) {
metadataResponse := new(MetadataResponse)
metadataResponse.AddBroker(seedBroker.Addr(), seedBroker.BrokerID())
seedBroker.Returns(metadataResponse)
findCoordResponse := new(FindCoordinatorResponse)
findCoordResponse.Coordinator = &Broker{id: seedBroker.brokerID, addr: seedBroker.Addr()}
seedBroker.Returns(findCoordResponse)
defer seedBroker.Close()

testClient, err := NewClient([]string{seedBroker.Addr()}, NewTestConfig())
Expand Down
Loading