Casbah (MongoDB Scala Driver) v2.4.1 Released

455 views
Skip to first unread message

Brendan W. McAdams

unread,
Jul 6, 2012, 10:42:44 AM7/6/12
to mongodb-user, mongodb-ca...@googlegroups.com, mongodb-...@googlegroups.com
Only one minor fix in this release, to correct an import issue from the previous release.

Fixed QueryDSL imports for “default” (com.mongodb.casbah.Imports) import so that bareword ops like $set and $inc are available.

Kocka Slavomir

unread,
Jul 18, 2012, 7:55:26 AM7/18/12
to <mongodb-casbah-users@googlegroups.com>
Hi,


However when browsing directly on repo http://repo1.maven.org/maven2/org/mongodb/casbah-core_2.9.2/

the last version is 2.4.0… Any idea? Maven is not able to find 2.4.1 :/

Thanks...

Slavo

Brendan W. McAdams

unread,
Jul 18, 2012, 10:14:27 AM7/18/12
to mongodb-ca...@googlegroups.com
We publish to Sonatype and do not have any control over the sync to central maven.  Sometimes it is fast, sometimes it is slow.

I recommend pulling artifacts from sonatype for the "most up to date"

On Wed, Jul 18, 2012 at 10:03 AM, Roman Timushev <rti...@gmail.com> wrote:
It is available in Sonatype repo: https://oss.sonatype.org/content/repositories/releases/org/mongodb/casbah-core_2.9.2/

среда, 18 июля 2012 г., 15:55:26 UTC+4 пользователь Slavo написал:

iwein...@gmail.com

unread,
Oct 23, 2012, 6:52:15 AM10/23/12
to mongodb-ca...@googlegroups.com, mongodb-user, mongodb-...@googlegroups.com
Is there a fix for the connection leaks that casbah is prone too? I've written my own template, and so has at least one other:

http://alvinalexander.com/scala/managing-mongodb-connections-casbah-driver-beginning-scala-using-function

Is this still needed in 2.4.1?

Age Mooij

unread,
Oct 24, 2012, 4:13:48 AM10/24/12
to mongodb-ca...@googlegroups.com, mongodb-user, mongodb-...@googlegroups.com, iwein...@gmail.com
Interesting question! 

AFAIK the MongoConnection class actually represents a connection pool so what I've done so far is to initialize the MongoConnection and MongoCollection instances when my repository actor is created and to make sure the connection is closed when the actor dies. In other words, I'm using a MongoConnection for potentially days/weeks/months. 

If that is not the intended usage pattern and we should really be creating and closing connections for every single interaction with Mongo, then I'd love to hear about it.

Age

Brendan W. McAdams

unread,
Oct 24, 2012, 5:14:06 AM10/24/12
to mongodb-ca...@googlegroups.com, mongodb-user, mongodb-...@googlegroups.com, iwein...@gmail.com
I wasn't aware of any connection leaks, but I do find the current Java driver connection pool to be atrocious.

I'm working on the 2.5.0 release this week, and I'll see if I can't integrate a change along these lines to mitigate some of the pooling problems.

I know in 2.9.x java driver  there have been some tweaks to the pool as well that may fix some of this.

Age Mooij

unread,
Oct 24, 2012, 5:21:25 AM10/24/12
to mongodb-ca...@googlegroups.com, mongodb-user, mongodb-...@googlegroups.com, iwein...@gmail.com
Which of the two usage patterns would you advise? keeping a connection/collection open for long periods or opening them for each individual interaction with Mongo?

Age


--
 
 

Brendan W. McAdams

unread,
Oct 24, 2012, 8:10:48 AM10/24/12
to mongodb-ca...@googlegroups.com
I don't know, as I'm not aware of any actual connection leaks.

There is a pool, so it should return to the pool.  I doubt it's a Java issue, there may be something I'm doing wrong on the Scala end that is causing references to be held on ot… need tos ee if there's an easy way to track that down.

--
 
 

Brendan W. McAdams

