bolt
bolt copied to clipboard
Using the same db in function call
I know that Bolt obtains a file lock on the data file so multiple processes cannot open the same database at the same time. Opening an already open Bolt database will cause it to hang until the other process closes it. But what if there is a function call and it is accesing the same database and doing a read-write as well read-view operation on it. how can i do this ? Is there any method in which i can use go routines to update the db ?
I am very new to bolt and code improvement suggestions will be helpful. Playground link : http://play.golang.org/p/QCbJ9lK3HG
One more query: DB.Batch() is only meant to batch.Use case : there are lots of key-value pair is coming,where key is the time stamp,so if i use batching operation will it store in order of the time stamp or any random order? It can't do reordering since the order of operations in a batch may still matter to the application.
Read-only transactions can execute simultaneously, but only one writable transaction can run at a time. The point of that is you should not have any writable transaction depend on a read-only transaction (which would result in a deadlock). You can, of course, execute a writable tx and execute a read tx at roughly the same time - provided they don't depend on each other, you'll see the new, written data at some point in the future.
Re DB.Batch
- goroutines do not have an ordering guarantee. So, say you create goroutines like so:
- 1
- 2
- 3
You may have 2
executed first, 3
, etc - it won't be in the order you expect (this is also noted in #390 as the DB.Batch
doc needs to be fleshed out).