Skip to content

iproto: support feature push - #247

Merged
DifferentialOrange merged 1 commit into
masterfrom
igrishnov/gh-201-iproto-push-support
Nov 3, 2022
Merged

iproto: support feature push#247
DifferentialOrange merged 1 commit into
masterfrom
igrishnov/gh-201-iproto-push-support

Conversation

@GRISHNOV

@GRISHNOVGRISHNOV commented Oct 19, 2022

Copy link
Copy Markdown
Contributor

Adds support for receiving out-of-band messages from a server that uses box.session.push call.

Implemented for methods: call, eval, select, insert, replace, update, upsert, delete.
To work with out-of-band messages, 2 new optional arguments are used:

  • on_push [function] - callback, launched with the received data for each out-of-band message. Two arguments for this callback are expected:
    • the first is the received from an out-of-band message data.
    • the second is on_push_ctx, variable for recording the result of the callback work.
  • on_push_ctx - result of the on_push work can be written to this variable.

Below is an example of the proposed API with method call and insert. In the described example, before the end of the call and insert, out-of-band messages are processed via specified callback.

For comparison: implementation in the lua version.

ClientServer
fiber = require('fiber')
box.cfg({listen = 3301})
box.schema.user.grant(
'guest',
'read,write,execute',
'universe'
)
function server_function()
x = {0,0}
while x[1] < 3 do
x[1] = x[1] + 1
fiber.sleep(1)
box.session.push(x)
end
fiber.sleep(1)
return x
end
import tarantool

def callback(data, on_push_ctx=[]): print('run callback with data: ', data) data[0][1] = data[0][1] + 1 on_push_ctx.append(data)
callback_res = []
conn = tarantool.connect(port=3301) res = conn.call( 'server_function', on_push=callback, on_push_ctx=callback_res ) # receiving out-of-band messages, # the conn.call is not finished yet. >>> run callback with data: [[1, 0]] >>> run callback with data: [[2, 0]] >>> run callback with data: [[3, 0]] # the conn.call is finished now.
print(res) >>> [3, 0]
print(callback_res) >>>[[[1, 1]], [[2, 1]], [[3, 1]]]
box.schema.create_space(
'tester', {
format = {
{name = 'id', type = 'unsigned'},
{name = 'name', type = 'string'},
}
})
box.space.tester:create_index(
'primary_index', {
parts = {
{field = 1, type = 'unsigned'},
}
})
function on_replace_callback()
x = {0,0}
while x[1] < 300 do
x[1] = x[1] + 100
box.session.push(x)
end
return x
end
box.space.tester:on_replace(
on_replace_callback
)
callback_res = []

conn_pool = tarantool.ConnectionPool( [{'host':'localhost', 'port':3301}], user='guest')
res = conn_pool.insert( 'tester', (1, 'Mike'), mode=tarantool.Mode.PREFER_RO, on_push=callback, on_push_ctx=callback_res, ) # receiving out-of-band messages, # the conn_pool.insert is not finished yet. >>> run callback with data: [[100, 0]] >>> run callback with data: [[200, 0]] >>> run callback with data: [[300, 0]] # the conn_pool.insert is finished now.
print(res) >>> [1, 'Mike']
print(callback_res) >>>[[[100, 1]], [[200, 1]], [[300, 1]]]

Closes#201

@Totktonada

Copy link
Copy Markdown
Contributor

In the Lua API on_push is a callback (called at receiving of a pushed value) and on_push_ctx is a value to pass to the callback (context). As I see from the PR description, here the API is different: pushed values are just stored in a provided collection. One can't instantly react on a push using a code during a long request. Is it intentional?

@GRISHNOV
GRISHNOVforce-pushed the igrishnov/gh-201-iproto-push-support branch 2 times, most recently from 9663a63 to df17542CompareOctober 20, 2022 13:16
@GRISHNOV

Copy link
Copy Markdown
ContributorAuthor

In the Lua API on_push is a callback (called at receiving of a pushed value) and on_push_ctx is a value to pass to the callback (context). As I see from the PR description, here the API is different: pushed values are just stored in a provided collection. One can't instantly react on a push using a code during a long request. Is it intentional?

I have updated the solution and description in PR. Now it is possible to use callback, which will be called streaming when out-of-band messages are received before the end of the main call (for example, the end of call or eval).

@DifferentialOrangeDifferentialOrange left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your draft!

I think we may implement push in a way even more similar to Lua one and describe basic cases with tests and small examples. Rework should be relatively small.

Comment threadtarantool/connection.py Outdated
Comment threadtarantool/connection.py Outdated
Comment threadtarantool/connection.py Outdated
Comment threadtarantool/connection.py Outdated
Comment threadtarantool/connection.py Outdated
@GRISHNOV
GRISHNOVforce-pushed the igrishnov/gh-201-iproto-push-support branch from df17542 to cbbe900CompareOctober 24, 2022 08:38
@GRISHNOV

Copy link
Copy Markdown
ContributorAuthor

Thank you for your feedback! If the current version of the draft is suitable, I will start writing tests and documentation

Comment threadtarantool/connection.py Outdated
Comment threadtarantool/connection.py Outdated
@GRISHNOV
GRISHNOVforce-pushed the igrishnov/gh-201-iproto-push-support branch from cbbe900 to 43b2142CompareOctober 24, 2022 11:57
@DifferentialOrange

