From b88f7e422937ab1a5f223c356a96c866bb5995b7 Mon Sep 17 00:00:00 2001
From: Ashwin <ashwin2007ray@gmail.com>
Date: Sat, 27 Feb 2016 16:58:48 +1100
Subject: [PATCH] Export Addr in conn.pool

---
 conn/pool.go     | 8 ++++----
 worker/worker.go | 8 +++-----
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/conn/pool.go b/conn/pool.go
index b8aa1305..40e00e8b 100644
--- a/conn/pool.go
+++ b/conn/pool.go
@@ -13,12 +13,12 @@ var glog = x.Log("conn")
 
 type Pool struct {
 	clients chan *rpc.Client
-	addr    string
+	Addr    string
 }
 
 func NewPool(addr string, maxCap int) *Pool {
 	p := new(Pool)
-	p.addr = addr
+	p.Addr = addr
 	p.clients = make(chan *rpc.Client, maxCap)
 	client, err := p.dialNew()
 	if err != nil {
@@ -36,7 +36,7 @@ func (p *Pool) dialNew() (*rpc.Client, error) {
 	var nconn net.Conn
 	var err error
 	for i := 0; i < 10; i++ {
-		nconn, err = d.Dial("tcp", p.addr)
+		nconn, err = d.Dial("tcp", p.Addr)
 		if err == nil {
 			break
 		}
@@ -44,7 +44,7 @@ func (p *Pool) dialNew() (*rpc.Client, error) {
 			break
 		}
 
-		glog.WithField("error", err).WithField("addr", p.addr).
+		glog.WithField("error", err).WithField("addr", p.Addr).
 			Info("Retrying connection...")
 		time.Sleep(10 * time.Second)
 	}
diff --git a/worker/worker.go b/worker/worker.go
index 5175a9b5..1e97061c 100644
--- a/worker/worker.go
+++ b/worker/worker.go
@@ -22,7 +22,6 @@ var glog = x.Log("worker")
 var dataStore, uidStore *store.Store
 var pools []*conn.Pool
 var numInstances, instanceIdx uint64
-var addrs []string
 
 func Init(ps, uStore *store.Store, idx, numInst uint64) {
 	dataStore = ps
@@ -45,8 +44,7 @@ func Connect(workerList []string) {
 			Fatalf("Wrong number of instances in workerList")
 	}
 
-	addrs = workerList
-	for _, addr := range addrs {
+	for _, addr := range workerList {
 		if len(addr) == 0 {
 			continue
 		}
@@ -73,7 +71,7 @@ func ProcessTaskOverNetwork(qu []byte) (result []byte, rerr error) {
 	attr := string(q.Attr())
 	idx := farm.Fingerprint64([]byte(attr)) % numInstances
 
-	runHere := false
+	var runHere bool = false
 	if attr == "_xid_" || attr == "_uid_" {
 		idx = 0
 		runHere = (instanceIdx == 0)
@@ -86,7 +84,7 @@ func ProcessTaskOverNetwork(qu []byte) (result []byte, rerr error) {
 	}
 
 	pool := pools[idx]
-	addr := addrs[idx]
+	addr := pool.Addr
 	query := new(conn.Query)
 	query.Data = qu
 	reply := new(conn.Reply)
-- 
GitLab