MCPcopy
hub / github.com/etcd-io/bbolt / run

Method run

concurrent_test.go:350–393  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

348}
349
350func (w *worker) run() (historyRecords, error) {
351 var rs historyRecords
352
353 ticker := time.NewTicker(1 * time.Second)
354 defer ticker.Stop()
355
356 for {
357 select {
358 case <-w.stopCh:
359 return rs, nil
360 default:
361 }
362
363 err := w.db.Update(func(tx *bolt.Tx) error {
364 for {
365 op := w.pickOperation()
366 bucket, key := w.pickBucket(), w.pickKey()
367 rec, eerr := executeOperation(op, tx, bucket, key, w.conf)
368 if eerr != nil {
369 opErr := fmt.Errorf("[%s: %s]: %w", w.name(), op, eerr)
370 w.t.Error(opErr)
371 w.errCh <- opErr
372 return opErr
373 }
374
375 rs = append(rs, rec)
376 if w.conf.workInterval != (duration{}) {
377 time.Sleep(randomDurationInRange(w.conf.workInterval.min, w.conf.workInterval.max))
378 }
379
380 select {
381 case <-ticker.C:
382 return nil
383 case <-w.stopCh:
384 return nil
385 default:
386 }
387 }
388 })
389 if err != nil {
390 return rs, err
391 }
392 }
393}
394
395func (w *worker) pickBucket() []byte {
396 return bucketName(mrand.Intn(w.conf.bucketCount))

Callers 1

runWorkerFunction · 0.45

Calls 9

pickOperationMethod · 0.95
pickBucketMethod · 0.95
pickKeyMethod · 0.95
nameMethod · 0.95
executeOperationFunction · 0.85
randomDurationInRangeFunction · 0.85
UpdateMethod · 0.80
ErrorfMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected