Skip to content

Commit

Permalink
Fix handle duplicate delete message in kafka (uber#1451)
Browse files Browse the repository at this point in the history
  • Loading branch information
vancexu authored Feb 12, 2019
1 parent 8ef3de8 commit 99b9eab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions service/worker/indexer/esProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ func (p *esProcessorImpl) Stop() {

// Add an ES request, and an map item for kafka message
func (p *esProcessorImpl) Add(request elastic.BulkableRequest, key string, kafkaMsg messaging.Message) {
if p.mapToKafkaMsg.Contains(key) { // handle duplicate delete message
p.ackKafkaMsg(key)
}
p.mapToKafkaMsg.Put(key, kafkaMsg)
p.processor.Add(request)
}
Expand Down
7 changes: 7 additions & 0 deletions service/worker/indexer/esProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ func (s *esProcessorSuite) TestAdd() {
s.esProcessor.Add(request, key, mockKafkaMsg)
s.Equal(1, s.esProcessor.mapToKafkaMsg.Size())
mockKafkaMsg.AssertExpectations(s.T())

// handle duplicate
mockKafkaMsg.On("Ack").Return(nil).Once()
s.mockBulkProcessor.On("Add", request).Return().Once()
s.esProcessor.Add(request, key, mockKafkaMsg)
s.Equal(1, s.esProcessor.mapToKafkaMsg.Size())
mockKafkaMsg.AssertExpectations(s.T())
}

func (s *esProcessorSuite) TestBulkAfterAction() {
Expand Down

0 comments on commit 99b9eab

Please sign in to comment.