diff --git a/README.md b/README.md index af28e1df74b9e0443ab37d1b4d087bbd863babb1..616e5065ba26c7bc11f06340ca872f6dfed6aabe 100644 --- a/README.md +++ b/README.md @@ -88,14 +88,14 @@ $ tar -xzvf postings.tar.gz -C $DIR ``` For quick testing, you can bring up 3 different processes of DGraph. You can of course, also set this up across multiple servers. ``` -go build . && ./server --instanceIdx 0 --mutations $DIR/m0 --port "8080" --postings $DIR/p0 --workers ":12345,:12346,:12347" --uids $DIR/uasync.final --workerport ":12345" & -go build . && ./server --instanceIdx 1 --mutations $DIR/m1 --port "8081" --postings $DIR/p1 --workers ":12345,:12346,:12347" --workerport ":12346" & -go build . && ./server --instanceIdx 2 --mutations $DIR/m2 --port "8082" --postings $DIR/p2 --workers ":12345,:12346,:12347" --workerport ":12347" & +go build . && ./server --instanceIdx 0 --mutations $DIR/m0 --port 8080 --postings $DIR/p0 --workers ":12345,:12346,:12347" --uids $DIR/uasync.final --workerport ":12345" & +go build . && ./server --instanceIdx 1 --mutations $DIR/m1 --port 8082 --postings $DIR/p1 --workers ":12345,:12346,:12347" --workerport ":12346" & +go build . && ./server --instanceIdx 2 --mutations $DIR/m2 --port 8084 --postings $DIR/p2 --workers ":12345,:12346,:12347" --workerport ":12347" & ``` Now you can run any of the queries mentioned in [Test Queries](https://github.com/dgraph-io/dgraph/wiki/Test-Queries). You can hit any of the 3 processes, they'll produce the same results. -`curl localhost:8081/query -XPOST -d '{}'` +`curl localhost:8080/query -XPOST -d '{}'` ## Installation Best way to do this is to refer to [Dockerfile](Dockerfile), which has the most complete diff --git a/client/go/main.go b/client/go/main.go index 64ad9644bd7da7ad38fc07360ddef6256083597c..e671f2822afb6d3260d5ffe7d843c656b2a3f9e8 100644 --- a/client/go/main.go +++ b/client/go/main.go @@ -28,7 +28,7 @@ import ( ) var glog = x.Log("client") -var ip = flag.String("ip", "127.0.0.1:9090", "Port to communicate with server") +var ip = flag.String("ip", "127.0.0.1:8081", "Port to communicate with server") var query = flag.String("query", "", "Query sent to the server") func main() { diff --git a/server/main.go b/server/main.go index 6c7e93295f0874fee7cff778f5fc43d33a580927..bbaafdfa70d7c1f76886311880e02b6785adedcc 100644 --- a/server/main.go +++ b/server/main.go @@ -49,9 +49,7 @@ var glog = x.Log("server") var postingDir = flag.String("postings", "", "Directory to store posting lists") var uidDir = flag.String("uids", "", "XID UID posting lists directory") var mutationDir = flag.String("mutations", "", "Directory to store mutations") -var port = flag.String("port", "8080", "Port to run server on.") -var clientPort = flag.String("clientPort", "9090", - "Port used to communicate with client.") +var port = flag.Int("port", 8080, "Port to run server on.") var numcpu = flag.Int("numCpu", runtime.NumCPU(), "Number of cores to be used by the process") var instanceIdx = flag.Uint64("instanceIdx", 0, @@ -209,45 +207,45 @@ type server struct{} // This method is used to execute the query and return the response to the // client as a protocol buffer message. func (s *server) Query(ctx context.Context, - r *pb.GraphRequest) (*pb.GraphResponse, error) { - gr := *pb.GraphResponse{} - if len(r.Query) == 0 { + req *pb.GraphRequest) (*pb.GraphResponse, error) { + resp := new(pb.GraphResponse) + if len(req.Query) == 0 { glog.Error("While reading query") - return gr, fmt.Errorf("Empty query") + return resp, fmt.Errorf("Empty query") } // TODO(pawan): Refactor query parsing and graph processing code to a common // function used by Query and queryHandler - glog.WithField("q", r.Query).Debug("Query received.") - gq, _, err := gql.Parse(r.Query) + glog.WithField("q", req.Query).Debug("Query received.") + gq, _, err := gql.Parse(req.Query) if err != nil { x.Err(glog, err).Error("While parsing query") - return gr, err + return resp, err } sg, err := query.ToSubGraph(gq) if err != nil { x.Err(glog, err).Error("While conversion to internal format") - return gr, err + return resp, err } - glog.WithField("q", r.Query).Debug("Query parsed.") + glog.WithField("q", req.Query).Debug("Query parsed.") rch := make(chan error) go query.ProcessGraph(sg, rch) err = <-rch if err != nil { x.Err(glog, err).Error("While executing query") - return gr, err + return resp, err } - glog.WithField("q", r.Query).Debug("Graph processed.") - gr, err = sg.PreTraverse() + glog.WithField("q", req.Query).Debug("Graph processed.") + resp, err = sg.PreTraverse() if err != nil { x.Err(glog, err).Error("While converting to protocol buffer.") - return gr, err + return resp, err } - return gr, err + return resp, err } // This function register a DGraph grpc server on the address, which is used @@ -276,9 +274,11 @@ func main() { logrus.SetLevel(logrus.InfoLevel) numCpus := *numcpu prev := runtime.GOMAXPROCS(numCpus) - glog.WithField("num_cpu", numCpus). - WithField("prev_maxprocs", prev). + glog.WithField("num_cpu", numCpus).WithField("prev_maxprocs", prev). Info("Set max procs to num cpus") + if *port%2 != 0 { + glog.Fatalf("Port should be an even number: %v", *port) + } ps := new(store.Store) ps.Init(*postingDir) @@ -297,7 +297,6 @@ func main() { } posting.Init(clog) - if *instanceIdx != 0 { worker.Init(ps, nil, *instanceIdx, lenAddr) uid.Init(nil) @@ -311,12 +310,12 @@ func main() { } worker.Connect(addrs) - - runGrpcServer(":" + *clientPort) + // Grpc server runs on (port + 1) + runGrpcServer(fmt.Sprintf(":%d", *port+1)) http.HandleFunc("/query", queryHandler) glog.WithField("port", *port).Info("Listening for requests...") - if err := http.ListenAndServe(":"+*port, nil); err != nil { + if err := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil); err != nil { x.Err(glog, err).Fatal("ListenAndServe") } } diff --git a/server/testrun.sh b/server/testrun.sh index d79aa9611205086bb0570c5e2153bccd64cbed76..9dbfd74ed4f4b4ad537fab1388304f7b78591700 100644 --- a/server/testrun.sh +++ b/server/testrun.sh @@ -1,4 +1,4 @@ dir="/dgraph" -go build . && ./server --instanceIdx 0 --mutations $dir/m0 --port "8080" --postings $dir/p0 --workers ":12345,:12346,:12347" --uids $dir/uasync.final --workerport ":12345" & -go build . && ./server --instanceIdx 1 --mutations $dir/m1 --port "8081" --postings $dir/p1 --workers ":12345,:12346,:12347" --workerport ":12346" & -go build . && ./server --instanceIdx 2 --mutations $dir/m2 --port "8082" --postings $dir/p2 --workers ":12345,:12346,:12347" --workerport ":12347" & +go build . && ./server --instanceIdx 0 --mutations $dir/m0 --port 8080 --postings $dir/p0 --workers ":12345,:12346,:12347" --uids $dir/uasync.final --workerport ":12345" & +go build . && ./server --instanceIdx 1 --mutations $dir/m1 --port 8082 --postings $dir/p1 --workers ":12345,:12346,:12347" --workerport ":12346" & +go build . && ./server --instanceIdx 2 --mutations $dir/m2 --port 8084 --postings $dir/p2 --workers ":12345,:12346,:12347" --workerport ":12347" &