2014년 12월 2일 화요일

ScopedDbConnection and runcommand

I'm positive I'm getting al this wrong, but here's my question:

I need a connection pool to mongo which I create like so:

mongo::ScopedDbConnection connectionPool("localhost");

Then on each thread, I do:

mongo::DBClientConnection c(connectionPool.get());   <-- is this even right?

Next I need to run 

c.runCommand()

and give the connection back:

connectionPool.done();



You haven't mentioned which version of the C++ driver you are using, so I am going to assume 26compat.

First, you are correct that you are not using ScopedDbConnection appropriately. You should not be sharing a ScopedDbConnection across threads. The ScopedDbConnection is not itself a pool: it merely obtains and returns connection objects owned by the global pool. You are correct, however, that you must use 'done' before calling the destructor of the ScopedDbConnection.

However, it is more important to note that the connection pool and related classes, including ScopedDbConnection, have been removed from driver in the current legacy RC releases. The soon to be released legacy-1.0.0 driver, which will deprecate the 26compat driver, will not offer pooling functionality. You will need to build your own pooling mechanism in a manner appropriate to your application.

Given that ScopedDbConnection will be going away, you might do better to just not use it or the DBConnectionPool at all in your application if you intend to later move to the updated stable driver.


댓글 없음:

댓글 쓰기