From 911d8b32595da06d07f6d6f460babfbd182c6df5 Mon Sep 17 00:00:00 2001
From: Ashwin <ashwin2007ray@gmail.com>
Date: Fri, 26 Feb 2016 16:28:37 +1100
Subject: [PATCH] Moved worker flag to server, removed numInstance flag

---
 query/query_test.go   |  4 ++--
 server/main.go        | 11 +++++++----
 server/main_test.go   |  2 +-
 worker/worker.go      |  8 +++-----
 worker/worker_test.go |  2 +-
 5 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/query/query_test.go b/query/query_test.go
index 67488dd8..397bcaa0 100644
--- a/query/query_test.go
+++ b/query/query_test.go
@@ -103,7 +103,7 @@ func TestNewGraph(t *testing.T) {
 		t.Error(err)
 	}
 
-	worker.Init(ps, nil)
+	worker.Init(ps, nil, nil)
 
 	uo := flatbuffers.GetUOffsetT(sg.result)
 	r := new(task.Result)
@@ -134,7 +134,7 @@ func populateGraph(t *testing.T) (string, *store.Store) {
 	ps := new(store.Store)
 	ps.Init(dir)
 
-	worker.Init(ps, nil)
+	worker.Init(ps, nil, nil)
 
 	clog := commit.NewLogger(dir, "mutations", 50<<20)
 	clog.Init()
diff --git a/server/main.go b/server/main.go
index 174ccd33..1200e766 100644
--- a/server/main.go
+++ b/server/main.go
@@ -22,6 +22,7 @@ import (
 	"io/ioutil"
 	"net/http"
 	"runtime"
+	"strings"
 	"time"
 
 	"github.com/Sirupsen/logrus"
@@ -45,8 +46,8 @@ var numcpu = flag.Int("numCpu", runtime.NumCPU(),
 	"Number of cores to be used by the process")
 var instanceIdx = flag.Uint64("instanceIdx", 0,
 	"serves only entities whose Fingerprint % numInstance == instanceIdx.")
-var numInstances = flag.Uint64("numInstances", 1,
-	"Total number of server instances")
+var workers = flag.String("workers", "",
+	"Comma separated list of IP addresses of workers")
 
 func addCorsHeaders(w http.ResponseWriter) {
 	w.Header().Set("Access-Control-Allow-Origin", "*")
@@ -142,16 +143,18 @@ func main() {
 	clog.Init()
 	defer clog.Close()
 
+	addrs := strings.Split(*workers, ",")
+
 	posting.Init(clog)
 	if *instanceIdx != 0 {
-		worker.Init(ps, nil)
+		worker.Init(ps, nil, addrs)
 		uid.Init(nil)
 	} else {
 		uidStore := new(store.Store)
 		uidStore.Init(*uidDir)
 		defer uidStore.Close()
 		// Only server instance 0 will have uidStore
-		worker.Init(ps, uidStore)
+		worker.Init(ps, uidStore, addrs)
 		uid.Init(uidStore)
 	}
 
diff --git a/server/main_test.go b/server/main_test.go
index 5e6a9f81..78c20da9 100644
--- a/server/main_test.go
+++ b/server/main_test.go
@@ -62,7 +62,7 @@ func prepare() (dir1, dir2 string, ps *store.Store, clog *commit.Logger, rerr er
 	clog.Init()
 
 	posting.Init(clog)
-	worker.Init(ps, nil)
+	worker.Init(ps, nil, nil)
 	uid.Init(ps)
 	loader.Init(ps, ps)
 
diff --git a/worker/worker.go b/worker/worker.go
index e412aaf8..20ee65a8 100644
--- a/worker/worker.go
+++ b/worker/worker.go
@@ -5,7 +5,6 @@ import (
 	"io"
 	"net"
 	"net/rpc"
-	"strings"
 
 	"github.com/dgraph-io/dgraph/conn"
 	"github.com/dgraph-io/dgraph/posting"
@@ -15,18 +14,18 @@ import (
 	"github.com/google/flatbuffers/go"
 )
 
-var workers = flag.String("workers", "",
-	"Comma separated list of IP addresses of workers")
 var workerPort = flag.String("workerport", ":12345",
 	"Port used by worker for internal communication.")
 
 var glog = x.Log("worker")
 var dataStore, xiduidStore *store.Store
 var pools []*conn.Pool
+var addrs []string
 
-func Init(ps, xuStore *store.Store) {
+func Init(ps, xuStore *store.Store, workerList []string) {
 	dataStore = ps
 	xiduidStore = xuStore
+	addrs = workerList
 }
 
 func Connect() {
@@ -38,7 +37,6 @@ func Connect() {
 		glog.Fatal(err)
 	}
 
-	addrs := strings.Split(*workers, ",")
 	for _, addr := range addrs {
 		if len(addr) == 0 {
 			continue
diff --git a/worker/worker_test.go b/worker/worker_test.go
index 8d2dbc8e..35ed5684 100644
--- a/worker/worker_test.go
+++ b/worker/worker_test.go
@@ -58,7 +58,7 @@ func TestProcessTask(t *testing.T) {
 	defer clog.Close()
 
 	posting.Init(clog)
-	Init(ps, nil)
+	Init(ps, nil, nil)
 
 	edge := x.DirectedEdge{
 		ValueId:   23,
-- 
GitLab