-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Verify that all the fields in a type exist in the schema. #4114
Conversation
Also, move the existing verification to the same place so that all type verification is done at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ A review job has been created and sent to the PullRequest network.
@martinmr you can click here to see the review status or cancel the code review job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes here look pretty good to me, left a few comments inline. One specific question is around the ctx.Background()
being used. I just wanted to verify this wasn't supposed to extend from the ctx
being passed in or have some sort of timeout to it.
Reviewed with ❤️ by PullRequest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 7 files reviewed, 8 unresolved discussions (waiting on @manishrjain, @martinmr, and @pawanrawal)
worker/mutation.go, line 573 at r3 (raw file):
fields := make([]string, len(t.Fields)) for i, field := range t.Fields { fields[i] = field.Predicate
If some preds are supplied in the request, i.e. are in the preds
map, then you don't really need to fetch the schema for them.
worker/mutation.go, line 575 at r3 (raw file):
fields[i] = field.Predicate } schs, err := GetSchemaOverNetwork(ctx, &pb.SchemaRequest{Predicates: fields})
This network call could be optimized and be done only once after collecting fields from all types.
worker/mutation.go, line 593 at r3 (raw file):
if !inSchema && !inRequest { return errors.Errorf( "Schema does not contain a matching predicate for field %s in type %s",
Do we have a test case for testing this scenario?
worker/mutation.go, line 605 at r3 (raw file):
if field.ValueType == pb.Posting_OBJECT && len(field.ObjectTypeName) == 0 { return errors.Errorf( "Field with value type OBJECT must specify the name of the object type")
Error test cases for these scenarios would be good to have so that if we break them tomorrow, we know that we did.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 7 files reviewed, 8 unresolved discussions (waiting on @golangcibot, @manishrjain, @pawanrawal, and @pullrequest[bot])
worker/mutation.go, line 578 at r1 (raw file):
Previously, golangcibot (Bot from GolangCI) wrote…
Error return value of
errors.Errorf
is not checked (fromerrcheck
)
Done.
worker/mutation.go, line 561 at r2 (raw file):
Previously, pullrequest[bot] wrote…
you could potentially pass a size here to prevent having to re-size the map:
preds := make(map[string]struct{}, len(m.Schema))
Done.
worker/mutation.go, line 575 at r2 (raw file):
Previously, pullrequest[bot] wrote…
Should this extend from the
ctx
or is it supposed to be a disconnected context? I would consider leaving a comment inline if it is meant to be disconnected.
Done.
worker/mutation.go, line 582 at r2 (raw file):
Previously, pullrequest[bot] wrote…
Similar to above, could be worth passing the
len(schs)
here to initialize map with exact amount of space and save allocations.
Done.
worker/mutation.go, line 573 at r3 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
If some preds are supplied in the request, i.e. are in the
preds
map, then you don't really need to fetch the schema for them.
Done.
worker/mutation.go, line 575 at r3 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
This network call could be optimized and be done only once after collecting fields from all types.
Done.
worker/mutation.go, line 593 at r3 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Do we have a test case for testing this scenario?
Done.
worker/mutation.go, line 605 at r3 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Error test cases for these scenarios would be good to have so that if we break them tomorrow, we know that we did.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added an inline comment regarding error handling in the for loop.
Reviewed with ❤️ by PullRequest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apart for one change which seems to be missing
Reviewed 4 of 7 files at r1, 1 of 2 files at r3, 3 of 3 files at r4.
Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @golangcibot, @manishrjain, @martinmr, and @pullrequest[bot])
worker/mutation.go, line 575 at r3 (raw file):
Previously, martinmr (Martin Martinez Rivera) wrote…
Done.
Not sure if this is done, I was talking about collecting fields from all types and then making the network call outside after this for loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 5 of 8 files reviewed, 9 unresolved discussions (waiting on @golangcibot, @manishrjain, @pawanrawal, and @pullrequest[bot])
dgraph/cmd/alpha/run_test.go, line 1232 at r3 (raw file):
Previously, pullrequest[bot] wrote…
Not a trivial change here but this would be more readable as an enum if a refactoring comes up.
Leaving it like this for now.
systest/mutations_test.go, line 1672 at r4 (raw file):
Previously, pullrequest[bot] wrote…
This has come up in previous reviews, but I think the tick mark needs to be moved to the leftmost position. If that is not an issue, disregard.
Done. Moved tick to the previous line.
systest/mutations_test.go, line 1681 at r4 (raw file):
Previously, pullrequest[bot] wrote…
This has come up in previous reviews, but I think the tick mark needs to be moved to the leftmost position. If that is not an issue, disregard.
Done.
worker/mutation.go, line 562 at r3 (raw file):
Previously, pullrequest[bot] wrote…
What are
sup
s? Schema updates? The variable name here could be a bit more descriptive. Not entirely clear what's being articulated.
Done.
worker/mutation.go, line 575 at r3 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Not sure if this is done, I was talking about collecting fields from all types and then making the network call outside after this for loop.
Sorry, I misinterpreted what you meant in your original comment.
worker/mutation.go, line 598 at r4 (raw file):
Previously, pullrequest[bot] wrote…
Could there be an expectation of continuing here or this all or nothing? The
return
after an error says yes. The way the code is written it looks like it could also be desirable to queue up several of these errors. This may result in a better experience instead of discovering the failures 1x1.
I don't think it's possible to queue multiple errors and trying to add all errors into a single message might make the message too big so I'll keep it as is for now.
worker/mutation.go
Outdated
for _, field := range t.Fields { | ||
fieldName := field.Predicate | ||
if len(fieldName) > 0 && fieldName[0] == '~' { | ||
fieldName = fieldName[1:len(fieldName)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File is not gofmt
-ed with -s
(from gofmt
)
fieldName = fieldName[1:len(fieldName)] | |
fieldName = fieldName[1:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 3 of 7 files at r1, 1 of 2 files at r3, 1 of 3 files at r4, 3 of 3 files at r5.
Reviewable status: all files reviewed, 15 unresolved discussions (waiting on @golangcibot, @martinmr, and @pullrequest[bot])
worker/mutation.go, line 575 at r2 (raw file):
Previously, martinmr (Martin Martinez Rivera) wrote…
Done.
schemas?
worker/mutation.go, line 562 at r5 (raw file):
func verifyTypes(ctx context.Context, m *pb.Mutations) error { // Create a set of all the predicates included in this schema request. preds := make(map[string]struct{}, len(m.Schema))
reqPreds
worker/mutation.go, line 569 at r5 (raw file):
// Create a set of all the predicates already present in the schema. schemaSet := make(map[string]struct{}) fields := make([]string, 0)
var fields []string
worker/mutation.go, line 577 at r5 (raw file):
for _, field := range t.Fields { fieldName := field.Predicate if len(fieldName) > 0 && fieldName[0] == '~' {
if len(fieldName) == 0 {
continue
}
worker/mutation.go, line 590 at r5 (raw file):
schs, err := GetSchemaOverNetwork(ctx, &pb.SchemaRequest{Predicates: fields}) if err != nil { return errors.Errorf("Cannot retrieve predicate information")
Never lose the original error. Must be wrapf or similar.
worker/mutation.go, line 592 at r5 (raw file):
return errors.Errorf("Cannot retrieve predicate information") } for _, schemaNode := range schs {
Declare schemaSet just above this. As close as possible to usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 7 of 8 files reviewed, 15 unresolved discussions (waiting on @golangcibot, @manishrjain, and @pullrequest[bot])
worker/mutation.go, line 575 at r2 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
schemas?
Done
worker/mutation.go, line 562 at r5 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
reqPreds
Done.
worker/mutation.go, line 569 at r5 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
var fields []string
Done.
worker/mutation.go, line 577 at r5 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
if len(fieldName) == 0 {
continue
}
The check already exists inside the typeSanityCheck method so I've changed the code so that it's called before this line.
worker/mutation.go, line 578 at r5 (raw file):
Previously, golangcibot (Bot from GolangCI) wrote…
File is not
gofmt
-ed with-s
(fromgofmt
)fieldName = fieldName[1:]
Done.
worker/mutation.go, line 590 at r5 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
Never lose the original error. Must be wrapf or similar.
Done.
worker/mutation.go, line 592 at r5 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
Declare schemaSet just above this. As close as possible to usage.
Done.
Also, move the existing verification to the same place so that all type
verification is done at the same time.
This change is