tarantool / tarantool-python

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

Missing error report while replication error occures #78

Closed vitalyisaev2 closed 8 years ago

vitalyisaev2 commented 8 years ago

Hello, I use tarantool-python for the purposes of Tarantool cluster management. I've faced with a misleading (from my point of view) behavior when I set replication_source for a particular Tarantool node.

In [21]: import tarantool

In [22]: c = tarantool.connect('ops-4.dev.search.ru', 33018)

In [23]: c.authenticate('id', 'id_pass')
Out[23]: 
null
...

In [24]: r = c.eval("return box.cfg{ replication_source = { 'id:id_pass@ops-7.dev.search.ru:33018' } }")

In [25]: r.strerror
Out[25]: ('ER_OK', 'OK')

In [26]: r.data
Out[26]: []

But in Tarantool logs I see that the error actually happened:

Jul 13 19:19:03 ops-4 ltime[1]: main/127/iproto C> starting replication from ops-7.dev.search.ru:33018
Jul 13 19:19:03 ops-4 ltime[1]: main/127/iproto I> set 'replication_source' configuration option to ["id:id_pass@ops-7.dev.search.ru:33018"]
Jul 13 19:19:03 ops-4 ltime[1]: main/128/applier/ops-7.dev.search I> connected to 1.6.8 at 10.241.232.31:33018
Jul 13 19:19:03 ops-4 ltime[1]: main/128/applier/ops-7.dev.search I> authenticated
Jul 13 19:19:03 ops-4 ltime[1]: main/128/applier/ops-7.dev.search I> can't read row
Jul 13 19:19:03 ops-4 ltime[1]: main/128/applier/ops-7.dev.search xrow.cc:262 E> ER_CLUSTER_ID_MISMATCH: Cluster id of the replica b83c8260-9b70-4abb-a9dd-0ba58d2cecf0 doesn't match cluster id of the master 80ef9a60-37ba-4065-93b6-34990deea9e7

Since no error was returned, could anyone please explain, if there are any convenient methods in Python API to check that replication really works.

Versions used:

knazarov commented 8 years ago

Hi @vitalyisaev2

You can read box.info.replication['status']. I do it like this:

tnt = tarantool.Connection(host, port)
replication_status = tnt.eval("return box.info.replication['status']")

if replication_status != 'follow':
    ...
vitalyisaev2 commented 8 years ago

@racktear thanks for a prompt response!

If the one would like to create two master-master replicas, how the verification should be performed? Both replicas must return follow state?

knazarov commented 8 years ago

Yes, both replicas should be in the "follow" state.

I use python to set up master-master replication between 2 instances. The only "catch" is that one of the instances must be initially created with box.cfg{replication_source=...} for them to have the same cluster ID. Then I connect to another instance, set up its replication_source dynamically and wait until both replicas switch to "follow" state.

vitalyisaev2 commented 8 years ago

Thanks again. Good point!