In my C++ code, I am using MySQL driver 8.0.xx and using xdevapi because of the costly approach of establishing a connection to the database for each client request, I am using a pool of database connections.
mysqlx documentation 2.2.3 Connecting to a Single MySQL Server Using Connection Pooling.
I Create a shared pointer from the client and using whenever it needs during the application life cycle.
Create the Client Object:
mClient_ = std::make_shared<mysqlx::Client>(connectionString.str().c_str(), ClientOption::POOL_QUEUE_TIMEOUT, pPoolTimeout,
ClientOption::POOL_MAX_SIZE, pPoolSize);
Getting Session and using:
mysqlx::Session session = mClient_->getSession();
mysqlx::RowResult res = session.sql(query.str().c_str()).execute();
it works fine, but if the application goes IDLE, pool sessions maybe drop, and the application is stuck, or in some cases it receives SIGSEGV, I can not find any way to check the connection status, for example before execution or after getting session?
I need some function like session.isConnected()
or some routine to check the session before using it.
is there any solution?
Thanks
Do you get the session and execute right away or you get the session once and use it whenever you need?
Because the right pattern is to get a session, use it and destroy it, so it gets back to the pool. And this way, when you get a session, it is guaranteed it is a working one.