Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update query_edge_limit config option info and error message. #2979

Merged
merged 9 commits into from
Feb 15, 2019
2 changes: 1 addition & 1 deletion dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ they form a Raft group and provide synchronous replication.

flag.Uint64("query_edge_limit", 1e6,
"Limit for the maximum number of edges that can be returned in a query."+
" This is only useful for shortest path queries.")
" This applies to shortest path and recursive queries.")

// TLS configurations
x.RegisterTLSFlags(flag)
Expand Down
39 changes: 38 additions & 1 deletion query/query3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/schema"
"github.com/dgraph-io/dgraph/types"
"github.com/dgraph-io/dgraph/x"
"github.com/stretchr/testify/require"
)

func TestRecurseError(t *testing.T) {

query := `
{
me(func: uid(0x01)) @recurse(loop: true) {
Expand All @@ -45,6 +45,25 @@ func TestRecurseError(t *testing.T) {
require.Contains(t, err.Error(), "Depth must be > 0 when loop is true for recurse query.")
}

func TestRecurseEdgeLimitError(t *testing.T) {
// HACK: Set this flag in the external test cluster when query tests are migrated to
// use it.
defer func(prev uint64) { x.Config.QueryEdgeLimit = prev }(x.Config.QueryEdgeLimit)
x.Config.QueryEdgeLimit = 5
query := `
{
me(func: uid(0x01)) @recurse(loop: true, depth: 2) {
friend
name
}
}`

ctx := defaultContext()
_, err := processToFastJsonCtxVars(t, query, ctx, nil)
require.Error(t, err)
require.Contains(t, err.Error(), "Exceeded query edge limit")
}

func TestRecurseQuery(t *testing.T) {

query := `
Expand Down Expand Up @@ -259,6 +278,24 @@ func TestShortestPath_ExpandError(t *testing.T) {
require.Error(t, err)
}

func TestShortestPath_EdgeLimitError(t *testing.T) {
// HACK: Set this flag in the external test cluster when query tests are migrated to
// use it.
defer func(prev uint64) { x.Config.QueryEdgeLimit = prev }(x.Config.QueryEdgeLimit)
x.Config.QueryEdgeLimit = 5
query := `
{
shortest(from:0x01, to:101) {
friend
}
}`

ctx := defaultContext()
_, err := processToFastJsonCtxVars(t, query, ctx, nil)
require.Error(t, err)
require.Contains(t, err.Error(), "Exceeded query edge limit")
}

func TestShortestPath_NoPath(t *testing.T) {

query := `
Expand Down
5 changes: 3 additions & 2 deletions query/recurse.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ func (start *SubGraph) expandRecurse(ctx context.Context, maxDepth uint64) error
}

if numEdges > x.Config.QueryEdgeLimit {
// If we've seen too many nodes, stop the query.
return ErrTooBig
// If we've seen too many edges, stop the query.
return x.Errorf("Exceeded query edge limit = %v. Found %v edges.",
x.Config.QueryEdgeLimit, numEdges)
}

if len(out) == 0 {
Expand Down
14 changes: 5 additions & 9 deletions query/shortest.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var pathPool = sync.Pool{
}

var ErrStop = x.Errorf("STOP")
var ErrTooBig = x.Errorf("Query exceeded memory limit. Please modify the query")
var ErrFacet = x.Errorf("Skip the edge")

type priorityQueue []*Item
Expand Down Expand Up @@ -203,8 +202,9 @@ func (sg *SubGraph) expandOut(ctx context.Context,
}

if numEdges > x.Config.QueryEdgeLimit {
// If we've seen too many nodes, stop the query.
rch <- ErrTooBig
// If we've seen too many edges, stop the query.
rch <- x.Errorf("Exceeded query edge limit = %v. Found %v edges.",
x.Config.QueryEdgeLimit, numEdges)
return
}

Expand Down Expand Up @@ -315,9 +315,7 @@ func KShortestPath(ctx context.Context, sg *SubGraph) ([]*SubGraph, error) {
select {
case err = <-expandErr:
if err != nil {
if err == ErrTooBig {
return nil, err
} else if err == ErrStop {
if err == ErrStop {
stopExpansion = true
} else {
return nil, err
Expand Down Expand Up @@ -474,9 +472,7 @@ func ShortestPath(ctx context.Context, sg *SubGraph) ([]*SubGraph, error) {
select {
case err = <-expandErr:
if err != nil {
if err == ErrTooBig {
return nil, err
} else if err == ErrStop {
if err == ErrStop {
stopExpansion = true
} else {
return nil, err
Expand Down