Fungibility Updated 2025-07-16
Multi-qubit gate Updated 2025-07-16
The most common way to construct multi-qubit gates is to use single-qubit gates as part of a controlled quantum gate.
Periplasm Updated 2025-07-16
UPDATE with JOIN in Sequelize Updated 2025-07-16
No support:
Example with raw examples under nodejs/sequelize/raw/many_to_many.js
Kosovo Updated 2025-07-16
The European Union is a failure Updated 2025-07-16
It hasn't achieved anything beyond the Schengen zone.
Related:
- having more than one natural language is bad for the world
- Video "The Euro Has Never Been More Problematic by Yanis Varoufakis (2018)" youtu.be/cCA68U3P_Z8?t=433 mentions a quote attributed to Gandhi, although Quote Investigator does not think that the attribution evidence is strong:to which Ghandi answers:
What do you think of Western civilization?
Adolf Hitler Updated 2025-07-16
Cretaceous-Paleogene extinction event Updated 2025-07-16
Era Updated 2025-07-16
Geography of Europe Updated 2025-07-16
Iran Updated 2025-07-16
Israel Updated 2025-07-16
List of mines Updated 2025-07-16
Period (geology) Updated 2025-07-16
Turkey Updated 2025-07-16
Western World Updated 2025-07-16
Archean Updated 2025-07-16
Austria Updated 2025-07-16
Country in East Asia Updated 2025-07-16
nodejs/sequelize/raw/parallel_create_delete_empty_tag.js Updated 2025-07-16
In this example, posts have tags. When a post is deleted, we check to see if there are now any empty tags, and now we want to delete any empty tags that the post deletion may have created.
If we are creating and deleting posts concurrently, a naive implementation might wrongly delete the tags of a newly created post.
This could be due to a concurrency issue of the following types.
Failure case 1:which would result in the new post incorrectly not having the
- thread 2: delete old post
- thread 2: find all tags with 0 posts. Finds
tag0from the deleted old post which is now empty. - thread 1: create new post, which we want to have tag
tag0 - thread 1: try to create a new tag
tag0, but don't because it already exists, this is done using SQLite'sINSERT OR IGNORE INTOor PostgreSQL'sINSERT ... ON CONFLICT DO NOTHING - thread 1: assign
tag0to the new post by adding an entry to the join table - thread 2: delete all tags with 0 posts. It still sees from its previous search that
tag0is empty, and deletes it, which then cascades into the join table
tag0.Failure case 2:which leads to a foreign key failure, because the tag does not exist anymore when the assignment happens.
- thread 2: delete old post
- thread 2: find all tags with 0 posts
- thread 1: create new post
- thread 1: try to create a new tag
tag0, but don't because it already exists - thread 2: delete all tags with 0 posts. It still sees from its previous search that
tag0is empty, and deletes it - thread 1: assign
tag0to the new post
Failure case 3:which leads to a foreign key failure, because the tag does not exist anymore when the assignment happens.
- thread 2: delete old post
- thread 1: create new post, which we want to have tag
tag0 - thread 1: try to create a new tag
tag0, and succeed because it wasn't present - thread 2: find all tags with 0 posts, finds the tag that was just created
- thread 2: delete all tags with 0 posts, deleting the new tag
- thread 1: assign
tag0to the new post
Sample executions:All executions use 2 threads.
node --unhandled-rejections=strict ./parallel_create_delete_empty_tag.js p 9 1000 'READ COMMITTED': PostgreSQL, 9 tags, DELETE/CREATE thetag0test tag 1000 times, useREAD COMMITTEDExecution often fails, although not always. The failure is always:because the:error: insert or update on table "PostTag" violates foreign key constraint "PostTag_tagId_fkey"tries to insert a tag that was deleted in the other thread, as it didn't have any corresponding posts, so this is the foreign key failure.INSERT INTO "PostTag"node --unhandled-rejections=strict ./parallel_create_delete_empty_tag.js p 9 1000 'READ COMMITTED' 'FOR UPDATE': do aSELECT ... FOR UPDATEbefore trying toINSERT.This is likely correct and the fastest correct method according to our quick benchmarking, about 20% faster thanREPEATABLE READ.node --unhandled-rejections=strict ./parallel_create_delete_empty_tag.js p 9 1000 'REPEATABLE READ': repeatable readWe've never observed any failures with this level. This should likely fix the foreign key issue according to the PostgreSQL docs, since:- the
DELETE "Post"commit cannot start to be seen only in the middle of the thread 1 transaction - and then if DELETE happened, the thread 1 transaction will detect it, ROLLBACK, and re-run. TODO how does it detect the need rollback? Is it because of the foreign key? It is very hard to be sure about this kind of thing, just can't find the information. Related: postgreSQL serialization failure.
- the
node --unhandled-rejections=strict ./parallel_create_delete_empty_tag.js p 9 1000 'SERIALIZABLE': serializablenode --unhandled-rejections=strict ./parallel_create_delete_empty_tag.js p 9 1000 'NONE': magic value, don't use any transaction. Can blow up of course, since even less restrictions thanREAD COMMITTED
Some theoretical notes:
stackoverflow.com/questions/10935850/when-to-use-select-for-update from SELECT FOR UPDATE also talks about a similar example, and has relevant answers.
Unlisted articles are being shown, click here to show only listed articles.