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

Use one atomic variable to generate blank node ids for json objects #3795

Merged
merged 7 commits into from
Aug 14, 2019

Conversation

gitlw
Copy link

@gitlw gitlw commented Aug 13, 2019

This change is Reviewable

@gitlw gitlw requested review from manishrjain and a team as code owners August 13, 2019 01:24
Copy link

@pullrequest pullrequest bot left a 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.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 Message
The description of this pull request is blank. Adding a high-level summary will help our reviewers provide better feedback.

chunker/json_parser.go Outdated Show resolved Hide resolved
Copy link
Contributor

@manishrjain manishrjain left a 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()

Copy link

@pullrequest pullrequest bot left a 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

chunker/json_parser.go Outdated Show resolved Hide resolved
chunker/json_parser.go Outdated Show resolved Hide resolved
chunker/json_parser.go Outdated Show resolved Hide resolved
Copy link
Contributor

@martinmr martinmr left a 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?

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

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 the AddUint64 here that another AddUint64 has already come in on another thread/goroutine? This might lead to some cases having duplicate idx values used across concurrent access, unless that is okay?

It looks like AddUint64 returns the new value so you could potentially drop the LoadUint64 altogether and just use the new returned value to infer idx 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.

@manishrjain manishrjain merged commit a7271fd into master Aug 14, 2019
@manishrjain manishrjain deleted the gitlw/atomic_json_idx branch August 14, 2019 02:25
danielmai added a commit to dgraph-io/dgo that referenced this pull request Aug 28, 2019
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants