I'm along the way of making a centralized ticket server for providing unique 32bit INT ids. I've got a function that may be known as inside my application that accepts a parameter for that entity/ table, e.g. getPrimaryKey('user'). I acquired the concept from Flickr via this web site publish:

http://code.flickr.com/blog/2010/02/08/ticket-servers-distributed-unique-primary-keys-on-the-cheap/

We'll eventually become sharding our data among multiple MySQL databases and I must understand this code ready to go like a evidence of concept.

My real question is what's the most practical way for implementing this functionality within Doctrine? Clearly, while using above ticket server, I will have to specify that none of my Doctrine models contain a car- incrementing primary key.

It is possible to Doctrine_Model method I'm able to extend which will retrieve the main key using my getPrimaryKey method just before placing a brand new record in to the database? Otherwise, must i be approaching this issue from another place inside my application?

Ideally, I'd like the ids to become produced while using above method when utilizing Doctrine relations for example:

$user = new User():  
$user->name = 'Bob';  
$user->Phonenumbers[]->number = '555-5555';  
$user->save();  

Also, sleep issues of the scenario is within choosing data from the particular shard. My current thought would be to conserve a master listing of key ranges contained on each shard such as this (disregard the few rows per shard):

Shard A person_id 1-1000
Shard B user_id 1001-2000
Shard C user_id 2001-3000

I'm able to then call something similar to getShard($table_title, $primary_key) to obtain the shard and perhaps switch my Doctrine connection compared to that shard. Related data for the user/entity will in all probability reside on a single shard so I'm not too worried relations spanning multiple shards. Though, it might be possible, so any assistance with this problem could be greatly appreciated too.