tarantool/mysql

Tarantool+ClickHouse via mysql protocol

fenogentov opened this issue · 6 comments

I have docker running ClickHouse 22.1.3.7 with revision 54458 (OS name: Linux, version: 5.16.0-kali7-amd64, architecture: x86_64)
I have Tarantool 2.10.4-1-g02908e625 running in docker
I connect to mysql db from Tarantool. Everything works.
I wanted to connect from a Tarantool to a ClickHouse. Reconfigured the ClickHouse to work using the mysql protocol.
Connect to ClickHouse mysql --protocol tcp -u default -P 9004 -p default. Everything works.

Trying to connect from Tarantool
local mysql = require('mysql') local pool, err = mysql.pool_create({ host = 'ch', port = '9004', user = 'default', password = 'TcPfSfIS', db='default' })
Does not work

2022-12-22 07:41:08.635 [1] main/103/tarantool-entrypoint.lua I> [INFO] Start init.lua
2022-12-22 07:41:08.638 [1] main utils.c:489 E> LuajitError: /.rocks/share/tarantool/mysql/init.lua:166: Can't connect to MySQL server on 'ch' (115)
2022-12-22 07:41:08.638 [1] main F> fatal error, exiting the event loop

host = 'ch'

It seems like a docker-compose cluster. Can you provide your network configuration?

{
    "Name": "tarantool_tntnet",
    "Id": "ae4c44e7287f55cae623e394df8af85e426fbb283890b3056c89b963f6b46fa6",
    "Created": "2022-12-21T09:39:37.07266562+03:00",
    "Scope": "local",
    "Driver": "bridge",
    "EnableIPv6": false,
    "IPAM": {
        "Driver": "default",
        "Options": null,
        "Config": [
            {
                "Subnet": "172.21.0.0/16",
                "Gateway": "172.21.0.1"
            }
        ]
    },
    "Internal": false,
    "Attachable": true,
    "Ingress": false,
    "ConfigFrom": {
        "Network": ""
    },
    "ConfigOnly": false,
    "Containers": {
        "16885c5ca17dade586c22a3c36112cb7b9091c5a706b4ac998456be1b45438c8": {
            "Name": "tnt_replica",
            "EndpointID": "b4e1d895e548faa5a250b15e8af6acbd99513f54a1b73627d5b0f8b7af4ed354",
            "MacAddress": "02:42:ac:15:00:02",
            "IPv4Address": "172.21.0.2/16",
            "IPv6Address": ""
        },
        "59ad60a4ad8159d3b36b67079383584eee27609b06ef507c36ed79f43d34d0a7": {
            "Name": "tnt_master",
            "EndpointID": "caaca446705d098c746aa93ff1fa1f6c1b973f0e271cd16a1471391eb5faef81",
            "MacAddress": "02:42:ac:15:00:03",
            "IPv4Address": "172.21.0.3/16",
            "IPv6Address": ""
        },
        "a58fff9e17512f65dd8f37a3bbb63a9a11daf7af090aa7c4f2a1b76ed25248ac": {
            "Name": "ch",
            "EndpointID": "829132ea8b5e4d5530d689fb4b3a5f1da882da36a55485512fa85b64f67146f4",
            "MacAddress": "02:42:ac:15:00:05",
            "IPv4Address": "172.21.0.5/16",
            "IPv6Address": ""
        },
        "c66ca792ae2a2edb2549a45b5f457b99d0d65e2826e418145a60b997a9e1efbf": {
            "Name": "mysql",
            "EndpointID": "b9d225033147768b9eb707b8daac7f0d4a6912ec87321805db0ccc9b7a952989",
            "MacAddress": "02:42:ac:15:00:04",
            "IPv4Address": "172.21.0.4/16",
            "IPv6Address": ""
        }
    },
    "Options": {},
    "Labels": {
        "com.docker.compose.network": "tntnet",
        "com.docker.compose.project": "tarantool",
        "com.docker.compose.version": "1.29.2"
    }
}

We'll look deeper onto this one, but a bit later (I'm going on vacancy till the end of 2022 and my colleagues are finishing their own Q4 tasks).

I configured in clickhouse:
<password_double_sha1_hex>f19e600029895f54818170776a1b6882509803f4</password_double_sha1_hex>

Now connects without error:
err : nil
pool : {"size":1,"user":"test_user_sha1","usable":true,"db":"default","pass":"RaCIkxIr","host":"ch","queue":"channel: 1","port":"9004"}

but falls:

tnt_master      | 2022-12-26 09:52:04.764 [1] main/122/console/unix/:/var/run/tarantool/tarantool.sock I> started
tnt_master      | 2022-12-26 09:52:04.764 [1] main/103/tarantool-entrypoint.lua I> [INFO] Start init.lua
tnt_master      | 2022-12-26 09:52:04.764 [1] main/103/tarantool-entrypoint.lua I> [MYSQL]
tnt_master      | 2022-12-26 09:52:04.768 [1] main/103/tarantool-entrypoint.lua I> nil
tnt_master      | 2022-12-26 09:52:04.768 [1] main/103/tarantool-entrypoint.lua I> {"size":1,"user":"test_user_sha1","usable":true,"db":"default","pass":"RaCIkxIr","host":"ch","queue":"channel: 1","port":"9004"}
tnt_master      | 2022-12-26 09:52:04.768 [1] main utils.c:489 E> LuajitError: /.rocks/share/tarantool/mysql/init.lua:136: Сonnection settings update failed.
tnt_master      | 2022-12-26 09:52:04.768 [1] main F> fatal error, exiting the event loop
tnt_master exited with code 1

I had failed to reproduce the issue.

Setup clickhouse container with mysql interface

cat ./ch_config.xml 
<clickhouse>
    <mysql_port>9004</mysql_port>
    <max_server_memory_usage_to_ram_ratio>0.1</max_server_memory_usage_to_ram_ratio>
</clickhouse>
docker run  -d --name some-clickhouse-server --ulimit nofile=262144:262144 -p 9004:9004 -v `pwd`/ch_config.xml:/etc/clickhouse-server/config.d/additional_config.xml -e CLICKHOUSE_PASSWORD=TcPfSfIS yandex/clickhouse-server

Connect from tarantool

tarantool
Tarantool 2.10.4-0-g816000e10
type 'help' for interactive help
tarantool> mysql = require('mysql')
---
...
tarantool> conn, err = mysql.connect({ host = '127.0.0.1', port = '9004', user = 'default', password = 'TcPfSfIS', db='default' })
---
...
tarantool> conn:ping()
---
- true
...

tarantool> conn:execute("SELECT version()")
---
- - - version(): 22.1.3.7
- true
...
tarantool> pool, err = mysql.pool_create({ host = '127.0.0.1', port = '9004', user = 'default', password = 'TcPfSfIS', db='default' })
---
...

tarantool> pool
---
- user: default
  usable: true
  host: 127.0.0.1
  queue: 'channel: 1'
  pass: TcPfSfIS
  port: '9004'
  db: default
  size: 1
...

tarantool> err
---
- null
...

Feel free to reopen with reproducer if still relevant