Fork me on GitHub
#datalevin
<
2023-01-09
>
erdos19:01:18

Hi, is it safe to use datalevin in a multithreaded environment naively (sharing the same connection between threads, calling dc/transact! and dc/query directly) or do we have to take any extra steps to make it safe (with explicit mutexes, etc)?

Huahai19:01:17

With the latest version 0.7.10, yes. dc/transact! now is wrapped in a with-transaction macro, so it is ensured that all reads/writes inside are using the same single read/write transaction, which is guarded by a lock.

Huahai19:01:47

So you donโ€™t have to lock or do anything

erdos19:01:00

thanks for the quick reply. I have just started playing with with-transaction but I ran into some concurrency problems (one of them broke the db file too). Am I missing anything obvious? Details: https://stackoverflow.com/questions/75062000/datalevin-concurrency-transactions

erdos19:01:22

last version was still 0.7.8 about half an hour ago when I wrote the question on stackoverflow ๐Ÿ™‚

Huahai19:01:25

try with the latest

Huahai19:01:56

the latest is 0.7.10 (which is in the process of releasing), but the code is the same with 0.7.9, so you can try 0.7.9

๐Ÿ‘€ 2
Huahai19:01:13

please let me know if 0.7.9 works for you

erdos19:01:18

the exception is gone! 0.7.9 seems to do the trick. thanks for the help.

Huahai19:01:08

Glad it worked. Thanks for testing.

Huahai20:01:10

Interestingly, using a single thread writes faster too, as we are not dealing with thread contention.

๐Ÿ‘ 2
Huahai20:01:57

There are still some problems, I will release a new one soon to address the remaining issue

โž• 2
Huahai04:01:17

Fixed more concurrent tx issue. Thanks for the test case.