Closed freitzzz closed 3 weeks ago
You need to execute it synchronously. The bucket instance is only valid during the lifecycle of the transaction.
go func() {
uuid := models.UUID()
err := b.Put([]byte(uuid), binary.LittleEndian.AppendUint64([]byte{}, uint64(i)))
if err != nil {
fmt.Printf("put err, %v", err)
}
ch <- 1
}()
@ahrtr If I make it synchronous, what's the point of allowing concurrency in the batch op?
Concurrent Batch calls are opportunistically combined into larger transactions. Batch is only useful when there are multiple goroutines calling it.
Or maybe I read it wrong. Is it multiple calls inside a batch call OR multiple calls of batch?
Please read https://github.com/etcd-io/bbolt?tab=readme-ov-file#batch-read-write-transactions
The purpose of DB.Batch is to minimize the overhead of commit by combining multiple updates.
Hi
I'm considering using bbolt on my project, but after playing around with concurrency, I noticed the library panics a lot on concurrent calls. This is the sample code I'm using:
Some of the panic errors include:
Since I'm doing 50 concurrent calls, I assume I must be doing seriously wrong.
Can someone help me?