Comment 5 for bug 1514608

Revision history for this message
Aaron Wells (u-aaronw) wrote :

Okay, I was able to replicate this locally by hand, by having multiple users copy the same collection at the same time, and adding a command of "sleep(1)" into the execute_sql() function in lib/dml.php to increase the amount by which the queries overlap.

1. Set up a Mahara site with five users.
2. Have one of the users create a collection with several pages and artefacts.
3. Set the collection so that it is shared with all registered users, and it can be copied, and the owner retains view access to copies.
4. In four browser simultaneously:
4.1. Log in as one of the other four users.
4.2. View the copyable collection
4.3. Click the "copy" button (but don't yet click "Collection" in the confirmation popup)
5. Edit lib/dml.php, adding "sleep(1);" on line 138, inside of the execute_sql() function
6. In each of the four browsers in quick succession, click the "Collection" button.

Expected result: It should copy the collection successfully in all four sessions.
Actual result: Some of the sessions get a deadlock error message. In my case, two of them did, and they both deadlocked while trying to insert into the "view_rows_columns" table.

[WAR] d9 (lib/errors.php:747) Failed to get a recordset: mysqli error: [1213: Deadlock found when trying to get lock; try restarting transaction] in adodb_throw(INSERT INTO "view_rows_columns" ("view", "row", "columns") VALUES (64, 1, 3), )
Command was: INSERT INTO "view_rows_columns" ("view", "row", "columns") VALUES (?, ?, ?) and values was (64,1,3)
Call stack (most recent first):
log_message("Failed to get a recordset: mysqli error: [1213: De...", 8, true, true) at /home/aaronw/www/mahara/htdocs/lib/errors.php:97
log_warn("Failed to get a recordset: mysqli error: [1213: De...") at /home/aaronw/www/mahara/htdocs/lib/errors.php:747
SQLException->__construct("Failed to get a recordset: mysqli error: [1213: De...") at /home/aaronw/www/mahara/htdocs/lib/dml.php:1055
insert_record("view_rows_columns", object(stdClass)) at /home/aaronw/www/mahara/htdocs/lib/view.php:756
View->commit() at /home/aaronw/www/mahara/htdocs/lib/view.php:581
View::_create(array(size 5), "4") at /home/aaronw/www/mahara/htdocs/lib/view.php:377
View::create_from_template(array(size 5), "12", "4", true, false) at /home/aaronw/www/mahara/htdocs/lib/collection.php:286
Collection::create_from_template(array(size 3), 1) at /home/aaronw/www/mahara/htdocs/lib/view.php:6141
copyview("6", 0, null, 1) at /home/aaronw/www/mahara/htdocs/view/copy.php:32
[WAR] d9 (lib/errors.php:747) Failed to get a recordset: mysqli error: [1452: Cannot add or update a child row: a foreign key constraint fails ("mahara"."view_rows_columns", CONSTRAINT "viewrowscolu_vie_fk" FOREIGN KEY ("view") REFERENCES "view" ("id"))] in adodb_throw(INSERT INTO "view_rows_columns" ("view", "row", "columns") VALUES (64, 1, 3), )
Command was: INSERT INTO "view_rows_columns" ("view", "row", "columns") VALUES (?, ?, ?) and values was (64,1,3)
Call stack (most recent first):
log_message("Failed to get a recordset: mysqli error: [1452: Ca...", 8, true, true) at /home/aaronw/www/mahara/htdocs/lib/errors.php:97
log_warn("Failed to get a recordset: mysqli error: [1452: Ca...") at /home/aaronw/www/mahara/htdocs/lib/errors.php:747
SQLException->__construct("Failed to get a recordset: mysqli error: [1452: Ca...") at /home/aaronw/www/mahara/htdocs/lib/dml.php:1055
insert_record("view_rows_columns", object(stdClass)) at /home/aaronw/www/mahara/htdocs/lib/view.php:756
View->commit() at /home/aaronw/www/mahara/htdocs/lib/view.php:704
View->__destruct() at /home/aaronw/www/mahara/htdocs/lib/view.php:377
View::_create(array(size 5), "4") at /home/aaronw/www/mahara/htdocs/lib/view.php:377
View::create_from_template(array(size 5), "12", "4", true, false) at /home/aaronw/www/mahara/htdocs/lib/collection.php:286
Collection::create_from_template(array(size 3), 1) at /home/aaronw/www/mahara/htdocs/lib/view.php:6141
copyview("6", 0, null, 1) at /home/aaronw/www/mahara/htdocs/view/copy.php:32
[WAR] d9 (lib/dml.php:1055) Failed to get a recordset: mysqli error: [1452: Cannot add or update a child row: a foreign key constraint fails ("mahara"."view_rows_columns", CONSTRAINT "viewrowscolu_vie_fk" FOREIGN KEY ("view") REFERENCES "view" ("id"))] in adodb_throw(INSERT INTO "view_rows_columns" ("view", "row", "columns") VALUES (64, 1, 3), )
Command was: INSERT INTO "view_rows_columns" ("view", "row", "columns") VALUES (?, ?, ?) and values was (64,1,3)
Call stack (most recent first):
insert_record("view_rows_columns", object(stdClass)) at /home/aaronw/www/mahara/htdocs/lib/view.php:756
View->commit() at /home/aaronw/www/mahara/htdocs/lib/view.php:704
View->__destruct() at /home/aaronw/www/mahara/htdocs/lib/view.php:377
View::_create(array(size 5), "4") at /home/aaronw/www/mahara/htdocs/lib/view.php:377
View::create_from_template(array(size 5), "12", "4", true, false) at /home/aaronw/www/mahara/htdocs/lib/collection.php:286
Collection::create_from_template(array(size 3), 1) at /home/aaronw/www/mahara/htdocs/lib/view.php:6141
copyview("6", 0, null, 1) at /home/aaronw/www/mahara/htdocs/view/copy.php:32