Copy link
Copy Markdown
Member

If the current version of the draft is suitable,

I think it is. To fix docs build, I recommend you to rebase on master branch. Moreover, I think it's better to rebase on yet unmerged #251 since it contains fixes for potential test fails.

@GRISHNOV
GRISHNOVforce-pushed the igrishnov/gh-201-iproto-push-support branch from 43b2142 to 25ae979CompareOctober 25, 2022 20:11
Comment threaddoc/quick-start.rst Outdated
@GRISHNOV
GRISHNOVforce-pushed the igrishnov/gh-201-iproto-push-support branch 3 times, most recently from f999db7 to c237b8eCompareOctober 26, 2022 09:54
@GRISHNOV
GRISHNOV marked this pull request as ready for review October 26, 2022 10:00
Comment threaddocs/source/quick-start.rst Outdated
@GRISHNOV
GRISHNOVforce-pushed the igrishnov/gh-201-iproto-push-support branch from c237b8e to 8b6c5c6CompareOctober 26, 2022 19:25

@DifferentialOrangeDifferentialOrange left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your PR! I have left several comments. If there is any questions about test infrastructure (currently it's a mess) or doc (it should be in shape after last PRs), feel free to ask me.

Comment threaddocs/source/quick-start.rst Outdated
Comment threaddocs/source/quick-start.rst Outdated
Comment threadtarantool/connection.py Outdated
Comment threadtarantool/connection.py
Comment threadtarantool/connection.py Outdated
Comment threadtest/suites/test_push.py Outdated
Comment threadtest/suites/test_push.py Outdated
Comment threadtest/suites/test_push.py Outdated
Comment threadtest/suites/test_push.py Outdated
Comment threadtest/suites/test_push.py Outdated
@GRISHNOV
GRISHNOVforce-pushed the igrishnov/gh-201-iproto-push-support branch 4 times, most recently from 8cfa4cc to 57c9055CompareOctober 31, 2022 07:46
Comment threadtest/suites/lib/skip.py
Comment threadtarantool/connection.py
Comment threaddocs/source/quick-start.rst Outdated
Comment threadtest/suites/test_push.py Outdated
Comment threadtest/suites/test_push.py Outdated
Comment threadtest/suites/test_push.py Outdated
@DifferentialOrange

Copy link
Copy Markdown
Member

Sorry, it seems that you'll need to rebase one more time. I think it's would be the last time and your PR would be merged next.

Master changes that are relevant to you: now ConnectionPool is supported on Python 3.6 and you don't need to skip tests anymore.

@GRISHNOV
GRISHNOVforce-pushed the igrishnov/gh-201-iproto-push-support branch from 57c9055 to 5d63f52CompareOctober 31, 2022 12:34
@GRISHNOV

Copy link
Copy Markdown
ContributorAuthor

Thank you for your feedback! I tried to answer all the comments on the code review

@DifferentialOrangeDifferentialOrange left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've try to read the current version once more tomorrow together with examining the complicated case of schema reload with push.

Comment threadtest/suites/test_push.py
Comment threadtest/suites/test_push.py Outdated
Comment threadtest/suites/test_push.py Outdated
@GRISHNOV
GRISHNOVforce-pushed the igrishnov/gh-201-iproto-push-support branch 2 times, most recently from 6d4a20e to 87f2bc0CompareNovember 2, 2022 13:14
Comment threadtarantool/connection.py Outdated
@GRISHNOV
GRISHNOVforce-pushed the igrishnov/gh-201-iproto-push-support branch from 87f2bc0 to 6c7ae28CompareNovember 2, 2022 14:36

@DifferentialOrangeDifferentialOrange left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your updates. I think this is the last round of comments.

Please, add the CHANGELOG entry (sorry for not having a convenient PR checklist yet).

Comment threadtarantool/connection.py Outdated
Comment threadtarantool/connection.py
Comment threadtest/suites/test_push.py Outdated
Comment threadtest/suites/test_push.py Outdated
@GRISHNOV
GRISHNOVforce-pushed the igrishnov/gh-201-iproto-push-support branch from 6c7ae28 to e366e46CompareNovember 3, 2022 09:36
Comment threadCHANGELOG.md Outdated
Adds support for receiving out-of-band messages
from server that uses box.session.push call.
Data obtaining is implemented for methods:
`call`, `eval`, `select`, `insert`, `replace`,
`update`, `upsert`, `delete`.
To do this, optional arguments `on_push` and `on_push_ctx`
are used for these methods. Argument `on_push` sets the
callback to call when an out-of-band message is received,
and the `on_push_ctx` argument allows to save the result
of `on_push` work or pass data to it.
So the API is similar to the implementation
of LUA version at the moment.
Closes#201
@GRISHNOV
GRISHNOVforce-pushed the igrishnov/gh-201-iproto-push-support branch from e366e46 to 64f2b0dCompareNovember 3, 2022 12:27

@oleg-jukovecoleg-jukovec left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

@DifferentialOrange
DifferentialOrange merged commit 26c6db1 into masterNov 3, 2022
@DifferentialOrange
DifferentialOrange deleted the igrishnov/gh-201-iproto-push-support branch November 3, 2022 13:44
Sign up for freeto 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.

Consider IPROTO_PUSH support

4 participants

@GRISHNOV@Totktonada@DifferentialOrange@oleg-jukovec