From fb4aef405cf46364cbfd7785ce4fcc3fee6e1e89 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Mon, 19 Oct 2015 15:23:50 -0400 Subject: [PATCH] Increase transaction isolation level to avoid duplicate shows, SAAS-1111 --- airtime_mvc/application/models/Show.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 2653fe848..504a53418 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -850,6 +850,9 @@ SQL; $con = Propel::getConnection(CcPrefPeer::DATABASE_NAME); try { $con->beginTransaction(); + //It is extremely important that we increase the transaction isolation level, so that if two + //requests cause the show schedule to be generated at the same time, one will be rolled back. + $con->exec("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"); //UTC DateTime object $showsPopUntil = Application_Model_Preference::GetShowsPopulatedUntil(); @@ -862,7 +865,9 @@ SQL; $con->commit(); } catch (Exception $e) { $con->rollBack(); - throw $e; + //throw $e; + Logging::warn("Did not create show instances due to transaction error. This is usually safe + and caused by two concurrent transactions. " . $e->getMessage()); } }