Skip to content

Commit

Permalink
Allow the normalize limit to be changed via a flag. (#3490)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmr authored May 30, 2019
1 parent 1e47988 commit ff5ee1e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 5 additions & 1 deletion dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ 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.")
flag.Uint64("normalize_node_limit", 1e4,
"Limit for the maximum number of nodes that can be returned in a query that uses the "+
"normalize directive.")

// TLS configurations
x.RegisterTLSFlags(flag)
Expand Down Expand Up @@ -472,6 +475,7 @@ func run() {
x.Config.DebugMode = Alpha.Conf.GetBool("debugmode")
x.Config.PortOffset = Alpha.Conf.GetInt("port_offset")
x.Config.QueryEdgeLimit = cast.ToUint64(Alpha.Conf.GetString("query_edge_limit"))
x.Config.NormalizeNodeLimit = cast.ToInt(Alpha.Conf.GetString("normalize_node_limit"))

x.PrintVersion()

Expand Down
8 changes: 2 additions & 6 deletions query/outputnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ import (
"github.com/dgraph-io/dgraph/x"
)

const (
normalizeLimit = 10000
)

// ToJson converts the list of subgraph into a JSON response by calling toFastJSON.
func ToJson(l *Latency, sgl []*SubGraph) ([]byte, error) {
sgr := &SubGraph{}
Expand Down Expand Up @@ -277,8 +273,8 @@ func merge(parent [][]*fastJsonNode, child [][]*fastJsonNode) ([][]*fastJsonNode
for _, pa := range parent {
for _, ca := range child {
cnt += len(pa) + len(ca)
if cnt > normalizeLimit {
return nil, x.Errorf("Couldn't evaluate @normalize directive - to many results")
if cnt > x.Config.NormalizeNodeLimit {
return nil, x.Errorf("Couldn't evaluate @normalize directive - too many results")
}
list := make([]*fastJsonNode, 0, len(pa)+len(ca))
list = append(list, pa...)
Expand Down
7 changes: 7 additions & 0 deletions query/outputnode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/dgraph-io/dgraph/types"
"github.com/dgraph-io/dgraph/x"
)

func makeFastJsonNode() *fastJsonNode {
Expand Down Expand Up @@ -59,6 +60,9 @@ func TestEncodeMemory(t *testing.T) {
}

func TestNormalizeJSONLimit(t *testing.T) {
// Set default normalize limit.
x.Config.NormalizeNodeLimit = 1e4

if testing.Short() {
t.Skip("Skipping TestNormalizeJSONLimit")
}
Expand Down Expand Up @@ -92,6 +96,9 @@ func TestNormalizeJSONLimit(t *testing.T) {
}

func TestNormalizeJSONUid1(t *testing.T) {
// Set default normalize limit.
x.Config.NormalizeNodeLimit = 1e4

n := (&fastJsonNode{}).New("root")
require.NotNil(t, n)
child1 := n.New("child1")
Expand Down
2 changes: 2 additions & 0 deletions x/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Options struct {
DebugMode bool
PortOffset int
QueryEdgeLimit uint64
// NormalizeNodeLimit is the maximum number of nodes allowed in a normalize query.
NormalizeNodeLimit int
}

var Config Options

0 comments on commit ff5ee1e

Please sign in to comment.