Skip to content

Skip concurrently stored link pairs and tell FOR UPDATE OF by the MySQL version - #7

Merged
SoloPHP merged 3 commits into
mainfrom
rc6/concurrent-links
Oct 27, 2026
Merged

SoloPHP merged 3 commits into
mainfrom
rc6/concurrent-links

Conversation

@SoloPHP

@SoloPHP SoloPHP commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Two fixes found while moving the dilio storefront onto v1.0.0-RC5, plus the subclass compatibility rules for 1.x:

  • concurrent toggles of one wishlist product answered 500: 437 of 1,200 failed on the pivot's unique key on MySQL 8.4;
  • locking reads chose FOR UPDATE OF on MySQL through MySQL80Platform, which DBAL deprecates.

Changes

  • LinkSet skips a pair another writer stored first. attach() and sync() read the stored pairs and insert the missing ones. A pair another writer stored between that read and the INSERT failed the whole operation on the unique key, although it is the link the caller asked for. The INSERT now carries the conflict clause shared with upserts (Database::upsertClause()):

    • ON CONFLICT (foreignPivotKey, relatedPivotKey) DO NOTHING on PostgreSQL and SQLite;
    • ON DUPLICATE KEY UPDATE fk = fk on MySQL and MariaDB;
    • the plain INSERT on other platforms.

    The read stays, so attaching pairs that are already stored still only reads. Foreign-key violations still propagate.

  • FOR UPDATE OF on MySQL by the server version. Database::executeLocked() named the read's table when the platform was a MySQL80Platform. DBAL deprecates its MySQL 8 platform classes and drops them with MySQL 5.7 support, after which MySQLPlatform itself stands for MySQL 8: the check would turn false without an error, and the lock would also cover the rows the read joins. It now asks for a MySQLPlatform and a server version of 8.0.1 or later; MySQL 5.7 and MariaDB keep the plain FOR UPDATE. The tests no longer use deprecated DBAL platform classes.

  • Subclass compatibility rules (ce1a080): what typed repositories can rely on throughout 1.x.

  • Docs: docs/guide/api.md, details.md, migration.md and the changelog section "Changes since 1.0.0-RC5".

Behavior changes for RC5 users

  • Concurrent link writes. A pair stored concurrently is skipped instead of raising UniqueConstraintViolationException. MariaDB with innodb_snapshot_isolation (its default since 11.6, error 1020) and PostgreSQL in REPEATABLE READ or SERIALIZABLE (40001) still refuse a transaction whose snapshot is older than the other writer's commit; an exact final set still needs an owner lock.
  • The UNIQUE pair is enforced on PostgreSQL and SQLite. ON CONFLICT needs the UNIQUE (foreignPivotKey, relatedPivotKey) that the guide already required; a pivot without it now fails these writes there.

Verification

  • 644 unit tests, PHPStan max and PSR-12; composer validate --strict; the examples run; the documentation builds. The lowest supported DBAL, 4.3.5, also passes, the integration suite included.

  • New tests:

    • LinkSetTest::testInsertsSkipPairsStoredSinceTheRead — the pair INSERT on MySQL, MariaDB, PostgreSQL, SQLite and another platform;
    • LockingReadTest cases carry the server version, including MySQL 8 on the base MySQLPlatform and MySQL 5.7.
  • Integration suite on MySQL 8.4, MariaDB 12.3 and PostgreSQL 17, 39 tests on each. A second session stores a pair between attach()'s read and its INSERT (through a QueryLog hook), at the server's default isolation and at REPEATABLE READ:

    Server Before After
    MySQL 8.4 1062 duplicate entry pair skipped
    PostgreSQL 17, READ COMMITTED 23505 unique violation pair skipped
    PostgreSQL 17, REPEATABLE READ not run 40001, attach() rolls back
    MariaDB 12.3 1020 1020, attach() rolls back

    The existing NOWAIT test still shows that MySQL 8.4 locks only the read's table, so the version check applies OF.

  • The dilio storefront moves to RC6 right after the tag.

🤖 Generated with Claude Code

Repository is open for extension since RC4, which makes adding a public
method a possible break for an application's subclass. The API reference
and the changelog now state what subclasses can rely on throughout 1.x:
Repository stays a non-final readonly class with final public methods and
private state, a minor release may add public methods, and constructor
parameters keep their names and order, with new ones optional and last.
LinkSet::attach() and sync() read the stored pairs and insert the
missing ones. A pair another writer stored between that read and the
INSERT failed the whole operation on the pivot's unique key, although
it is the link the caller asked for. The INSERT now carries the
conflict clause shared with upserts: ON CONFLICT (pair) DO NOTHING on
PostgreSQL and SQLite, ON DUPLICATE KEY UPDATE on MySQL and MariaDB.
Foreign-key violations still propagate; other platforms keep the plain
INSERT.

Concurrent attaches of one pair now both succeed on MySQL and on
PostgreSQL in READ COMMITTED. MariaDB with snapshot isolation and
PostgreSQL above READ COMMITTED still refuse a transaction whose
snapshot is older than the other writer's commit. On PostgreSQL and
SQLite a pivot without the UNIQUE pair the guide requires now fails
these writes.
A locking read named its table with FOR UPDATE OF on MySQL when the
platform was a MySQL80Platform. DBAL deprecates its MySQL 8 platform
classes and drops them with MySQL 5.7 support, after which
MySQLPlatform itself stands for MySQL 8: the check would then turn
false without an error, and the lock would also cover the rows the
read joins. The server version now decides, 8.0.1 or later on a
MySQLPlatform; MySQL 5.7 and MariaDB keep the plain FOR UPDATE.

The tests no longer refer to a deprecated DBAL platform class.
@SoloPHP
SoloPHP merged commit ff122e9 into main Oct 27, 2026
26 checks passed
@SoloPHP
SoloPHP deleted the rc6/concurrent-links branch October 27, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant