0
votes

I am using

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php

as my session handler for my PHP app.

Our app is expecting high volume traffic, so we are experimenting with sharding the Mongo that store session.

I have set up my shard according the the document, and things are all fine before I shard the collection (I can see session document being created in the session collection).

As soon as I enabled sharding on session using sharding key sess_id, then no session document gets created (i.e. count never change), and I see these lines in the mongos log whenever I visit my PHP page: resetting shard version of mydb.session on my.hsard.ip.address:port, version is zero

I have tried to shard my other collection and it works fine, so that tells me my sharding setup is correct.

Anybody have a clue of what might be wrong? I'm using Mongo 2.2.3.

1

1 Answers

1
votes

Found the cause.

It was because the write function in MongoDbSessionHandler.php that comes with symfony version we are using will not work with sharding.

The MongoDbSessionHandler.php we are using implements write like this:

$mongo->update({shardkey:1}, {shardkey:1, data:2}, {upsert:true})

which is not allowed, because you cannot change the shard key.

Solution is to simply use the latest version of MongoDbSessionHandler.php in the github.