Procházet zdrojové kódy

Only add dirty subscriptions to the request

Also handle if the request ends up empty because all of the subscriptions were
clean.
Evan Huus před 10 roky
rodič
revize
b4fb5b7b3b
1 změnil soubory, kde provedl 14 přidání a 2 odebrání
  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) {