Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

(Refactoring) Exclusive transaction #1

Open
andy0130tw opened this issue Jun 1, 2017 · 0 comments
Open

(Refactoring) Exclusive transaction #1

andy0130tw opened this issue Jun 1, 2017 · 0 comments

Comments

@andy0130tw
Copy link
Owner

andy0130tw commented Jun 1, 2017

The project had made a big mistake leading to deadlocks by using a single transaction to findOrCreate. I had avoid it by caching associated objects in memory and had painfully used lots of tedious Promises / async to do careful writings.

Today, by reading the document of SQLite, I noticed that the type of transactions are default to DEFERRED. This was why the deadlocks happened. The solution is quite straightforward; by changing the type to EXCLUSIVE and those operations can be done concurrently like our intuitions.

https://sqlite.org/lang_transaction.html

To use it in sequelize: http://docs.sequelizejs.com/class/lib/transaction.js~Transaction.html#static-get-TYPES

The refactoring can also be painful.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant