From d86c4e03664e4b476942eb76993584668a4203c5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 9 Jul 2012 10:39:21 -0700 Subject: [PATCH] Store forced connections in the Lisk connection cache Summary: In unit tests which use fixtures, we open transactions on every connection we establish. However, since we don't track connections that are established with "$force_new" (currently, only GlobalLock connections) we never close these transactions normally. Instead of not tracking these connections, track them using unique keys so we'll never get a cache hit on them. Test Plan: Built unit tests on top of this, had them stop dying from unclosed transactions. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T1162 Differential Revision: https://secure.phabricator.com/D2938 --- src/infrastructure/storage/lisk/LiskDAO.php | 26 ++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/infrastructure/storage/lisk/LiskDAO.php b/src/infrastructure/storage/lisk/LiskDAO.php index 6382094540..a1d832d241 100644 --- a/src/infrastructure/storage/lisk/LiskDAO.php +++ b/src/infrastructure/storage/lisk/LiskDAO.php @@ -302,9 +302,18 @@ abstract class LiskDAO { */ protected function setEstablishedConnection( $mode, - AphrontDatabaseConnection $connection) { + AphrontDatabaseConnection $connection, + $force_unique = false) { $key = $this->getConnectionNamespace().':'.$mode; + + if ($force_unique) { + $key .= ':unique'; + while (isset(self::$connections[$key])) { + $key .= '!'; + } + } + self::$connections[$key] = $connection; return $this; } @@ -483,7 +492,7 @@ abstract class LiskDAO { * * @task load */ - public function loadAllWhere($pattern/*, $arg, $arg, $arg ... */) { + public function loadAllWhere($pattern/* , $arg, $arg, $arg ... */) { $args = func_get_args(); array_unshift($args, null); $data = call_user_func_array( @@ -503,7 +512,7 @@ abstract class LiskDAO { * * @task load */ - public function loadColumnsWhere(array $columns, $pattern/*, $args... */) { + public function loadColumnsWhere(array $columns, $pattern/* , $args... */) { if (!$this->getConfigOption(self::CONFIG_PARTIAL_OBJECTS)) { throw new BadMethodCallException( "This class does not support partial objects."); @@ -528,7 +537,7 @@ abstract class LiskDAO { * * @task load */ - public function loadOneWhere($pattern/*, $arg, $arg, $arg ... */) { + public function loadOneWhere($pattern/* , $arg, $arg, $arg ... */) { $args = func_get_args(); array_unshift($args, null); $data = call_user_func_array( @@ -549,7 +558,7 @@ abstract class LiskDAO { } - protected function loadRawDataWhere($columns, $pattern/*, $args... */) { + protected function loadRawDataWhere($columns, $pattern/* , $args... */) { $connection = $this->establishConnection('r'); $lock_clause = ''; @@ -1009,9 +1018,10 @@ abstract class LiskDAO { if (self::shouldIsolateAllLiskEffectsToTransactions()) { $connection->openTransaction(); } - if (!$force_new) { - $this->setEstablishedConnection($mode, $connection); - } + $this->setEstablishedConnection( + $mode, + $connection, + $force_unique = $force_new); } return $connection;