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

Add public API with request object types #162

Merged
merged 3 commits into from
Jun 20, 2022

Conversation

oleg-jukovec
Copy link
Collaborator

This patch provides request types for part of space operations: Select, Update
and Upstream. It allows to create requests step by step. The main idea here
is too provide more extensible approach to create requests.

Part of #126

@oleg-jukovec oleg-jukovec requested a review from Totktonada April 13, 2022 07:26
@oleg-jukovec oleg-jukovec changed the title Add public API with a request object for Select/Update/Upstream Add public API with a request object for Select/Update/Upsert Apr 15, 2022
@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-126-request-object-select branch 2 times, most recently from 08d91c5 to fe3d5e3 Compare April 20, 2022 12:49
CHANGELOG.md Outdated Show resolved Hide resolved
client_tools.go Outdated Show resolved Hide resolved
@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-126-request-object-select branch 2 times, most recently from 3ce324b to 263fb81 Compare April 22, 2022 06:08
@oleg-jukovec oleg-jukovec requested a review from ligurio April 22, 2022 06:11
@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-126-request-object-select branch 3 times, most recently from ea269e8 to 3f58815 Compare April 29, 2022 12:04
@ligurio ligurio removed their request for review May 16, 2022 09:28
@oleg-jukovec oleg-jukovec dismissed ligurio’s stale review May 16, 2022 16:33

ligurio removed their request for review

@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-126-request-object-select branch 2 times, most recently from 183da38 to 017eb2a Compare May 19, 2022 15:22
@Totktonada Totktonada requested a review from vr009 May 20, 2022 10:45
@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-126-request-object-select branch from 017eb2a to 886b40f Compare May 25, 2022 06:26
Copy link

@vr009 vr009 left a comment

Choose a reason for hiding this comment

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

The patch looks good to me. Please, consider my comments.

Also there is a kind of a "rule" to add some prefix word in the commit header, like "api: add a request object for select/update/upsert". See CONTRIBUTING.md for details.

What about the implementation of request object, and it's filling with chaining methods, I like this approach. It is more comfortable, to use the constructor and other methods instead of filling the structure manually and passing it.

future.go Outdated Show resolved Hide resolved
tarantool_test.go Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
const.go Show resolved Hide resolved
@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-126-request-object-select branch 2 times, most recently from 192d807 to 3818833 Compare June 1, 2022 08:31
@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-126-request-object-select branch from 0d42a5e to ceb6678 Compare June 2, 2022 08:59
@oleg-jukovec
Copy link
Collaborator Author

oleg-jukovec commented Jun 2, 2022

I've updated the pull request. Changes:

  • add request object API for all queries
  • add Do/DoTyped/DoAsync to ConnectionPool and ConnectionMulti types
  • fix some comments

In general it's ready, but in additional, we can use Request objects in the internal implementation instead of closures:

go-tarantool/request.go

Lines 272 to 275 in d44ffa0

return future.send(conn, func(enc *msgpack.Encoder) error {
enc.EncodeMapLen(2)
return future.fillInsert(enc, spaceNo, tuple)
})

It will simplify the Request interface:

type Request interface {
	Code() int32
	BodyFunc(resolver SchemaResolver) (func(enc *msgpack.Encoder) error, error)
}

There will be no need to return a closure from BodyFunc and it can be replaced by just Body(enc *msgpack.Encoder). I like this change and I want to do this, but I would like to get some feedback first.

@oleg-jukovec oleg-jukovec changed the title Add public API with a request object for Select/Update/Upsert Add public API with request object types Jun 2, 2022
@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-126-request-object-select branch from ceb6678 to 80fe1fd Compare June 2, 2022 12:43
Copy link
Member

@Totktonada Totktonada left a comment

Choose a reason for hiding this comment

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

I think it is the nice addition!

Looks okay for me at brief glance.

request.go Outdated Show resolved Hide resolved
request.go Outdated Show resolved Hide resolved
tarantool_test.go Show resolved Hide resolved
request.go Show resolved Hide resolved
@Totktonada
Copy link
Member

I like this change and I want to do this, but I would like to get some feedback first.

I don't see any downsides in the proposed refactoring.

@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-126-request-object-select branch 2 times, most recently from 2202126 to daae235 Compare June 14, 2022 15:54
@oleg-jukovec
Copy link
Collaborator Author

oleg-jukovec commented Jun 14, 2022

I've updated the pull request. Changes:

  • Commits with request objects (Select/Update/Upsert and Insert/.../Ping) have been squashed into one.
  • Added a separate commit with refactoring. Request objects are used by an internal implementation instead of closures.

I don't see what else can be changed anymore.

Copy link
Member

@DifferentialOrange DifferentialOrange left a comment

Choose a reason for hiding this comment

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

I've reviewed some parts of this review and will review the remaining parts tomorrow. But it seems like a really useful PR.

connection.go Show resolved Hide resolved
connection.go Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-126-request-object-select branch 2 times, most recently from 200ba67 to 2d477f4 Compare June 17, 2022 12:13
Copy link
Member

@DifferentialOrange DifferentialOrange left a comment

Choose a reason for hiding this comment

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

I couldn't say I dig too deep, but it seems LGTM

request.go Outdated Show resolved Hide resolved
example_test.go Show resolved Hide resolved
connection.go Show resolved Hide resolved
@Totktonada
Copy link
Member

@oleg-jukovec Are you plan to finish any work here or it is time to proceed?

@oleg-jukovec
Copy link
Collaborator Author

@oleg-jukovec Are you plan to finish any work here or it is time to proceed?

I plan to merge it after #171 .

@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-126-request-object-select branch from 2d477f4 to 0343412 Compare June 20, 2022 12:50
This patch provides request types. It allows to create requests step
by step. The main idea here is too provide more extensible approach to
create requests.

It renames IPROTO_* constants that identify requests from
`<Name>Request` to `<Name>RequestCode` to provide names for request
types.

Part of #126
This patch provides Do, DoTyped and DoAsync functions for
ConnectionPool and ConnectionMulti types.

Part of #126
The patch is a refactoring of an internal logic. It replaces the usage
of closures to request objects to construct a request body. After the
patch all Connection.* requests use request objects inside.

Closes #126
@oleg-jukovec oleg-jukovec force-pushed the oleg-jukovec/gh-126-request-object-select branch from 0343412 to e62bd36 Compare June 20, 2022 13:36
@oleg-jukovec oleg-jukovec merged commit 7116a33 into master Jun 20, 2022
@oleg-jukovec oleg-jukovec deleted the oleg-jukovec/gh-126-request-object-select branch June 20, 2022 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants