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

Support IPROTO_PUSH messages #156

Merged
merged 2 commits into from
Jun 14, 2022
Merged

Support IPROTO_PUSH messages #156

merged 2 commits into from
Jun 14, 2022

Conversation

oleg-jukovec
Copy link
Collaborator

This patch adds support for receiving messages sent using box.session.push()
via an iterator in the manner of asynchronous case of a Lua implementation[1].

Now the calls Future.Get() and Future.GetTyped() ignore push messages, and
do not report an error.

  1. https://www.tarantool.io/ru/doc/latest/reference/reference_lua/box_session/push/

Closes #67

I'm not particularly familiar with Go. So I most likely made mistakes in some basic and idiomatic things

tarantool_test.go Outdated Show resolved Hide resolved
tarantool_test.go Show resolved Hide resolved
config.lua Outdated Show resolved Hide resolved
config.lua Outdated Show resolved Hide resolved
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 tried to run the example with "slow" function and I failed to do it successfully, even though timeout is ok. See the comment below for additional details.

response_it.go Outdated Show resolved Hide resolved
response_it.go Outdated Show resolved Hide resolved
request.go Outdated Show resolved Hide resolved
request.go Outdated Show resolved Hide resolved
request.go Outdated Show resolved Hide resolved
example_test.go Outdated Show resolved Hide resolved
example_test.go Show resolved Hide resolved
example_test.go Show resolved Hide resolved
config.lua Show resolved Hide resolved
example_test.go Show resolved Hide resolved
example_test.go Outdated Show resolved Hide resolved
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.

Thank you for your responses and fixes.

I have left some comments. There shouldn't be anything critical this time. I think it will be the last round and I'll approve the PR after we deal with these comments.

tarantool_test.go Outdated Show resolved Hide resolved
tarantool_test.go Show resolved Hide resolved
tarantool_test.go Outdated Show resolved Hide resolved
tarantool_test.go Show resolved Hide resolved
tarantool_test.go Outdated Show resolved Hide resolved
tarantool_test.go Outdated Show resolved Hide resolved
example_test.go Show resolved Hide resolved
@DifferentialOrange
Copy link
Member

BTW, we use 72-symbols limit for commit message body: https://www.tarantool.io/en/doc/latest/dev_guide/developer_guidelines/#how-to-write-a-commit-message

response_it.go Outdated
defer it.fut.mutex.RUnlock()

resp = it.nextResponse()
if it.resp == nil {
Copy link

@funny-falcon funny-falcon Apr 21, 2022

Choose a reason for hiding this comment

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

I don't get:

  • if iterator doesn't get timeout parameter
  • then it doesn't wait anything
  • therefore usually it doesn't get anything, because nextResponse sees empty fut.pushes and empty resp.

LOL
What i'm missing?

Copy link
Collaborator Author

@oleg-jukovec oleg-jukovec Apr 21, 2022

Choose a reason for hiding this comment

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

Exactly, see Lua implementation:
https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_session/push/
Lua's iterator just leave a loop if nothing to do (returns it.Next() == false in the case).

-- There is no pause because conn:call does not wait for
-- server_function to finish. The first time that we go through
-- the pairs() loop, we see the messages table is empty. Like this:
-- tarantool> messages

Choose a reason for hiding this comment

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

Go is not Lua. It doesn't need to match Lua's code exactly.
In Go one gets notifications through channels. Channels are composable.
"Polling" on it.Next() would be definitely anti-pattern in Go.

Well... I could not came with clear api now.
It doesn't look like iterator could be efficiently implemented in Go-friendly way if there is no separate method "conn.CallStream".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree that iterators are not idiomatic in Go. But we need to provide a similar interface as in Lua, which would not confuse an user. If each language implements features in its own way, it will be too difficult to translate very simple examples of code between connectors.

Maybe, but sometimes Next() is used in this context:
https://pkg.go.dev/database/sql#Rows.Next
https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#ChangeStream.Next

response_it.go Outdated Show resolved Hide resolved
request.go Outdated
@@ -12,6 +13,9 @@ type Future struct {
requestId uint32
requestCode int32
timeout time.Duration
mutex sync.RWMutex
cond *sync.Cond

Choose a reason for hiding this comment

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

Instead of (ab)using sync.Cond, you'd better

    // this doesn't consume more memory, than make(chan struct{})
    fut.ready := make(chan struct{}, 1000000000) 

And then notify about PUSH using fut.ready <- struct{}{}
This way you will need no separate goroutine to merry push notifications with timeouts and final response.
Whole iterator handling will be much simpler.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you, it's much easier.

Copy link

@funny-falcon funny-falcon left a comment

Choose a reason for hiding this comment

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

@oleg-jukovec
Copy link
Collaborator Author

BTW, we use 72-symbols limit for commit message body: https://www.tarantool.io/en/doc/latest/dev_guide/developer_guidelines/#how-to-write-a-commit-message

Oh, I'm surprised. It fixed and remembered.

connection.go Outdated Show resolved Hide resolved
connection.go Outdated Show resolved Hide resolved
example_test.go Show resolved Hide resolved
future_test.go Outdated Show resolved Hide resolved
future_test.go Outdated Show resolved Hide resolved
future_test.go Outdated Show resolved Hide resolved
future_test.go Outdated Show resolved Hide resolved
future_test.go Outdated Show resolved Hide resolved
future_test.go Outdated Show resolved Hide resolved
future_test.go Outdated Show resolved Hide resolved
future_test.go Outdated Show resolved Hide resolved
future_test.go Show resolved Hide resolved
future_test.go Show resolved Hide resolved
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.

Should be LGTM after resolving remaining comments.

Please don't forget to rebase onto master if needed (for example, when #160 will be merged) and solve all possible conflicts and warnings.

@ligurio ligurio removed their request for review May 16, 2022 09:00
@oleg-jukovec oleg-jukovec dismissed ligurio’s stale review May 16, 2022 16:32

ligurio removed their request for review

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.

AFAIR, there shouldn't be any unsolved questions, isn't it?

@oleg-jukovec
Copy link
Collaborator Author

oleg-jukovec commented May 20, 2022

AFAIR, there shouldn't be any unsolved questions, isn't it?

For me it seems ok, I only sometimes do rebase.

This is not a critical change. It just splits request.go into
request.go and future.go.
This patch adds support for receiving messages sent using
box.session.push() via an iterator in the manner of asynchronous case
of a Lua implementation[1].

Now the calls Future.Get() and Future.GetTyped() ignore push messages,
and do not report an error.

1. https://www.tarantool.io/ru/doc/latest/reference/reference_lua/box_session/push/

Closes #67
@oleg-jukovec oleg-jukovec merged commit 1a1fe7b into tarantool:master Jun 14, 2022
@oleg-jukovec oleg-jukovec removed their assignment Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support IPROTO_PUSH
4 participants