-
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
Use one atomic variable to generate blank node ids for json objects #3795
Conversation
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.
@gitlw 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.
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 3 files at r1.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @gitlw)
chunker/json_parser.go, line 277 at r1 (raw file):
// GetNextIdx is only used for testing func getNextIdx() uint64 {
getNextBlank()
return string. Also, at process start, generate a random int of 4 bytes. And the total string should be:
_:dg.%d.%d
. The first int is the process level int. The second is the idx by atomic.
chunker/json_parser.go, line 278 at r1 (raw file):
// GetNextIdx is only used for testing func getNextIdx() uint64 { return atomic.LoadUint64(&nextIdx)
return atomic.AddUint64(&nextIdx, 1)
chunker/json_parser.go, line 326 at r1 (raw file):
idx := atomic.LoadUint64(&nextIdx) atomic.AddUint64(&nextIdx, 1)
No need for this.
chunker/json_parser.go, line 328 at r1 (raw file):
atomic.AddUint64(&nextIdx, 1) mr.uid = fmt.Sprintf("_:blank-%d", idx)
Directly use getNextIdx() here.
chunker/json_parser_test.go, line 145 at r1 (raw file):
require.Equal(t, 6, len(nq)) aliceId := fmt.Sprintf("_:blank-%d", baseIdx)
aliceId := getNextBlank()
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.
Have a question primarily on the use of the atomic add and a couple other minor suggestions.
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.
Reviewed 3 of 3 files at r2.
Reviewable status: all files reviewed, 12 unresolved discussions (waiting on @gitlw)
chunker/json_parser.go, line 273 at r2 (raw file):
// nextIdx is the index that is used to generate blank node ids for a json map object // when the map object does not have a "uid" field
minor: period.
chunker/json_parser.go, line 274 at r2 (raw file):
// nextIdx is the index that is used to generate blank node ids for a json map object // when the map object does not have a "uid" field // it should only be accessed through the atomic APIs
minor: period and uppercase.
chunker/json_parser.go, line 277 at r2 (raw file):
var nextIdx uint64 // randomId will be used to generate blank node ids
minor: period and uppercase.
chunker/json_parser_test.go, line 95 at r2 (raw file):
} type Experiment struct {
maybe call this Test?
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 3 files at r2.
Reviewable status: all files reviewed, 11 unresolved discussions (waiting on @gitlw and @pullrequest[bot])
chunker/json_parser.go, line 326 at r1 (raw file):
Previously, pullrequest[bot] wrote…
Is it possible that between the
LoadUint64
and theAddUint64
here that anotherAddUint64
has already come in on another thread/goroutine? This might lead to some cases having duplicateidx
values used across concurrent access, unless that is okay?It looks like
AddUint64
returns the new value so you could potentially drop theLoadUint64
altogether and just use the new returned value to inferidx
at the time of the increment. Eg:idx := atomic.AddUint64(&nextIdx, 1) - 1
Nice catch. I had the same comment.
chunker/json_parser_test.go, line 84 at r2 (raw file):
ctx := context.Background() require.NoError(exp.t, dg.Alter(ctx, &api.Operation{DropAll: true}), "drop all failed") require.NoError(exp.t, dg.Alter(ctx, &api.Operation{Schema: exp.schema}), "schema change failed")
100 chars.
This fixes an example that used the auto-generated blank node name "blank-0". Auto-generated blank node names have changed with hypermodeinc/dgraph#3795. The test now sets the blank node name and uses that instead of relying on Dgraph's auto-generated blank node name in the mutation response. Note: This example isn't configured to run as a Go test because "// Output:" is intentionally omitted for this example. As indicated in the comment above the last line, the output is considered unordered for list schema types. This could be made as a runnable test by printing out the individual edge values and using the "Unordered output:" check instead of the raw JSON response.
This change is