applyConfig applies the given cfg to reverseProxy. New config is applied only if non-nil error returned. Otherwise old config version is kept.
(cfg *config.Config)
| 625 | // New config is applied only if non-nil error returned. |
| 626 | // Otherwise old config version is kept. |
| 627 | func (rp *reverseProxy) applyConfig(cfg *config.Config) error { |
| 628 | // configLock protects from concurrent calls to applyConfig |
| 629 | // by serializing such calls. |
| 630 | // configLock shouldn't be used in other places. |
| 631 | rp.configLock.Lock() |
| 632 | defer rp.configLock.Unlock() |
| 633 | |
| 634 | clusters, err := newClusters(cfg.Clusters) |
| 635 | if err != nil { |
| 636 | return err |
| 637 | } |
| 638 | |
| 639 | rp.maxErrorReasonSize = int64(cfg.MaxErrorReasonSize) |
| 640 | |
| 641 | caches := make(map[string]*cache.AsyncCache, len(cfg.Caches)) |
| 642 | defer func() { |
| 643 | // caches is swapped with old caches from rp.caches |
| 644 | // on successful config reload - see the end of reloadConfig. |
| 645 | for _, tmpCache := range caches { |
| 646 | // Speed up applyConfig by closing caches in background, |
| 647 | // since the process of cache closing may be lengthy |
| 648 | // due to cleaning. |
| 649 | go tmpCache.Close() |
| 650 | } |
| 651 | }() |
| 652 | |
| 653 | // transactionsTimeout used for creation of transactions registry inside async cache. |
| 654 | // It is set to the highest configured execution time of all users to avoid setups were users use the same cache and have configured different maxExecutionTime. |
| 655 | // This would provoke undesired behaviour of `dogpile effect` |
| 656 | transactionsTimeout := config.Duration(0) |
| 657 | for _, user := range cfg.Users { |
| 658 | if user.MaxExecutionTime > transactionsTimeout { |
| 659 | transactionsTimeout = user.MaxExecutionTime |
| 660 | } |
| 661 | if user.IsWildcarded { |
| 662 | rp.hasWildcarded = true |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | if err := initTempCaches(caches, transactionsTimeout, cfg.Caches); err != nil { |
| 667 | return err |
| 668 | } |
| 669 | |
| 670 | params, err := paramsFromConfig(cfg.ParamGroups) |
| 671 | if err != nil { |
| 672 | return err |
| 673 | } |
| 674 | |
| 675 | profile := &usersProfile{ |
| 676 | cfg: cfg.Users, |
| 677 | clusters: clusters, |
| 678 | caches: caches, |
| 679 | params: params, |
| 680 | } |
| 681 | users, err := profile.newUsers() |
| 682 | if err != nil { |
| 683 | return err |
| 684 | } |