• kirrg001's avatar
    Fixed random test deadlocks temporarily · 03d48436
    kirrg001 authored
    no issue
    
    - we have seen random test failures recently
    - the cause: deadlocks
    
    - @NOTE: Deadlocks can and will happen naturally in innodb when multiple transactions are running and they operate on the same table.
      	 The challenge is just how to minimize, handle or avoid them.
    
    ---
    
    Why did the deadlock occur?
    
    The tests insert posts in parallel.
    As soon you insert two posts, we will attach the relations.
    
    The relations are basically: tags & authors.
    
    Both tables use foreign keys:
      post_id -> posts.id
      author_id -> users.id
      tag_id -> tags.id
    
    Attaching relations runs through two stages:
    - inserting or deleting the row (Bookshelf-Relations)
    - updating the row because of sort order (Ghost)
    
    2 or more transactions can create a deadlock on the target relation table because of X and S locks for the foreign key, which get automatically set.
    
    Refs:
    https://bugs.mysql.com/bug.php?id=48652
    https://www.chriscalender.com/advanced-innodb-deadlock-troubleshooting-what-show-innodb-status-doesnt-tell-you-and-what-diagnostics-you-should-be-looking-at/
    
    Long-Term?
    - investigate further
    - retry deadlocks if we know it's fine?
    - drop foreign key and handle in Bookshelf?
    03d48436
Name
Last commit
Last update
.github Loading commit data...
content Loading commit data...
core Loading commit data...
.editorconfig Loading commit data...
.eslintignore Loading commit data...
.eslintrc.json Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.gitmodules Loading commit data...
.npmignore Loading commit data...
.travis.yml Loading commit data...
Gruntfile.js Loading commit data...
LICENSE Loading commit data...
MigratorConfig.js Loading commit data...
PRIVACY.md Loading commit data...
README.md Loading commit data...
SECURITY.md Loading commit data...
index.js Loading commit data...
package.json Loading commit data...
yarn.lock Loading commit data...