Raunak Dugar
Raunak Dugar

Reputation: 247

Does boltdb support concurrent queries for reading and updating the db?

Currently using boltdb for storing various entries in the bucket.

How can I use goroutines and channels in reading and updating in the db?

Upvotes: 4

Views: 2798

Answers (1)

Didier Spezia
Didier Spezia

Reputation: 73306

Generally, yes you can, provided you pay attention to the following points:

  • all accesses should be done in their own transactions. Transactions should not be shared between goroutines (whether they are read-only or read-write).

  • boltdb only tolerates one writer at a given point in time. If multiple concurrent transactions try to write at the same time, they will be serialized. The consistency of the database is guaranteed, but it has an impact on the performance, since write operations cannot be parallelized.

  • read-only transactions are executed concurrently (and potentially parallelized).

  • open only one transaction in a given goroutine at the same time to avoid deadlock situations.

Upvotes: 10

Related Questions