Browse Source

Only add dirty subscriptions to the request

Also handle if the request ends up empty because all of the subscriptions were
clean.
Evan Huus 10 years ago
parent
commit
b4fb5b7b3b
1 changed files with 14 additions and 2 deletions
  1. 14 2
      offset_manager.go

+ 14 - 2
offset_manager.go

@@ -384,6 +384,10 @@ func (bom *brokerOffsetManager) mainLoop() {
 
 func (bom *brokerOffsetManager) flushToBroker() {
 	request := bom.constructRequest()
+	if request == nil {
+		return
+	}
+
 	response, err := bom.broker.CommitOffset(request)
 
 	if err != nil {
@@ -428,12 +432,20 @@ func (bom *brokerOffsetManager) constructRequest() *OffsetCommitRequest {
 		Version:       1,
 		ConsumerGroup: bom.parent.group,
 	}
+
 	for s := range bom.subscriptions {
 		s.lock.Lock()
-		r.AddBlock(s.topic, s.partition, s.offset, 0, s.metadata)
+		if s.dirty {
+			r.AddBlock(s.topic, s.partition, s.offset, 0, s.metadata)
+		}
 		s.lock.Unlock()
 	}
-	return r
+
+	if len(r.blocks) > 0 {
+		return r
+	}
+
+	return nil
 }
 
 func (bom *brokerOffsetManager) abort(err error) {