Eindhoven 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.
France Updated 2025-07-16
Hadean Updated 2025-07-16
Historic counties of England Updated 2025-07-16
Proterozoic Updated 2025-07-16
Sinophile Updated 2025-07-16
Tael Updated 2025-07-16
Tokyo Updated 2025-07-16
Literally: "capital of the East". Note that the Chinese term 东京 (dong1 jing1) is highly ambiguous in historical contexts, as many places throughout history have been known as "the capital of the East".Of of those other places is the Kaifeng, which is the Capital in Water Margin and in real life during the Song dynasty. The novel is also likely highly popular in Japan apparently as well BTW, e.g. it merited a well funded adaptation: The Water Margin.
Bird Updated 2025-07-16
City in Shandong Updated 2025-07-16
County in South East England Updated 2025-07-16
Mammal Updated 2025-07-16
Mojim Updated 2025-07-16
Leading Chinese lyrics website: mojim.com/twznew.htm
Citric acid cycle Updated 2025-07-16
The key metabolic pathway of cellular respiration.
Compile MicroPython code for Micro Bit locally on Ubuntu 22.04 with your own firmware Updated 2025-07-27
TODO didn't manage from source Ubuntu 22.04, their setup bitrotted way too fast... it's shameful even. Until I gave up and went for the magic Docker of + github.com/bbcmicrobit/micropython, and it bloody worked:
git clone https://github.com/bbcmicrobit/micropython
cd micropython
git checkout 7fc33d13b31a915cbe90dc5d515c6337b5fa1660
docker pull ghcr.io/carlosperate/microbit-toolchain:latest
docker run -v $(pwd):/home --rm ghcr.io/carlosperate/microbit-toolchain:latest yt target bbc-microbit-classic-gcc-nosd@https://github.com/lancaster-university/yotta-target-bbc-microbit-classic-gcc-nosd
docker run -v $(pwd):/home --rm ghcr.io/carlosperate/microbit-toolchain:latest make all
# Build one.
tools/makecombinedhex.py build/firmware.hex examples/counter.py -o build/counter.hex
cp build/counter.hex "/media/$USER/MICROBIT/"
# Build all.
for f in examples/*; do b="$(basename "$f")"; echo $b; tools/makecombinedhex.py build/firmware.hex "$f" -o "build/${b%.py}.hex"; doneThe pre-Docker attempts:
sudo add-apt-repository -y ppa:team-gcc-arm-embedded
sudo apt update
sudo apt install gcc-arm-embedded
sudo apt install cmake ninja-build srecord libssl-dev
# Rust required for some Yotta component, OMG.
sudo snap install rustup
rustup default 1.64.0
python3 -m pip install yottaThe line:warns:and then the update/
sudo add-apt-repository -y ppa:team-gcc-arm-embeddedE: The repository 'https://ppa.launchpadcontent.net/team-gcc-arm-embedded/ppa/ubuntu jammy Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.sudo apt-get install gcc-arm-embedded fails, bibliography:Attempting to install Yotta:or:was failing with:Running:did not help. Bibliography:
sudo -H pip3 install yottapython3 -m pip install --user yottaException: Version mismatch: this is the 'cffi' package version 1.15.1, located in '/tmp/pip-build-env-dinhie_9/overlay/local/lib/python3.10/dist-packages/cffi/api.py'. When we import the top-level '_cffi_backend' extension module, we get version 1.15.0, located in '/usr/lib/python3/dist-packages/_cffi_backend.cpython-310-x86_64-linux-gnu.so'. The two versions should be equal; check your installation.python3 -m pip install --user cffi==1.15.1From a clean virtualenv, it appears to move further, and then fails at:So we install Rust and try again, OMG:which at the time of writing was
Building wheel for cmsis-pack-manager (pyproject.toml) ... error
error: [Errno 2] No such file or directory: 'cargo'sudo snap install rustup
rustup default stablerustc 1.64.0, and then OMG, it worked!! We have the yt command.However, it is still broken, e.g.:blows up:bibliography:
git clone https://github.com/lancaster-university/microbit-samples
cd microbit-samples
git checkout 285f9acfb54fce2381339164b6fe5c1a7ebd39d5
cp source/examples/invaders/* source
yt clean
yt buildannot import name 'soft_unicode' from 'markupsafe' WhatsApp Updated 2025-07-16
Claimed to remove metadata from servers unless legally obliged to collect it: www.quora.com/Does-WhatsApp-store-messages-on-its-servers-or-is-all-deleted-after-delivery-and-only-stored-on-recipients-phones/answer/Ciro-Santilli
They claim to delete metadata: www.quora.com/Does-WhatsApp-store-messages-on-its-servers-or-is-all-deleted-after-delivery-and-only-stored-on-recipients-phones/answer/Ciro-Santilli
Congee Updated 2025-07-16
Marketing Updated 2025-07-16
There are unlisted articles, also show them or only show them.
