mirror of
https://github.com/etcd-io/bbolt.git
synced 2025-05-31 11:42:30 +00:00
Merge pull request #379 from benbjohnson/tx-doc
Add docs for dependent transactions.
This commit is contained in:
commit
afceb316b9
@ -87,6 +87,11 @@ 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
|
||||||
|
another and generally shouldn't be opened simultaneously in the same goroutine.
|
||||||
|
This can cause a deadlock as the read-write transaction needs to periodically
|
||||||
|
re-map the data file but it cannot do so while a read-only transaction is open.
|
||||||
|
|
||||||
|
|
||||||
#### Read-write transactions
|
#### Read-write transactions
|
||||||
|
|
||||||
|
5
db.go
5
db.go
@ -401,6 +401,11 @@ func (db *DB) close() error {
|
|||||||
// will cause the calls to block and be serialized until the current write
|
// will cause the calls to block and be serialized until the current write
|
||||||
// transaction finishes.
|
// transaction finishes.
|
||||||
//
|
//
|
||||||
|
// Transactions should not be depedent on one another. Opening a read
|
||||||
|
// transaction and a write transaction in the same goroutine can cause the
|
||||||
|
// writer to deadlock because the database periodically needs to re-mmap itself
|
||||||
|
// as it grows and it cannot do that while a read transaction is open.
|
||||||
|
//
|
||||||
// IMPORTANT: You must close read-only transactions after you are finished or
|
// IMPORTANT: You must close read-only transactions after you are finished or
|
||||||
// else the database will not reclaim old pages.
|
// else the database will not reclaim old pages.
|
||||||
func (db *DB) Begin(writable bool) (*Tx, error) {
|
func (db *DB) Begin(writable bool) (*Tx, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user