Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dgraph
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
dgraph
Commits
557b2f9a
Commit
557b2f9a
authored
8 years ago
by
Manish R Jain
Browse files
Options
Downloads
Plain Diff
Merge pull request #76 from dgraph-io/dmuts
Set 1 min timeout on query processing
parents
019cb0f2
c455febd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
query/query.go
+28
-12
28 additions, 12 deletions
query/query.go
query/query_test.go
+3
-3
3 additions, 3 deletions
query/query_test.go
server/main.go
+2
-2
2 additions, 2 deletions
server/main.go
server/main_test.go
+3
-2
3 additions, 2 deletions
server/main_test.go
with
36 additions
and
19 deletions
query/query.go
+
28
−
12
View file @
557b2f9a
...
...
@@ -473,7 +473,9 @@ func sortedUniqueUids(r *task.Result) (sorted []uint64, rerr error) {
return
sorted
,
nil
}
func
ProcessGraph
(
sg
*
SubGraph
,
rch
chan
error
)
{
func
ProcessGraph
(
sg
*
SubGraph
,
rch
chan
error
,
td
time
.
Duration
)
{
timeout
:=
time
.
Now
()
.
Add
(
td
)
var
err
error
if
len
(
sg
.
query
)
>
0
&&
sg
.
Attr
!=
"_root_"
{
sg
.
result
,
err
=
worker
.
ProcessTaskOverNetwork
(
sg
.
query
)
...
...
@@ -515,6 +517,13 @@ func ProcessGraph(sg *SubGraph, rch chan error) {
return
}
timeleft
:=
timeout
.
Sub
(
time
.
Now
())
if
timeleft
<
0
{
glog
.
WithField
(
"attr"
,
sg
.
Attr
)
.
Error
(
"Query timeout before children"
)
rch
<-
fmt
.
Errorf
(
"Query timeout before children"
)
return
}
// Let's execute it in a tree fashion. Each SubGraph would break off
// as many goroutines as it's children; which would then recursively
// do the same thing.
...
...
@@ -523,21 +532,28 @@ func ProcessGraph(sg *SubGraph, rch chan error) {
for
i
:=
0
;
i
<
len
(
sg
.
Children
);
i
++
{
child
:=
sg
.
Children
[
i
]
child
.
query
=
createTaskQuery
(
child
.
Attr
,
sorted
)
go
ProcessGraph
(
child
,
childchan
)
go
ProcessGraph
(
child
,
childchan
,
timeleft
)
}
tchan
:=
time
.
After
(
timeleft
)
// Now get all the results back.
for
i
:=
0
;
i
<
len
(
sg
.
Children
);
i
++
{
err
=
<-
childchan
glog
.
WithFields
(
logrus
.
Fields
{
"num_children"
:
len
(
sg
.
Children
),
"index"
:
i
,
"attr"
:
sg
.
Children
[
i
]
.
Attr
,
"err"
:
err
,
})
.
Debug
(
"Reply from child"
)
if
err
!=
nil
{
x
.
Err
(
glog
,
err
)
.
Error
(
"While processing child task."
)
rch
<-
err
select
{
case
err
=
<-
childchan
:
glog
.
WithFields
(
logrus
.
Fields
{
"num_children"
:
len
(
sg
.
Children
),
"index"
:
i
,
"attr"
:
sg
.
Children
[
i
]
.
Attr
,
"err"
:
err
,
})
.
Debug
(
"Reply from child"
)
if
err
!=
nil
{
x
.
Err
(
glog
,
err
)
.
Error
(
"While processing child task."
)
rch
<-
err
return
}
case
<-
tchan
:
glog
.
WithField
(
"attr"
,
sg
.
Attr
)
.
Error
(
"Query timeout after children"
)
rch
<-
fmt
.
Errorf
(
"Query timeout after children"
)
return
}
}
...
...
This diff is collapsed.
Click to expand it.
query/query_test.go
+
3
−
3
View file @
557b2f9a
...
...
@@ -214,7 +214,7 @@ func TestProcessGraph(t *testing.T) {
}
ch
:=
make
(
chan
error
)
go
ProcessGraph
(
sg
,
ch
)
go
ProcessGraph
(
sg
,
ch
,
time
.
Minute
)
err
=
<-
ch
if
err
!=
nil
{
t
.
Error
(
err
)
...
...
@@ -306,7 +306,7 @@ func TestToJson(t *testing.T) {
}
ch
:=
make
(
chan
error
)
go
ProcessGraph
(
sg
,
ch
)
go
ProcessGraph
(
sg
,
ch
,
time
.
Minute
)
err
=
<-
ch
if
err
!=
nil
{
t
.
Error
(
err
)
...
...
@@ -347,7 +347,7 @@ func TestPreTraverse(t *testing.T) {
}
ch
:=
make
(
chan
error
)
go
ProcessGraph
(
sg
,
ch
)
go
ProcessGraph
(
sg
,
ch
,
time
.
Minute
)
err
=
<-
ch
if
err
!=
nil
{
t
.
Error
(
err
)
...
...
This diff is collapsed.
Click to expand it.
server/main.go
+
2
−
2
View file @
557b2f9a
...
...
@@ -177,7 +177,7 @@ func queryHandler(w http.ResponseWriter, r *http.Request) {
glog
.
WithField
(
"q"
,
string
(
q
))
.
Debug
(
"Query parsed."
)
rch
:=
make
(
chan
error
)
go
query
.
ProcessGraph
(
sg
,
rch
)
go
query
.
ProcessGraph
(
sg
,
rch
,
time
.
Minute
)
err
=
<-
rch
if
err
!=
nil
{
x
.
Err
(
glog
,
err
)
.
Error
(
"While executing query"
)
...
...
@@ -233,7 +233,7 @@ func (s *server) Query(ctx context.Context,
glog
.
WithField
(
"q"
,
req
.
Query
)
.
Debug
(
"Query parsed."
)
rch
:=
make
(
chan
error
)
go
query
.
ProcessGraph
(
sg
,
rch
)
go
query
.
ProcessGraph
(
sg
,
rch
,
time
.
Minute
)
err
=
<-
rch
if
err
!=
nil
{
x
.
Err
(
glog
,
err
)
.
Error
(
"While executing query"
)
...
...
This diff is collapsed.
Click to expand it.
server/main_test.go
+
3
−
2
View file @
557b2f9a
...
...
@@ -21,6 +21,7 @@ import (
"io/ioutil"
"os"
"testing"
"time"
"github.com/dgraph-io/dgraph/commit"
"github.com/dgraph-io/dgraph/gql"
...
...
@@ -158,7 +159,7 @@ func TestQuery(t *testing.T) {
}
ch
:=
make
(
chan
error
)
go
query
.
ProcessGraph
(
g
,
ch
)
go
query
.
ProcessGraph
(
g
,
ch
,
time
.
Minute
)
if
err
:=
<-
ch
;
err
!=
nil
{
t
.
Error
(
err
)
return
...
...
@@ -217,7 +218,7 @@ func BenchmarkQuery(b *testing.B) {
}
ch
:=
make
(
chan
error
)
go
query
.
ProcessGraph
(
g
,
ch
)
go
query
.
ProcessGraph
(
g
,
ch
,
time
.
Minute
)
if
err
:=
<-
ch
;
err
!=
nil
{
b
.
Error
(
err
)
return
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment