ILIAS icon indicating copy to clipboard operation
ILIAS copied to clipboard

Memberships: Prevent integrity constraint issues

Open mjansenDatabay opened this issue 1 year ago • 4 comments

If you monitor the log of ILIAS installations with many concurrent users, you often find dozens of integrity constraint violations for the object_members table.

These duplicate key issues are caused by race conditons. This commit makes the state modifying SQL statements more robust and prevents that exceptions or WSOD (white screen of death) are shown to the user. I added a ON DUPLICATE KEY UPDATE clause (possible, because we do not support Oracle or Postgres anymore) which updates only the relevant field(s) if the tuple already exists.

Important:

The use of VALUES() to refer to the new row and columns is deprecated beginning with MySQL 8.0.20, and is subject to removal in a future version of MySQL. Instead, use row and column aliases, as described in the next few paragraphs of this section.

Beginning with MySQL 8.0.19, it is possible to use an alias for the row, with, optionally, one or more of its columns to be inserted, following the VALUES or SET clause, and preceded by the AS keyword. Using the row alias new, the statement shown previously using VALUES() to access the new column values can be written in the form shown here:

See: https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html

mjansenDatabay avatar Mar 16 '23 09:03 mjansenDatabay

@alex40724 There is a difference. A REPLACE is equivalent to a DELETE/INSERT.

The main problem is:

Values for all columns are taken from the values specified in the [REPLACE] statement. Any missing columns are set to their default values, just as happens for [INSERT].

mjansenDatabay avatar Jun 19 '23 07:06 mjansenDatabay

@mjansenDatabay Yes, I know, but we are selecting from obj_members before anyway. So we could provide these or null values.

If we use INSERT... ON DUPLICATE... shouldn't the SELECTS and UPDATES be removed completely?

alex40724 avatar Jul 19 '23 11:07 alex40724

So we could provide these or null values.

You are right. I personally would try to use the most "atomic" approach.

If we use INSERT... ON DUPLICATE... shouldn't the SELECTS and UPDATES be removed completely?

Yes, I could change this.

mjansenDatabay avatar Jul 31 '23 14:07 mjansenDatabay

Hi @smeyer-ilias

As Technical Board, we regularly check for pull requests that have been open for a long time. Any Updates on this? Note, that you can also close this, if you are not able or if you not have the resources to look into it in detail.

Best regards! @kergomard

kergomard avatar Feb 20 '24 11:02 kergomard

Hi @smeyer-ilias, how should we proceed here?

mjansenDatabay avatar May 23 '24 06:05 mjansenDatabay

Thanks @mjansenDatabay for the fix and merge to R8

smeyer-ilias avatar Jun 11 '24 15:06 smeyer-ilias