← Back to team overview

maria-discuss team mailing list archive

Question about MariaDB Non-blocking Client

 

Greetings,

I'm using the MariaDB Non-blocking API to write a C++ client, but I've hit
a wall regarding connection checking. I've been referencing the binding
from node-mariasql (
https://github.com/mscdex/node-mariasql/blob/master/src/binding.cc).

My app parses a config and creates new objects for each query, where each
object has a MYSQL struct and MYSQL *pointer. Then, for each I set state to
STATE_CONNECT and call doWork().  This works fine, when I can connect right
away.

The problem I'm experiencing is if I have a connection and kill the server
(/etc/init.d/mysql stop) and then start it back (/etc/init.d/mysql start),
I can never get clean reconnects. It's usually a mixture of errcode 2058,
2003, 2013.

I'm really confused how to gracefully manage connections. Before I was
using the official MySQL C++ connector, and it provides a
connection->isConnected() method. I'm wondering how I can get something
similar with MariaDB's client, as I need the non-blocking interface.

Given: MYSQL mysql, *mysqlHandle;

Look at the mysql_real_connect_start() or cont() functions. I provide MYSQL
struct and on connect I get a copy of the struct stored in *mysqlHandle.
It's not clear to me what the purpose of the copy is at this point as I
still use the initial struct to call query().

In the case that I can detect a disconnection, how do I properly clean up
the connection and attempt reconnect? Do I mysql_close(&mysql) and/or
mysql_close(mysqlHandle), shutdown/close the file descriptor, mysql_init()
a new handle and go through mysql_real_connect_start/cont()?

Does it even make sense for each object to have its own MYSQL struct that I
mysql_init(), or would it be better to have layer on top that mysql_init()s
a single MYSQL struct, connects, and passes the returned *mysqlHandle to
each query?

Thanks for providing the async client, any help is appreciated.

Follow ups