On Dec 9, 2007, at 11:50 AM, Anton V. Belyaev wrote:

>
> On Dec 6, 11:51 pm, Andrew Stromnov <[EMAIL PROTECTED]> wrote:
>> I have DB with onemasterserver and several replicated slaves
>> (MySQL). How to implement this functionality: read-only request can  
>> be
>> passed to any DB (masterorslave), but any write request with
>> following read requests must be sended tomasteronly (to avoid
>> synchronization lag).
>
> This is an example of vertical partitioning. I am trying to find out
> how to implement this with SA too.
>
> Quite an offen-used scheme. Strange that no one has replied this
> thread yet.
>
> SA even has support for sharding (which is more complex than vertical
> partitioning IMHO) so there certainly should be the way for 1-master- 
> N-
> slaves scheme.

"vertical" partioning at the Session level is pretty  
straightforward..this example:  
http://www.sqlalchemy.org/docs/04/session.html#unitofwork_contextual_partitioning_vertical
 
   is pretty short but thats really all there is to it....just map  
classes to different database connections.

partitioning among read-only or write is a different case - the  
easiest way is to use two Sessions, one bound to the read-only DB, one  
bound to the write DB.   your application methods choose which session  
they want based on it they are writers or not.  I would not advise  
having a single session "switch" databases mid-stream since you lose  
transactional consistency in that case, but if you really want to do  
that, i.e. you'll ensure that no transactional state is present on the  
session after youve read, you can re-bind it to the writer engine  
using session.bind = <new_engine_or_connection>, and then continue.   
you can create a very simple subclass of Session which overrides  
flush() to do this, and if you're using sessionmaker just send in your  
class with the "class_" keyword argument.

with MySQL there are a lot of third party clustering tools out there  
which could obviate the need for SQLAlchemy to be aware of things like  
this.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to