浏览代码

Don't start setting until the initial get succeeds

Divorce selecting the appropriate broker with subscribing to that broker, they
have to be separate actions.

Thanks to Aaron Kavlie for finding the bug.
Evan Huus 10 年之前
父节点
当前提交
9e2380c33a
共有 1 个文件被更改,包括 7 次插入2 次删除
  1. 7 2
      offset_manager.go

+ 7 - 2
offset_manager.go

@@ -168,6 +168,8 @@ func (om *offsetManager) newPartitionOffsetManager(topic string, partition int32
 		return nil, err
 	}
 
+	pom.broker.updateSubscriptions <- pom
+
 	go withRecover(pom.mainLoop)
 
 	return pom, nil
@@ -180,6 +182,8 @@ func (pom *partitionOffsetManager) mainLoop() {
 			if err := pom.selectBroker(); err != nil {
 				pom.handleError(err)
 				pom.rebalance <- none{}
+			} else {
+				pom.broker.updateSubscriptions <- pom
 			}
 		case <-pom.dying:
 			if pom.broker != nil {
@@ -213,7 +217,6 @@ func (pom *partitionOffsetManager) selectBroker() error {
 	}
 
 	pom.broker = pom.parent.refBrokerOffsetManager(broker)
-	pom.broker.updateSubscriptions <- pom
 	return nil
 }
 
@@ -362,7 +365,9 @@ func (bom *brokerOffsetManager) mainLoop() {
 	for {
 		select {
 		case <-bom.timer.C:
-			bom.flushToBroker()
+			if len(bom.subscriptions) > 0 {
+				bom.flushToBroker()
+			}
 		case s, ok := <-bom.updateSubscriptions:
 			if !ok {
 				bom.timer.Stop()