Skip to content
Snippets Groups Projects
Commit 0d4dbd41 authored by Pawan Rawal's avatar Pawan Rawal
Browse files

Formatting changes

1. Port flag is now an integer. Client runs on port + 1
2. Made changes to README.md and testrun.sh to reflect this change.
3. Renamed variables
parent 87eae203
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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() {
......
......@@ -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")
}
}
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" &
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment