tarantool / tarantool-python

Python client library for Tarantool
https://www.tarantool.io
BSD 2-Clause "Simplified" License
100 stars 48 forks source link

api: extend connect with `fetch_schema` param #271

Closed GRISHNOV closed 1 year ago

GRISHNOV commented 1 year ago

Added support of the fetch_schema parameter, which allows to ignore schema changes on the server.

By default, it is used fetch_schema = True:

>>> import tarantool
>>> conn = tarantool.Connection(host='localhost', port=3303)

>>> conn.schema_version
80

>>> conn.schema.schema
{257: <tarantool.schema.SchemaSpace object at 0x10fd21a80>, '_vinyl_deferred_delete': <tarantool.schema.SchemaSpace object at 0x10fd21a80>, 272: <tarantool.schema.SchemaSpace object at 0x10fd229b0>, ... ... , 'tester': <tarantool.schema.SchemaSpace object at 0x10fd22830>}

>>> tester = conn.schema.schema['tester']
>>> tester
<tarantool.schema.SchemaSpace object at 0x10fd22830>
>>> tester.
tester.arity    tester.flush()  tester.format   tester.indexes  tester.name     tester.schema   tester.sid      
>>> tester.format
{'id': {'name': 'id', 'type': 'unsigned', 'id': 0}, 0: {'name': 'id', 'type': 'unsigned', 'id': 0}, 'name': {'name': 'name', 'type': 'string', 'id': 1}, 1: {'name': 'name', 'type': 'string', 'id': 1}}

If the fetch_schema is specified as False, fields schema_version and schema will no longer be present in the connection object:

>>> import tarantool
>>> conn = tarantool.Connection(host='localhost', port=3303, fetch_schema=False)

>>> hasattr(conn, 'schema_version')
False
>>> hasattr(conn, 'schema')
False

In this case, requests to the server via the connection.update_schema will no longer be made when there is SchemaReloadException.

Closes #219

DifferentialOrange commented 1 year ago

In this case, requests to the server via the connection.update_schema will no longer be made when there is SchemaReloadException.

So there won't be any way to use a connection for any space operations? Only calls and evals? To be honest, I don't quite get this one without tests.

GRISHNOV commented 1 year ago

In this case, requests to the server via the connection.update_schema will no longer be made when there is SchemaReloadException.

So there won't be any way to use a connection for any space operations? Only calls and evals? To be honest, I don't quite get this one without tests.

I suppose, it is. By analogy with an existing solution:

c = netbox.connect(uri, {fetch_schema = false})
c.space -- always will be nil
GRISHNOV commented 1 year ago

Now the connection with fetch_schema=False will throw an exception NotSupportedError when trying to call the methods replace, insert, delete, upsert, update, select.

DifferentialOrange commented 1 year ago

You'll also need to rebase, sorry for the inconveniences

GRISHNOV commented 1 year ago

While working on the task, I noticed that there is an issue in the CRUD tests. When running make test locally, in the absence of an installed crud rocks, CRUD tests freezes forever. So, I made some changes to the CRUD instance configuration file

GRISHNOV commented 1 year ago

Thanks for the feedback!

I've made all the corrections. At the moment there is a problem with tests that fall with variable probability. At the moment, it is difficult to determine the cause, but the problem, as far as I can see, is related to the update_schema call for connection pool:

# Turning the same connection into schemafull.
if mode is not None:
    for addr in con.pool.keys():
        con.pool[addr].conn.update_schema(con.pool[addr].conn.schema_version) # <------
    else:
        con.update_schema(con.schema_version)

It looks like there is a desynchronization with the transmitted con.pool[addr].conn.schema_version value and the value on the server

DifferentialOrange commented 1 year ago

Ping me when everything is ready