# HG changeset patch # User jbe # Date 1347548542 -7200 # Node ID 69d6fba0f84cbb9f3d591f40147a67433ee0ef0a # Parent e818f83e133bc545681b4bc06ce3c4f280de4672 Use EXCLUSIVE MODE table locks in function "lock_issue"("issue"."id") Avoids deadlocks caused by explicit FOR UPDATE row locks when updating member statements and implicit FOR SHARE row locks when writing snapshots. diff -r e818f83e133b -r 69d6fba0f84c core.sql --- a/core.sql Wed Jun 20 21:22:02 2012 +0200 +++ b/core.sql Thu Sep 13 17:02:22 2012 +0200 @@ -2925,10 +2925,10 @@ RETURNS VOID LANGUAGE 'plpgsql' VOLATILE AS $$ BEGIN - LOCK TABLE "member" IN SHARE MODE; - LOCK TABLE "privilege" IN SHARE MODE; - LOCK TABLE "membership" IN SHARE MODE; - LOCK TABLE "policy" IN SHARE MODE; + LOCK TABLE "member" IN EXCLUSIVE MODE; + LOCK TABLE "privilege" IN EXCLUSIVE MODE; + LOCK TABLE "membership" IN EXCLUSIVE MODE; + LOCK TABLE "policy" IN EXCLUSIVE MODE; PERFORM NULL FROM "issue" WHERE "id" = "issue_id_p" FOR UPDATE; -- NOTE: The row-level exclusive lock in combination with the -- share_row_lock_issue(_via_initiative)_trigger functions (which @@ -2936,7 +2936,7 @@ -- is changed, which could affect calculation of snapshots or -- counting of votes. Table "delegation" must be table-level-locked, -- as it also contains issue- and global-scope delegations. - LOCK TABLE "delegation" IN SHARE MODE; + LOCK TABLE "delegation" IN EXCLUSIVE MODE; LOCK TABLE "direct_population_snapshot" IN EXCLUSIVE MODE; LOCK TABLE "delegating_population_snapshot" IN EXCLUSIVE MODE; LOCK TABLE "direct_interest_snapshot" IN EXCLUSIVE MODE;