[odb-users] Questions about releasing/closing CONNECTION POOL under WAL mode

Reilly He reillyhekazusa at gmail.com
Wed Apr 26 05:17:17 EDT 2023


Dear All/Boris,

Sorry to bother you guys, recently I have some questions about
closing/releasing connection-pool in the ODB framework.

I understand this email will be a little bit long to read, so thanks a lot
for your patience.

Deeply appreciated if you guys can kindly provide us some help.

1.Env
The general environment is:

   - *Compiler*: CXX11
   - *OS*: Android&IOS
   - *Inner DB*: SQLite


2. Background information
In our project, we are using *odb::sqlite::database *under WAL
<https://www.sqlite.org/wal.html> mode.

And since we are using it under WAL mode, we managed to insert our own
implementation of *odb::sqlite::connection_factory* in order to fully
activate the power of *WAL*.

Why we want to implement our own connection pool:

> Because if we open a database by default, the odb framework will create a
> database under SHARED_CACHE <https://www.sqlite.org/sharedcache.html> mode,
> with a *odb::sqlite::connection_pool_factory* with *min* and *max* equals
> to ZERO. I found this via reading odb source code, *correct me if I am
> wrong*.


 So as a result, we just wrap a *odb::sqlite::connection_pool_factory *and a
* odb::sqlite::single_connection_factory* as our new connection pool:

> /**
>  * a connection pool which support multi connections under WAL mode
>  * noted that by default:
>  *  - reader`s connection will be provided by a connection_pool_factory
> which consists of [getMinReaderConnectionCount,
> getMaxReaderConnectionCount] connections
>  *  - writer`s connection will be provided by a single_connection_factory
> which ONLY HAVE ONE connection
>  * requesting a connection when either pool is empty will result in
> WAITING for any threads
>  */
> class RWConnectionPool: public odb::sqlite::connection_factory{
>     typedef std::unique_ptr<odb::sqlite::connection_pool_factory>
> ReaderPool;
>     typedef std::unique_ptr<odb::sqlite::single_connection_factory>
> WriterPool;
> public:
>     RWConnectionPool(std::shared_ptr<ConnectionDelegate> delegate,
> std::shared_ptr<ConnectionConfiguration> config);
>     odb::sqlite::connection_ptr connect() override;
>     void database(database_type & db) override;
>     ~RWConnectionPool();
>
> protected:
>     ReaderPool m_Reader{};
>     WriterPool m_Writer{};
> };
>
We set our m_Reader`s min = 4, and max = 4, which means during the runtime
we will hold 4 connections forever for database reading, and m_Writer
is a *odb::sqlite::single_connection_factory,
*so it will hold 1 connection forever for database writing.

3. Problems
Since we just made a wrap of *odb::sqlite::single_connection_factory
*and *odb::sqlite::connection_pool_factory
*to come up with our own connection pool.

*Q:When?*
I wanna make sure whether we should release/close all the connections in
these 2 pools *explicitly*?

*Q:How?*
If we really need to do that, how to do it? I don`t think there are
any *existing
APIs <https://www.codesynthesis.com/products/odb/doc/manual.xhtml> *in your
docs for me to call directly.
After checking the source codes, are *odb::sqlite::single_connection_factory
*and *odb::sqlite::connection_pool_factory`s *deallocator just doing those
things for us?

*Q:Process related issue?*
Our program also runs on *Android* platform, and in android platform, we
got NO hint/callbacks before process exiting. So in this case, the pool's
*deallocator* will not be working (since user just kill our program`s
process), is that OK? Since we released this feature to the market, we
received 17 Android database corruption issues compared to just 1 iOS
database corruption issue on IOS.

Again, really appreciated for any kind of help.

Best regards,
Reilly He


More information about the odb-users mailing list