From 203e06cbb92608a8f735aa129890cb6cba649590 Mon Sep 17 00:00:00 2001 From: Erik Rose Date: Wed, 16 Jun 2010 12:34:58 -0700 Subject: [PATCH] Adjust settings to use new pinning database router and middleware. Audit forum views for master-slave race conditions. Added a few comments about possible ones but didn't find any that can't be equally caused by our autocommitting. --- apps/forums/views.py | 13 ++++++++++++- requirements.txt | 2 +- settings.py | 3 ++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/forums/views.py b/apps/forums/views.py index 983842fe908..b8b01679a37 100644 --- a/apps/forums/views.py +++ b/apps/forums/views.py @@ -104,6 +104,11 @@ def reply(request, forum_slug, thread_id): if form.is_valid(): forum = get_object_or_404(Forum, slug=forum_slug) thread = get_object_or_404(Thread, pk=thread_id, forum=forum) + + # A reply or two might sneak in after the thread is locked due to + # replication lag, but that should be very rare and won't result in a + # user-visible error. Not worth pinning to master as long as we're not + # even using one transaction per request. if not thread.is_locked: reply_ = form.save(commit=False) reply_.thread = thread @@ -167,6 +172,9 @@ def lock_thread(request, forum_slug, thread_id): (Forum, 'slug__iexact', 'forum_slug')) def sticky_thread(request, forum_slug, thread_id): """Mark/unmark a thread sticky.""" + # TODO: Have a separate sticky_thread() and unsticky_thread() to avoid a + # race condition where a double-bounce on the "sticky" button sets it + # sticky and then unsticky. [572836] forum = get_object_or_404(Forum, slug=forum_slug) thread = get_object_or_404(Thread, pk=thread_id, forum=forum) @@ -302,7 +310,10 @@ def delete_post(request, forum_slug, thread_id, post_id): @login_required @require_POST def watch_thread(request, forum_slug, thread_id): - """Start watching a thread.""" + """Toggle whether a thread is being watched.""" + # TODO: Have a separate watch_thread() and unwatch_thread() to avoid a + # race condition where a double-bounce on the "watch" button watches and + # then unwatches a thread. [572836] forum = get_object_or_404(Forum, slug=forum_slug) thread = get_object_or_404(Thread, pk=thread_id, forum=forum) diff --git a/requirements.txt b/requirements.txt index a8884c6c7a1..4f61b296ad0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -e svn+http://code.djangoproject.com/svn/django/trunk@13302#egg=Django --e git://github.com/jbalogh/django-multidb-router.git@8eeef712a2f594d9fe6ba1e2ffc9240814d6a185#egg=django-multidb-router +-e git://github.com/jbalogh/django-multidb-router.git@25ca0c68929144ed9020d89f2ea1e941c7f9aeca#egg=django-multidb-router -e git://github.com/jbalogh/django-cache-machine.git@bdee25ba4eeb20758da86f4013edbc48a77bcc6e#egg=django-cache-machine -e git://github.com/django-extensions/django-extensions.git#egg=django_extensions Jinja2==2.2.1 diff --git a/settings.py b/settings.py index 161cd00be78..706132c4e1f 100644 --- a/settings.py +++ b/settings.py @@ -33,7 +33,7 @@ } } -DATABASE_ROUTERS = ('multidb.MasterSlaveRouter',) +DATABASE_ROUTERS = ('multidb.PinningMasterSlaveRouter',) # Put the aliases for your slave databases in this list SLAVE_DATABASES = [] @@ -122,6 +122,7 @@ ) MIDDLEWARE_CLASSES = ( + 'multidb.middleware.PinningRouterMiddleware', 'sumo.middleware.LocaleURLMiddleware', 'sumo.middleware.Forbidden403Middleware', 'django.middleware.common.CommonMiddleware',