InitConnections create db connection and domain for storage.
(g glue.Glue, store kv.Storage)
| 629 | |
| 630 | // InitConnections create db connection and domain for storage. |
| 631 | func (rc *SnapClient) InitConnections(g glue.Glue, store kv.Storage) error { |
| 632 | // setDB must happen after set PolicyMode. |
| 633 | // we will use policyMode to set session variables. |
| 634 | var err error |
| 635 | rc.db, rc.supportPolicy, err = tidallocdb.NewDB(g, store, rc.policyMode) |
| 636 | if err != nil { |
| 637 | return errors.Trace(err) |
| 638 | } |
| 639 | rc.dom, err = g.GetDomain(store) |
| 640 | if err != nil { |
| 641 | return errors.Trace(err) |
| 642 | } |
| 643 | |
| 644 | // init backupMeta only for passing unit test |
| 645 | if rc.backupMeta == nil { |
| 646 | rc.backupMeta = new(backuppb.BackupMeta) |
| 647 | } |
| 648 | |
| 649 | // There are different ways to create session between in binary and in SQL. |
| 650 | // |
| 651 | // Maybe allow user modify the DDL concurrency isn't necessary, |
| 652 | // because executing DDL is really I/O bound (or, algorithm bound?), |
| 653 | // and we cost most of time at waiting DDL jobs be enqueued. |
| 654 | // So these jobs won't be faster or slower when machine become faster or slower, |
| 655 | // hence make it a fixed value would be fine. |
| 656 | rc.dbPool, err = makeDBPool(defaultDDLConcurrency, func() (*tidallocdb.DB, error) { |
| 657 | db, _, err := tidallocdb.NewDB(g, store, rc.policyMode) |
| 658 | return db, err |
| 659 | }) |
| 660 | if err != nil { |
| 661 | log.Warn("create session pool failed, we will send DDLs only by created sessions", |
| 662 | zap.Error(err), |
| 663 | zap.Int("sessionCount", len(rc.dbPool)), |
| 664 | ) |
| 665 | } |
| 666 | return errors.Trace(err) |
| 667 | } |
| 668 | |
| 669 | func SetSpeedLimitFn(ctx context.Context, stores []*metapb.Store, pool *tidbutil.WorkerPool) func(*SnapFileImporter, uint64) error { |
| 670 | return func(importer *SnapFileImporter, limit uint64) error { |