Skip to content
Snippets Groups Projects
Commit 749b981d authored by Manish R Jain's avatar Manish R Jain
Browse files

Handle absense of mutation or query in GraphQL. Fix bugs in goroutine's...

Handle absense of mutation or query in GraphQL. Fix bugs in goroutine's variable access, and pointer assignment to mutationArray.
parent 520e8560
No related branches found
No related tags found
No related merge requests found
...@@ -88,6 +88,7 @@ func mutationHandler(mu *gql.Mutation) error { ...@@ -88,6 +88,7 @@ func mutationHandler(mu *gql.Mutation) error {
} }
} }
if err := worker.GetOrAssignUidsOverNetwork(&xidToUid); err != nil { if err := worker.GetOrAssignUidsOverNetwork(&xidToUid); err != nil {
glog.WithError(err).Error("GetOrAssignUidsOverNetwork")
return err return err
} }
...@@ -143,7 +144,20 @@ func queryHandler(w http.ResponseWriter, r *http.Request) { ...@@ -143,7 +144,20 @@ func queryHandler(w http.ResponseWriter, r *http.Request) {
x.SetStatus(w, x.E_INVALID_REQUEST, err.Error()) x.SetStatus(w, x.E_INVALID_REQUEST, err.Error())
return return
} }
mutationHandler(mu)
// If we have mutations, run them first.
if mu != nil && len(mu.Set) > 0 {
if err = mutationHandler(mu); err != nil {
glog.WithError(err).Error("While handling mutations.")
x.SetStatus(w, x.E_ERROR, err.Error())
return
}
}
if gq == nil || (gq.UID == 0 && len(gq.XID) == 0) {
x.SetStatus(w, x.E_OK, "Done")
return
}
sg, err := query.ToSubGraph(gq) sg, err := query.ToSubGraph(gq)
if err != nil { if err != nil {
...@@ -204,6 +218,10 @@ func main() { ...@@ -204,6 +218,10 @@ func main() {
addrs := strings.Split(*workers, ",") addrs := strings.Split(*workers, ",")
lenAddr := uint64(len(addrs)) lenAddr := uint64(len(addrs))
if lenAddr == 0 {
// If no worker is specified, then we're it.
lenAddr = 1
}
posting.Init(clog) posting.Init(clog)
......
package worker package worker
import ( import (
"fmt"
"sync" "sync"
"github.com/dgraph-io/dgraph/conn" "github.com/dgraph-io/dgraph/conn"
...@@ -33,6 +34,10 @@ func createXidListBuffer(xids map[string]uint64) []byte { ...@@ -33,6 +34,10 @@ func createXidListBuffer(xids map[string]uint64) []byte {
func getOrAssignUids( func getOrAssignUids(
xidList *task.XidList) (uidList []byte, rerr error) { xidList *task.XidList) (uidList []byte, rerr error) {
if xidList.XidsLength() == 0 {
return uidList, fmt.Errorf("Empty xid list")
}
wg := new(sync.WaitGroup) wg := new(sync.WaitGroup)
uids := make([]uint64, xidList.XidsLength()) uids := make([]uint64, xidList.XidsLength())
che := make(chan error, xidList.XidsLength()) che := make(chan error, xidList.XidsLength())
...@@ -40,15 +45,15 @@ func getOrAssignUids( ...@@ -40,15 +45,15 @@ func getOrAssignUids(
wg.Add(1) wg.Add(1)
xid := string(xidList.Xids(i)) xid := string(xidList.Xids(i))
go func() { go func(idx int) {
defer wg.Done() defer wg.Done()
u, err := uid.GetOrAssign(xid, 0, 1) u, err := uid.GetOrAssign(xid, 0, 1)
if err != nil { if err != nil {
che <- err che <- err
return return
} }
uids[i] = u uids[idx] = u
}() }(i)
} }
wg.Wait() wg.Wait()
close(che) close(che)
......
...@@ -42,6 +42,7 @@ func mutate(m *Mutations, left *Mutations) error { ...@@ -42,6 +42,7 @@ func mutate(m *Mutations, left *Mutations) error {
return fmt.Errorf("predicate fingerprint doesn't match this instance.") return fmt.Errorf("predicate fingerprint doesn't match this instance.")
} }
glog.WithField("edge", edge).Debug("mutate")
key := posting.Key(edge.Entity, edge.Attribute) key := posting.Key(edge.Entity, edge.Attribute)
plist := posting.GetOrCreate(key, dataStore) plist := posting.GetOrCreate(key, dataStore)
if err := plist.AddMutation(edge, posting.Set); err != nil { if err := plist.AddMutation(edge, posting.Set); err != nil {
...@@ -93,6 +94,7 @@ func MutateOverNetwork( ...@@ -93,6 +94,7 @@ func MutateOverNetwork(
mu := mutationArray[idx] mu := mutationArray[idx]
if mu == nil { if mu == nil {
mu = new(Mutations) mu = new(Mutations)
mutationArray[idx] = mu
} }
mu.Set = append(mu.Set, edge) mu.Set = append(mu.Set, edge)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment