ExecuteBatch atomically incorporates the provided Batch into the collection. The Batch instance should not be reused after ExecuteBatch() returns.
(bIn Batch, writeOptions WriteOptions)
| 295 | // collection. The Batch instance should not be reused after |
| 296 | // ExecuteBatch() returns. |
| 297 | func (m *collection) ExecuteBatch(bIn Batch, |
| 298 | writeOptions WriteOptions) error { |
| 299 | startTime := time.Now() |
| 300 | |
| 301 | defer func() { |
| 302 | m.fireEvent(EventKindBatchExecute, time.Now().Sub(startTime)) |
| 303 | }() |
| 304 | |
| 305 | atomic.AddUint64(&m.stats.TotExecuteBatchBeg, 1) |
| 306 | |
| 307 | b, ok := bIn.(*batch) |
| 308 | if !ok { |
| 309 | atomic.AddUint64(&m.stats.TotExecuteBatchErr, 1) |
| 310 | |
| 311 | return fmt.Errorf("wrong Batch implementation type") |
| 312 | } |
| 313 | |
| 314 | if b == nil || b.isEmpty() { |
| 315 | atomic.AddUint64(&m.stats.TotExecuteBatchEmpty, 1) |
| 316 | |
| 317 | m.histograms["ExecuteBatchUsecs"].Add( |
| 318 | uint64(time.Since(startTime).Nanoseconds()/1000), 1) |
| 319 | |
| 320 | return nil |
| 321 | } |
| 322 | |
| 323 | maxPreMergerBatches := m.options.MaxPreMergerBatches |
| 324 | if maxPreMergerBatches <= 0 { |
| 325 | maxPreMergerBatches = |
| 326 | DefaultCollectionOptions.MaxPreMergerBatches |
| 327 | } |
| 328 | |
| 329 | if m.options.DeferredSort { |
| 330 | b.readyDeferredSort() // Recursively ready child batches. |
| 331 | } else { |
| 332 | b.doSort() // Recursively sort the child batches. |
| 333 | } |
| 334 | |
| 335 | // Notify handlers that we are about to execute a batch. |
| 336 | m.fireEvent(EventKindBatchExecuteStart, 0) |
| 337 | |
| 338 | m.m.Lock() |
| 339 | |
| 340 | for m.stackDirtyTop != nil && |
| 341 | len(m.stackDirtyTop.a) >= maxPreMergerBatches { |
| 342 | if m.isClosed() { |
| 343 | m.m.Unlock() |
| 344 | return ErrClosed |
| 345 | } |
| 346 | |
| 347 | if m.options.DeferredSort { |
| 348 | go b.RequestSort() // While waiting, might as well sort. |
| 349 | } |
| 350 | |
| 351 | atomic.AddUint64(&m.stats.TotExecuteBatchWaitBeg, 1) |
| 352 | m.stackDirtyTopCond.Wait() |
| 353 | atomic.AddUint64(&m.stats.TotExecuteBatchWaitEnd, 1) |
| 354 | } |
nothing calls this directly
no test coverage detected