Clarify transaction section (#59)

Even nested read-only transactions can cause deadlocks. This is due to golang's RWMutex behaviour.
It doesn't allow readers to acquire a lock if a write lock is pending. It's possible for a child read-only
transaction to block trying to acquire `mmaplock.RLock`, while a writer is trying to acquire
`mmaplock.Lock`. As a result, the parent transaction never releases its read lock on `mmaplock`, and the
application deadlocks.

This wasn't clear to me from the provided docs, which just mentions read/write and read transactions being nested.
pull/215/head
James Ravn 2020-04-06 22:46:16 +01:00 committed by GitHub
parent 68cc10a767
commit 6dc724cf03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -152,11 +152,12 @@ are not thread safe. To work with data in multiple goroutines you must start
a transaction for each one or use locking to ensure only one goroutine accesses a transaction for each one or use locking to ensure only one goroutine accesses
a transaction at a time. Creating transaction from the `DB` is thread safe. a transaction at a time. Creating transaction from the `DB` is thread safe.
Read-only transactions and read-write transactions should not depend on one Transactions should not depend on one another and generally shouldn't be opened
another and generally shouldn't be opened simultaneously in the same goroutine. simultaneously in the same goroutine. This can cause a deadlock as the read-write
This can cause a deadlock as the read-write transaction needs to periodically transaction needs to periodically re-map the data file but it cannot do so while
re-map the data file but it cannot do so while a read-only transaction is open. any read-only transaction is open. Even a nested read-only transaction can cause
a deadlock, as the child transaction can block the parent transaction from releasing
its resources.
#### Read-write transactions #### Read-write transactions