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

Skip afterUid after decoder seek #3149

Merged
merged 15 commits into from
Apr 12, 2019

Conversation

srfrog
Copy link
Contributor

@srfrog srfrog commented Mar 16, 2019

When using pagination, both at root and children, the pagination results include the uid specified in after clause. This change fixes the posting list iterator by skipping the afterUid from the unpacked uid list, to yield the correct result.

Closes #3109


This change is Reviewable

@srfrog srfrog requested a review from a team March 16, 2019 00:08
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.

Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @srfrog)


posting/list.go, line 106 at r2 (raw file):

	// The decoder Seek includes afterUid in uids, we must skip it to iterate correctly.
	if it.Valid() && it.uids[0] == afterUid {

Can you add tests for some edge cases. Like if you put after to math.Maxuint64, etc. what happens?

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.

Reviewable status: 0 of 3 files reviewed, 2 unresolved discussions (waiting on @srfrog)


posting/list.go, line 290 at r2 (raw file):

	}

	return l.iterate(txn.StartTs, 0, func(obj *pb.Posting) error {

Also, the right place to do this would be in iterate function. Because we might have the UID come in from a mutation as well. In which case, it would still get output.

Also, can you add which PR caused the breakage in the first place? So, the previous behavior (before v1.0.10) can be understood -- because it used to work before apparently.

srfrog added 5 commits March 15, 2019 18:43
The whence value indicates how to use the uid offset with Seek.
Whence can be SeekStart (0) or SeekCurrent (1). SeekStart will
return the list including the offset. SeekCurrent returns values
after the offset.
@MichelDiz
Copy link
Contributor

I've tested this PR and is working to #3109

@srfrog srfrog added the kind/maintenance Maintenance tasks, such as refactoring, with no impact in features. label Mar 26, 2019
@srfrog srfrog closed this Apr 9, 2019
@srfrog srfrog deleted the srfrog/issue-3109_pagination_after_includes_uid branch April 9, 2019 19:21
@srfrog srfrog restored the srfrog/issue-3109_pagination_after_includes_uid branch April 10, 2019 04:21
@srfrog srfrog reopened this Apr 10, 2019
@srfrog srfrog requested a review from a team April 10, 2019 17:24
Copy link
Contributor

@codexnull codexnull left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 3 files at r1, 5 of 6 files at r3.
Reviewable status: 7 of 8 files reviewed, 3 unresolved discussions (waiting on @srfrog)


codec/codec_test.go, line 93 at r3 (raw file):

		{in: 10000, out: 10000, whence: SeekStart},
		{in: 9999, out: 10000, whence: SeekCurrent},
	}

Is there a reason there are no tests for SeekEnd?

Copy link
Contributor Author

@srfrog srfrog left a 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, 3 unresolved discussions (waiting on @codexnull and @srfrog)


codec/codec_test.go, line 93 at r3 (raw file):

Previously, codexnull (Javier Alvarado) wrote…

Is there a reason there are no tests for SeekEnd?

I haven't implemented it yet. First I wanted to know if this API change is acceptable.

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 2 of 3 files at r1, 6 of 6 files at r3.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @codexnull and @srfrog)


algo/uidlist.go, line 47 at r3 (raw file):

	}
	dec := codec.Decoder{Pack: pack}
	dec.Seek(afterUID, codec.SeekStart)

Is this the right behavior? Do we have tests which can check for this edge case?


codec/codec.go, line 128 at r3 (raw file):

		return (whence == SeekStart && pack.Blocks[i].Base >= uid) ||
			(whence == SeekCurrent && pack.Blocks[i].Base > uid)
	})

The SeekStart or SeekCurrent can be done after sort.Search. And sort.Search can use >=. That'd be cheaper computationally speaking (which makes a difference here).


