1- ``multidb `` provides two Django database routers useful in master-slave
1+ ``multidb `` provides two Django database routers useful in primary-replica database
22deployments.
33
44
5- MasterSlaveRouter
5+ ReplicaRouter
66-----------------
77
8- With ``multidb.MasterSlaveRouter `` all read queries will go to a slave
8+ With ``multidb.ReplicaRouter `` all read queries will go to a replica
99database; all inserts, updates, and deletes will go to the ``default ``
1010database.
1111
12- First, define ``SLAVE_DATABASES `` in your settings. It should be a list of
12+ First, define ``REPLICA_DATABASES `` in your settings. It should be a list of
1313database aliases that can be found in ``DATABASES ``::
1414
1515 DATABASES = {
1616 'default': {...},
1717 'shadow-1': {...},
1818 'shadow-2': {...},
1919 }
20- SLAVE_DATABASES = ['shadow-1', 'shadow-2']
20+ REPLICA_DATABASES = ['shadow-1', 'shadow-2']
2121
22- Then put ``multidb.MasterSlaveRouter `` into DATABASE_ROUTERS::
22+ Then put ``multidb.ReplicaRouter `` into DATABASE_ROUTERS::
2323
24- DATABASE_ROUTERS = ('multidb.MasterSlaveRouter ',)
24+ DATABASE_ROUTERS = ('multidb.ReplicaRouter ',)
2525
26- The slave databases will be chosen in round-robin fashion.
26+ The replica databases will be chosen in round-robin fashion.
2727
28- If you want to get a connection to a slave in your app, use
29- ``multidb.get_slave ``::
28+ If you want to get a connection to a replica in your app, use
29+ ``multidb.get_replica ``::
3030
3131 from django.db import connections
3232 import multidb
3333
34- connection = connections[multidb.get_slave ()]
34+ connection = connections[multidb.get_replica ()]
3535
3636
37- PinningMasterSlaveRouter
37+ PinningReplicaRouter
3838------------------------
3939
40- In some applications, the lag between the master receiving a write and its
41- replication to the slaves is enough to cause inconsistency for the end user.
40+ In some applications, the lag between the primary database receiving a write and its
41+ replication to the replicas is enough to cause inconsistency for the end user.
4242For example, imagine a scenario with 1 second of replication lag. If a user
43- makes a forum post (to the master ) and then is redirected to a fully-rendered
44- view of it (from a slave ) 500ms later, the view will fail. If this is a problem
45- in your application, consider using ``multidb.PinningMasterSlaveRouter ``. This
43+ makes a forum post (to the primary ) and then is redirected to a fully-rendered
44+ view of it (from a replica ) 500ms later, the view will fail. If this is a problem
45+ in your application, consider using ``multidb.PinningReplicaRouter ``. This
4646router works in combination with ``multidb.middleware.PinningRouterMiddleware ``
4747to assure that, after writing to the ``default `` database, future reads from
4848the same user agent are directed to the ``default `` database for a configurable
@@ -64,10 +64,10 @@ request, but only in the next request.
6464Configuration
6565=============
6666
67- To use ``PinningMasterSlaveRouter ``, put it into ``DATABASE_ROUTERS `` in your
67+ To use ``PinningReplicaRouter ``, put it into ``DATABASE_ROUTERS `` in your
6868settings::
6969
70- DATABASE_ROUTERS = ('multidb.PinningMasterSlaveRouter ',)
70+ DATABASE_ROUTERS = ('multidb.PinningReplicaRouter ',)
7171
7272Then, install the middleware. It must be listed before any other middleware
7373which performs database writes::
@@ -90,25 +90,25 @@ setting::
9090 MULTIDB_PINNING_COOKIE = 'multidb_pin_writes'
9191
9292
93- ``use_master ``
93+ ``use_primary_db ``
9494==============
9595
96- ``multidb.pinning.use_master `` is both a context manager and a decorator for
97- wrapping code to use the master database. You can use it as a context manager::
96+ ``multidb.pinning.use_primary_db `` is both a context manager and a decorator for
97+ wrapping code to use the primary database. You can use it as a context manager::
9898
99- from multidb.pinning import use_master
99+ from multidb.pinning import use_primary_db
100100
101- with use_master :
101+ with use_primary_db :
102102 touch_the_database()
103103 touch_another_database()
104104
105105or as a decorator::
106106
107- from multidb.pinning import use_master
107+ from multidb.pinning import use_primary_db
108108
109- @use_master
109+ @use_primary_db
110110 def func(*args, **kw):
111- """Touches the master database."""
111+ """Touches the primary database."""
112112
113113
114114Running the Tests
0 commit comments