From patchwork Wed Oct 19 02:14:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael-Doyle Hudson X-Patchwork-Id: 4736 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 2610923EF6 for ; Wed, 19 Oct 2011 02:14:15 +0000 (UTC) Received: from mail-bw0-f52.google.com (mail-bw0-f52.google.com [209.85.214.52]) by fiordland.canonical.com (Postfix) with ESMTP id 07BD8A1870C for ; Wed, 19 Oct 2011 02:14:15 +0000 (UTC) Received: by bkbzs2 with SMTP id zs2so2228410bkb.11 for ; Tue, 18 Oct 2011 19:14:14 -0700 (PDT) Received: by 10.223.4.215 with SMTP id 23mr7953377fas.8.1318990454489; Tue, 18 Oct 2011 19:14:14 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.1.71 with SMTP id 7cs67846lak; Tue, 18 Oct 2011 19:14:14 -0700 (PDT) Received: by 10.227.59.67 with SMTP id k3mr1755865wbh.108.1318990453444; Tue, 18 Oct 2011 19:14:13 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id p13si3182789wbh.104.2011.10.18.19.14.13 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 18 Oct 2011 19:14:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1RGLfY-0002mK-PZ for ; Wed, 19 Oct 2011 02:14:12 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id AF0C7E02F0 for ; Wed, 19 Oct 2011 02:14:12 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-scheduler X-Launchpad-Branch: ~linaro-validation/lava-scheduler/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 86 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-scheduler/trunk] Rev 86: try a bit harder to fix bug 861149 in all cases Message-Id: <20111019021412.14211.54799.launchpad@ackee.canonical.com> Date: Wed, 19 Oct 2011 02:14:12 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14157"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 8e9d681b2548424c112ee7f0c338411774b02571 Merge authors: Michael Hudson-Doyle (mwhudson) Related merge proposals: https://code.launchpad.net/~mwhudson/lava-scheduler/workaround-django-tz-bug-861149/+merge/79634 proposed by: Michael Hudson-Doyle (mwhudson) review: Approve - Zygmunt Krynicki (zkrynicki) ------------------------------------------------------------ revno: 86 [merge] committer: Michael Hudson-Doyle branch nick: trunk timestamp: Wed 2011-10-19 15:12:33 +1300 message: try a bit harder to fix bug 861149 in all cases modified: lava_scheduler_daemon/dbjobsource.py --- lp:lava-scheduler https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk You are subscribed to branch lp:lava-scheduler. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk/+edit-subscription === modified file 'lava_scheduler_daemon/dbjobsource.py' --- lava_scheduler_daemon/dbjobsource.py 2011-10-17 23:35:27 +0000 +++ lava_scheduler_daemon/dbjobsource.py 2011-10-19 01:40:01 +0000 @@ -56,8 +56,18 @@ def getBoardList(self): return self.deferForDB(self.getBoardList_impl) - @transaction.commit_on_success() + @transaction.commit_manually() def getJobForBoard_impl(self, board_name): + # If there is no db connection yet on this thread, create a connection + # and immediately commit, because rolling back the first transaction + # on a connection loses the effect of settings.TIME_ZONE when using + # postgres (see https://code.djangoproject.com/ticket/17062) and this + # method has to be able to roll back to avoid assigning the same job + # to multiple boards. + if connection.connection is None: + connection.cursor().close() + assert connection.connection is not None + transaction.commit() while True: device = Device.objects.get(hostname=board_name) if device.status != Device.IDLE: @@ -85,6 +95,9 @@ # same job -- this is an application level bug though. device.save() except IntegrityError: + self.logger.info( + "job %s has been assigned to another board -- " + "rolling back", job.id) transaction.rollback() continue else: @@ -93,8 +106,15 @@ job.save() json_data = json.loads(job.definition) json_data['target'] = device.hostname + transaction.commit() return json_data else: + # We don't really need to rollback here, as no modifying + # operations have been made to the database. But Django is + # stupi^Wconservative and assumes the queries that have been + # issued might have been modifications. + # See https://code.djangoproject.com/ticket/16491. + transaction.rollback() return None def getJobForBoard(self, board_name):