ibmdb / rust-ibm_db

RUST Driver for IBM Db2 servers
MIT License
18 stars 5 forks source link

[Question] Full and Correct Support for Connection Pooling? #2

Open mdgozza opened 3 years ago

mdgozza commented 3 years ago

Hi!

Thanks so much for supporting rust.

When reviewing the r2d2 pooling implementation I noticed that this library doesn't yet seem to properly take care of broken and invalid connections in the r2d2 pool. Is there any timeline for when this might become officially complete?

https://github.com/ibmdb/rust-ibm_db/blob/1fd871d907012378bf54c939284f620c741dfe0a/src/lib.rs#L138-L146

Also: I noticed the work on this library is quite new. What kind of levels of support is IBM currently looking at providing for this module?

Again, thanks so much for supporting rust!!

AWADHAMBIKA commented 3 years ago

Hi @mdgozza thanks for your query. We are always happy to help and support open-source drivers on Db2. Also, current idea was to support ODBC APIs as is and that is what is supported as of now. In future, we are planning to support DB2 complete set of CLI APIs as well. In the meanwhile, if you have any specific API in mind that you would like to e supported, do let us know and we will prioritize the same.

As we are learning(this project is inspired by r2d2 pooling itself) and implementing, we are still in process of implementing certain things like the above connection pooling thing. We will try to create full support for connection pooling.

Hope it clarifies.

mdgozza commented 3 years ago

Awesome @AWADHAMBIKA thanks so much for the explanation!

I am going to try to build an http server that processes db2 queries in rust and pools connections using this connection manager, but I am worried that without an is_valid implementation pool connections will be created and left open even if they are no longer valid. ( likewise for has_broken )

I will do some research into how it may be possible to detect if a connection is valid or has broken and maybe provide those implementations so that I can use connection pooling and feel confident that a connection I get from the pool will be both valid and not broken.

mdgozza commented 3 years ago

A quick glance at the postgres implementation shows maybe it's not so bad! 🎉

https://github.com/sfackler/r2d2-postgres/blob/master/src/lib.rs#L70-L76

AWADHAMBIKA commented 3 years ago

Hi @mdgozza not sure if you were able to implement the is_valid. I was thinking of something like below(There might be syntactical problem but I hope I am able to explain myself) i.e. if prepare is working fine then that means the connection is still valid. Does this looks good?:

 fn is_valid(&self, _conn: &mut Self::Connection) -> std::result::Result<(), Self::Error> { 
     Statement::with_parent(&_conn)?.prepare(
        "select * from sysibm.sysdummy1",
    )?;
} 
mdgozza commented 3 years ago

Hey @AWADHAMBIKA, Yeah, I think that's fantastic. Only concern I have is with prepare.

I'm not positive about this, but it should be confirmed. Prepare might be telling the sql server ( DB2 ) that we are going to execute a statement. So maybe the sql server ( DB2 ) hangs onto information about that unexecuted statement and causes some kind of buildup in the engine?

I feel like prepare might leave some stuff hanging around where a full query might be more clean on both sides. Let me know your thoughts, you might know more that I do here, don't have a ton of experience working with sql engines.