unread,
Oct 24, 2012, 8:49:49 AM10/24/12
to mongodb-ca...@googlegroups.com, mongodb-user, mongodb-...@googlegroups.com, iwein...@gmail.com
Reading through the linked post, I still don't see leakage happening.

Casbah provides you with a connection *POOL*, not an individual connection.

calling close() shuts down the entire connection pool.  This is the "leakage" you are observing: The connection pool opens a pool of connections, not an individual connection.

This is incorrect usage, and you should be utilizing the pool.  The Connection objects will be released back into the pool when unused and you don't need to close them manually.

I will update the docs to clarify that.

Iwein Fuld

unread,
Oct 24, 2012, 4:09:46 PM10/24/12
to mongodb-ca...@googlegroups.com
I just went over this with Age. It seems that indeed I was using the
pool in the wrong way (although we didn't reproduce that). I'll get
back to this if I can confirm a problem, otherwise I'd assume
everything is fine.

Thanks!
--
http://twitter.com/iweinfuld
http://www.linkedin.com/in/iweinfuld

Iwein Fuld

unread,
Nov 14, 2012, 5:53:37 AM11/14/12
to Alvin Alexander, mongodb-ca...@googlegroups.com, mongodb-user, mongodb-...@googlegroups.com
Kudos for posting back here. Please update the article (don't delete
it), you're not the first to fall into this and people (like me :p)
could really use the background.

Iwein

On Tue, Nov 13, 2012 at 8:22 PM, Alvin Alexander <devd...@gmail.com> wrote:
> FWIW, I wrote the article at alvinalexander.com mentioned near the beginning
> of this discussion. I just figured out what I was doing wrong, and posted a
> small sample project at Github that shows how to insert objects into MongoDB
> with Casbah without leaking connections:
>
> https://github.com/alvinj/ScalaCasbahConnections
>
> There may be a better way to do this, but I want to use Casbah with
> Scalatra, and using the MongoFactory and DAO approach in my Stock class
> seems like what I want.
>
> I just wanted to let you know that this was user error (me), and I'll update
> or delete the article on alvinalexander.com tonight.

Age Mooij

unread,
Nov 14, 2012, 6:28:14 AM11/14/12
to mongodb-ca...@googlegroups.com, Alvin Alexander, mongodb-user, mongodb-...@googlegroups.com
This matches how I use Casbah. I set up the MongoConnection and the required MongoCollections when my repository (actor) gets created (started) and I just reuse the collections until it's time to shut down. Casbah should take care of the connection pooling.

One important thing to think about though is that by default Casbah (or the underlying Java driver) does not retry after a connection failure. so if there is a brief network outage between your code and the Mongo server, your app won;t be able to recover. There's an easy fix for this (which I think should be default): set the correct option:

MongoOptions(autoConnectRetry = true)

And then use one of the MongoConnection apply methods that supports the MongoOptions argument.

If, like me, you are using Casbah from an Akka actor, you should also make sure your actor is restartable without leaking connections. I do this by calling close() on my MongoConnection in the actor postStop method.

Age

PS
Congratulations to Brendan for the new job at TypeSafe! I'm still patiently waiting for Casbah 2.5 ;)
> --
>
>

tigerfoot

unread,
Nov 29, 2012, 7:59:58 PM11/29/12
to mongodb-ca...@googlegroups.com, mongodb-user, mongodb-...@googlegroups.com
I read on Mongo's site that they've release a change that allows writes to returns a status (especially an error) that wasn't present before.
They claimed to have support across the drivers.

Does this latest version of Casbah support this feature?

Thanks for the fantastic code!

Brendan W. McAdams

unread,
Nov 30, 2012, 2:14:58 AM11/30/12
to mongodb-ca...@googlegroups.com

Writes always returned a status in casbah. See all write methods - they return WriteResult and always have.

We simply changed the default. In previous releases you had to specifically turn on "safe" writes.

In the new driver releases it is on by default *if you use the new MongoClient class*. Casbah will eventually reflect this behavior.

--
 
 
Reply all
Reply to author
Forward
0 new messages