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

Paginated datastore API #1265

Merged
merged 12 commits into from
Apr 18, 2023
Merged

Paginated datastore API #1265

merged 12 commits into from
Apr 18, 2023

Conversation

jakedt
Copy link
Member

@jakedt jakedt commented Apr 16, 2023

No description provided.

@jakedt jakedt requested a review from vroldanbet April 16, 2023 01:20
@jakedt jakedt requested a review from a team as a code owner April 16, 2023 01:20
@github-actions github-actions bot added area/api v0 Affects the v0 API area/api v1 Affects the v1 API area/CLI Affects the command line area/datastore Affects the storage system area/dependencies Affects dependencies area/dispatch Affects dispatching of requests area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Apr 16, 2023
@jakedt jakedt force-pushed the paginated-datastore branch 3 times, most recently from aa6ec4c to 8edefc7 Compare April 16, 2023 01:32
Copy link
Contributor

@vroldanbet vroldanbet left a comment

Choose a reason for hiding this comment

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

This looks good to me! 💯 I mostly pointed out missing tests, and the opportunity to create a new RelationshipIterator that abstracts pagination, when pagination is not exposed to API client (e.g. streaming APIs)

internal/datastore/common/tuple.go Outdated Show resolved Hide resolved
internal/datastore/common/sql.go Outdated Show resolved Hide resolved
internal/datastore/common/cursor.go Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

we probably want to add unit tests for both modes of TupleOrder and for After

Copy link
Member Author

Choose a reason for hiding this comment

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

There are datastore tests for both modes of TupleOrder in the pagination.go test suite. Does that work, or are you thinking about something else?

internal/datastore/common/sql.go Show resolved Hide resolved
@@ -345,16 +345,99 @@ func filterFuncForFilters(
return !found
}

tpl := &core.RelationTuple{
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is memdb and all but I wonder if we can do avoid this allocation, specially if this method is to be applied over a potentially long list of tuples. Could we perhaps take the raw relationship?

Copy link
Contributor

Choose a reason for hiding this comment

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

friendly ping ☝🏻 can we make this non-allocating?

internal/datastore/memdb/readonly.go Outdated Show resolved Hide resolved
internal/services/v1/relationships.go Outdated Show resolved Hide resolved
internal/services/v1/relationships.go Outdated Show resolved Hide resolved
pkg/datastore/options/options.go Show resolved Hide resolved
internal/datastore/common/cursor.go Outdated Show resolved Hide resolved
internal/datastore/common/cursor.go Outdated Show resolved Hide resolved
internal/datastore/common/cursor.go Outdated Show resolved Hide resolved
pkg/datastore/datastore.go Outdated Show resolved Hide resolved
internal/services/v1/relationships.go Outdated Show resolved Hide resolved
@jakedt jakedt force-pushed the paginated-datastore branch 3 times, most recently from 7bdf590 to f9be65f Compare April 17, 2023 19:47
pkg/cmd/serve.go Outdated Show resolved Hide resolved
internal/services/v1/relationships.go Outdated Show resolved Hide resolved
internal/datastore/common/tuple.go Outdated Show resolved Hide resolved
ResourceType: tc.objectType,
}, options.WithLimit(&testLimit), options.WithAfter(&core.RelationTuple{}))
require.ErrorIs(err, datastore.ErrCursorsWithoutSorting)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could be a good place to also test the new paginatedIterator given it has no tests, to make sure it properly does resuming based on batchSize

Copy link
Member Author

Choose a reason for hiding this comment

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

I think of the paginated iterator as a helper written from the perspective of the datastore consumer. As such I don't think tests for it belong here. Ideally it would test using mocks. Let me see how long it will take to write that.

@@ -345,16 +345,99 @@ func filterFuncForFilters(
return !found
}

tpl := &core.RelationTuple{
Copy link
Contributor

Choose a reason for hiding this comment

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

friendly ping ☝🏻 can we make this non-allocating?

pkg/datastore/options/options.go Outdated Show resolved Hide resolved
pkg/datastore/pagination/iterator.go Show resolved Hide resolved
pkg/datastore/pagination/iterator.go Outdated Show resolved Hide resolved

// NewPaginatedIterator creates an implementation of the datastore.Iterator
// interface that internally paginates over datastore results.
func NewPaginatedIterator(
Copy link
Contributor

Choose a reason for hiding this comment

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

Does not have a test, but perhaps as I proposed in pkg/datastore/test/pagination.go, we could do integration test for the iterator there

t.Run("TestOrdering", func(t *testing.T) { OrderingTest(t, tester) })
t.Run("TestLimit", func(t *testing.T) { LimitTest(t, tester) })
t.Run("TestOrderedLimit", func(t *testing.T) { OrderedLimitTest(t, tester) })
t.Run("TestResume", func(t *testing.T) { ResumeTest(t, tester) })
Copy link
Member

Choose a reason for hiding this comment

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

Might be better to be specific here: TestOrderedQueryRels, TestResumeQueryRels, etc

@@ -77,18 +95,120 @@ func NewSchemaQueryFilterer(schema SchemaInformation, initialQuery sq.SelectBuil
}
}

func (sqf SchemaQueryFilterer) TupleOrder(order options.SortOrder) SchemaQueryFilterer {
Copy link
Member

Choose a reason for hiding this comment

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

Can we add SQL tests for this (and below)

Copy link
Contributor

@vroldanbet vroldanbet left a comment

Choose a reason for hiding this comment

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

LGTM!

@jakedt jakedt merged commit 8440f11 into main Apr 18, 2023
24 checks passed
@jakedt jakedt deleted the paginated-datastore branch April 18, 2023 19:05
@github-actions github-actions bot locked and limited conversation to collaborators Apr 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/api v0 Affects the v0 API area/api v1 Affects the v1 API area/CLI Affects the command line area/datastore Affects the storage system area/dependencies Affects dependencies area/dispatch Affects dispatching of requests area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants