Replies: 6 comments
-
SQLite is transactional, so multiple write operations should work in isolation. Afaik we use transactions already all over the place and i think we only have one open connection to the db. Soo this should be fine. What might be missing is to handle roll back errors and retry them... but I'm not sure we have ever encountered them. Reading should be possible concurrently: this depends on the underlying file system. |
Beta Was this translation helpful? Give feedback.
-
Yes SQLite creates locks implicitly when you perform inserts, updates, deletes. https://docs.oracle.com/cd/E17076_05/html/bdb-sql/lockhandling.html. My point is the following. Assume the following transaction below Transaction
if you have two threads executing that transaction (or other but similar transactions), you only get a lock at step 3. Hence you should already ensure mutual exclusion before step 1. otherwise you will run in concurrency issues e.g. dirty writes. |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing the link. Very useful read :) @da-kami : I believe we have seen |
Beta Was this translation helpful? Give feedback.
-
I don't think we have concurrent writes by virtue of only being able to modify the CFD in one place (as mentioned above). Is it still a problem if we can write and read at the same time? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the link, that was indeed interesting. I dug a bit into the https://github.com/launchbadge/sqlx/blob/main/sqlx-core/src/sqlite/transaction.rs#L13-L15 https://github.com/launchbadge/sqlx/blob/main/sqlx-core/src/sqlite/connection/worker.rs#L157-L167 https://github.com/launchbadge/sqlx/blob/main/sqlx-core/src/transaction.rs#L218-L224 I am not sure how the We do see
Yes, this is currently ensured by updating open cfd data by the fact that we only have one instance of the
For moving cfds into Note that we might also have a problem of concurrent writes when creating a It would be interesting to discuss if database access can be improved by re-designing how/when we access the database and potentially a better retry mechanism within the db layer. |
Beta Was this translation helpful? Give feedback.
-
As for the original question...
I don't think it should, unless we changed how the application triggers data updates when persisting data. Given this order this should be fine, because only when the data is saved we tell the application to update it's state. Note that we do have read requests that are independent of Note that information not being available in the database yet can become a problem if the event and the event-data are not available at the same time! This is what happened for our We know that we trigger loading an open cfd from the database outside the |
Beta Was this translation helpful? Give feedback.
-
I think we are already implementing mutual exclusion when writing to the database because we only have one call to
append_event
in production:https://github.com/itchysats/itchysats/blob/1305340f1fbb8567ed72f594bbf03013cbae93da/daemon/src/process_manager.rs#L74
Since the
process_manager::Actor
can only handle one message at a time, we cannot be calling this line in parallel. Interestingly, we cannot do it for different CFDs either! I have no idea if that is a problem, but different CFDs are orthogonal, so we should be able to modify them at the same time.However, we are not preventing reading a CFD from the database whilst we're writing to that very same CFD, as far as I can tell. Am I right? If so, can it be a problem?
Originally posted by @luckysori in #2651 (comment)
Beta Was this translation helpful? Give feedback.
All reactions