CommitExWithContext commits the current transaction and returns all the pooled queries with context.
( ctx context.Context)
| 606 | // CommitExWithContext commits the current transaction and returns all the pooled queries |
| 607 | // with context. |
| 608 | func (s *State) CommitExWithContext( |
| 609 | ctx context.Context) (failed []*types.Request, queries []*QueryTracker, err error, |
| 610 | ) { |
| 611 | var ( |
| 612 | start = time.Now() |
| 613 | |
| 614 | lockAcquired, committed, poolCleaned, lockReleased time.Duration |
| 615 | ) |
| 616 | |
| 617 | defer func() { |
| 618 | var fields = log.Fields{} |
| 619 | fields["1#lockAcquired"] = float64(lockAcquired.Nanoseconds()) / 1000 |
| 620 | if committed > 0 { |
| 621 | fields["2#committed"] = float64((committed - lockAcquired).Nanoseconds()) / 1000 |
| 622 | } |
| 623 | if poolCleaned > 0 { |
| 624 | fields["3#poolCleaned"] = float64((poolCleaned - committed).Nanoseconds()) / 1000 |
| 625 | } |
| 626 | if lockReleased > 0 { |
| 627 | fields["4#lockReleased"] = float64((lockReleased - poolCleaned).Nanoseconds()) / 1000 |
| 628 | } |
| 629 | log.WithFields(fields).Debug("Commit duration stat (us)") |
| 630 | }() |
| 631 | |
| 632 | s.Lock() |
| 633 | lockAcquired = time.Since(start) |
| 634 | defer func() { |
| 635 | s.Unlock() |
| 636 | lockReleased = time.Since(start) |
| 637 | }() |
| 638 | // Always try to commit before the block is produced |
| 639 | s.flushHandler() |
| 640 | committed = time.Since(start) |
| 641 | // Return pooled items and reset |
| 642 | failed = s.pool.failedList() |
| 643 | queries = s.pool.queries |
| 644 | for _, v := range s.pool.reads { |
| 645 | queries = append(queries, v) |
| 646 | } |
| 647 | s.pool = newPool() |
| 648 | poolCleaned = time.Since(start) |
| 649 | return |
| 650 | } |
| 651 | |
| 652 | func (s *State) flushHandler() { |
| 653 | s.commitHandler() |
no test coverage detected