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

Allow the normalize limit to be set via a flag. #3467

Merged
merged 3 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ 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 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
flag.String("tls_dir", "", "Path to directory that has TLS certificates and keys.")
Expand Down Expand Up @@ -477,6 +480,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
6 changes: 1 addition & 5 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 @@ -282,7 +278,7 @@ func merge(parent [][]*fastJsonNode, child [][]*fastJsonNode) ([][]*fastJsonNode
for _, pa := range parent {
for _, ca := range child {
cnt += len(pa) + len(ca)
if cnt > normalizeLimit {
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))
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 = 1e5

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 = 1e5

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 @@ -25,6 +25,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
Expand Down