codec/codec.go, line 148 at r3 (raw file):

	uidx := sort.Search(len(d.uids), func(i int) bool {
		return (whence == SeekStart && d.uids[i] >= uid) ||
			(whence == SeekCurrent && d.uids[i] > uid)

Same here.

Copy link
Contributor Author

@srfrog srfrog left a comment

Choose a reason for hiding this comment

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

Reviewable status: 6 of 8 files reviewed, 6 unresolved discussions (waiting on @codexnull and @manishrjain)


algo/uidlist.go, line 47 at r3 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Is this the right behavior? Do we have tests which can check for this edge case?

Done.


codec/codec.go, line 128 at r3 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

The SeekStart or SeekCurrent can be done after sort.Search. And sort.Search can use >=. That'd be cheaper computationally speaking (which makes a difference here).

Done.


codec/codec.go, line 148 at r3 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Same here.

Done.


posting/list.go, line 106 at r2 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Can you add tests for some edge cases. Like if you put after to math.Maxuint64, etc. what happens?

Done.


posting/list.go, line 290 at r2 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Also, the right place to do this would be in iterate function. Because we might have the UID come in from a mutation as well. In which case, it would still get output.

Also, can you add which PR caused the breakage in the first place? So, the previous behavior (before v1.0.10) can be understood -- because it used to work before apparently.

The offending PR was #2719
Basically this has been broken since then.

Copy link
Contributor

@codexnull codexnull left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r4.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @manishrjain and @srfrog)


codec/codec.go, line 32 at r4 (raw file):

	SeekStart   = 0 // seek relative to the origin of the list (inclusive)
	SeekCurrent = 1 // seek relative to the current offset
	SeekEnd     = 2 // seek relative to the end

If SeekEnd is not implemented can you remove it so that someone doesn't try to use it? Looks like right now because of the switch statements it will result in SeekStart bahavior.

Copy link
Contributor

@codexnull codexnull left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @manishrjain and @srfrog)


codec/codec.go, line 134 at r4 (raw file):

		default: // SeekStart
			f = func(i int) bool { return pack.Blocks[i].Base >= uid }
		}

Since when is a plain int, it could be any number. I think it would be better to check explicitly for only the allowed values and flag anything else as a logic error in the code. It seems wrong that a whence value of -1 starts seeking at the start of the list.

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.

Once you have approval from @codexnull , you can merge.

Reviewed 2 of 2 files at r4.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @srfrog)

srfrog added 2 commits April 11, 2019 13:29
SeekEnd is future functionality that we don't need right now.
Copy link
Contributor Author

@srfrog srfrog left a comment

Choose a reason for hiding this comment

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

Reviewable status: 6 of 8 files reviewed, 2 unresolved discussions (waiting on @codexnull and @manishrjain)


codec/codec.go, line 32 at r4 (raw file):

Previously, codexnull (Javier Alvarado) wrote…

If SeekEnd is not implemented can you remove it so that someone doesn't try to use it? Looks like right now because of the switch statements it will result in SeekStart bahavior.

Done.


codec/codec.go, line 134 at r4 (raw file):

Previously, codexnull (Javier Alvarado) wrote…

Since when is a plain int, it could be any number. I think it would be better to check explicitly for only the allowed values and flag anything else as a logic error in the code. It seems wrong that a whence value of -1 starts seeking at the start of the list.

Done.

Copy link
Contributor

@codexnull codexnull 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 2 of 2 files at r5.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@srfrog srfrog merged commit 501e1a6 into master Apr 12, 2019
@srfrog srfrog deleted the srfrog/issue-3109_pagination_after_includes_uid branch April 12, 2019 17:08
dna2github pushed a commit to dna2fork/dgraph that referenced this pull request Jul 19, 2019
* codec/codec.go: add whence to Seek

The whence value indicates how to use the uid offset with Seek.
Whence can be SeekStart (0) or SeekCurrent (1). SeekStart will
return the list including the offset. SeekCurrent returns values
after the offset.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/maintenance Maintenance tasks, such as refactoring, with no impact in features.
Development

Successfully merging this pull request may close these issues.

Bug: "After" func from Pagination started to miss behave since v1.0.10.
4 participants