// newRetrieveManager creates the retrieve manager
513659
func newRetrieveManager(peers *peerSet, dist *requestDistributor, serverPool peerSelector) *retrieveManager {
	return &retrieveManager{
		peers:      peers,
		dist:       dist,
		serverPool: serverPool,
		sentReqs:   make(map[uint64]*sentReq),
	}
}
725501
func WithRetry(retry retry.Opts) Opt {
	return func(options *options) {
		options.retry = retry
	}
}
227901
func NewMockManager(id string, cancel context.CancelFunc) Manager {
	return &mockManager{
		id:     id,
		cancel: cancel,
	}
}
1226680
func NewOwnerManager(etcdCli *clientv3.Client, prompt, id, key string, cancel context.CancelFunc) Manager {
	logPrefix := fmt.Sprintf("[%s] %s ownerManager %s", prompt, key, id)
	return &ownerManager{
		etcdCli:   etcdCli,
		id:        id,
		key:       key,
		prompt:    prompt,
		cancel:    cancel,
		logPrefix: logPrefix,
		logCtx:    logutil.WithKeyValue(context.Background(), "owner info", logPrefix),
	}
}
44447
func indefiniteRetry() retry.Iterator {
	return &retry.ExponentialBackoff{
		Limited: retry.Limited{
			Retries: -1,
			Delay:   500 * time.Millisecond,
		},
		MaxDelay: 30 * time.Second,
	}
}
683781
func WithRetentionEnforcer(finder BucketFinder) Option {
	return func(e *Engine) {
		e.retentionEnforcer = newRetentionEnforcer(e, finder)
	}
}
366391
func NewRollbackManager(ctx context.Context, logger log.Logger, backendsFunc func() []*MountEntry, router *Router, core *Core) *RollbackManager {
	r := &RollbackManager{
		logger:      logger,
		backends:    backendsFunc,
		router:      router,
		period:      rollbackPeriod,
		inflight:    make(map[string]*rollbackState),
		doneCh:      make(chan struct{}),
		shutdownCh:  make(chan struct{}),
		quitContext: ctx,
		core:        core,
	}
	return r
}
209807
func NewContainerManager(conf container.ManagerConfig) (container.Manager, error) {
	modelUUID := conf.PopValue(container.ConfigModelUUID)
	if modelUUID == "" {
		return nil, errors.Errorf("model UUID is required")
	}
	namespace, err := instance.NewNamespace(modelUUID)
	if err != nil {
		return nil, errors.Trace(err)
	}
	logDir := conf.PopValue(container.ConfigLogDir)
	if logDir == "" {
		logDir = agent.DefaultPaths.LogDir
	}

	availabilityZone := conf.PopValue(container.ConfigAvailabilityZone)
	if availabilityZone == "" {
		logger.Infof("Availability zone will be empty for this container manager")
	}

	imageMetaDataURL := conf.PopValue(config.ContainerImageMetadataURLKey)
	imageStream := conf.PopValue(config.ContainerImageStreamKey)

	conf.WarnAboutUnused()
	return &containerManager{
		namespace:        namespace,
		logDir:           logDir,
		availabilityZone: availabilityZone,
		imageMetadataURL: imageMetaDataURL,
		imageStream:      imageStream,
	}, nil
}
1065349
func (db *DB) NewGetter(mode ModeGet) *Getter {
	return &Getter{
		mode: mode,
		db:   db,
	}
}
988506
func NewEventManager() EventManagers {
	em := EventManager{
		events:   make(map[string]EventSubs),
		attaches: make(map[EventManagers]bool),
	}

	return &em
}
798590
func NewDatastoreManagementService(opts ...ManagementOption) DatastoreManagementService {
	s := &datastoreManagementService{
		QueueName:             "exec-rm-old-datastore-backups",
		ExpireAfter:           30 * 24 * time.Hour,
		APIDeleteBackupsURL:   "/api/datastore-management/delete-old-backups",
		DeleteOldBackupURL:    "/tq/datastore-management/delete-old-backups",
		DeleteUnitOfBackupURL: "/tq/datastore-management/delete-backup",
	}

	for _, opt := range opts {
		opt.implements(s)
	}

	return s
}
650915
func NewRetryTransport(retrier *retry.Retrier, transport RoundTripper) *RetryTransport {
	return &RetryTransport{
		Retrier: retrier,
		MethodsToRetry: map[string]bool{
			"":     true, // http.Client treats empty methods the same as "GET"
			"GET":  true,
			"HEAD": true,
		},
		Transport: transport,
	}
}
560500
func newReporter(
	maxRetries, backoff int,
	input, retries chan *utils.Message,
) *reportHandler {

	r := &reportHandler{
		input:   input,
		retries: retries,
		out:     make(chan *utils.Message),

		queued: make(map[uint64]interface{}),

		maxRetries: maxRetries,
		backoff:    backoff,
	}

	go func() {
		// Get reports from the handler channel
		for m := range r.input {
			// If the message has status code 0 (success) send the report to the user
			rep := m.Reports.Head().(Report)
			if rep.Code == 0 || r.maxRetries == 0 {
				r.out <- m
				continue
			}

			// If the message has status code != 0 (fail) but has been retried the
			// maximum number or retries also send it to the user
			if r.maxRetries > 0 && rep.retries >= r.maxRetries {
				r.out <- m
				continue
			}

			// In other case retry the message sending it again to the pipeline
			r.wg.Add(1)
			go func(m *utils.Message) {
				defer r.wg.Done()
				rep := m.Reports.Pop().(Report)
				rep.retries++
				m.Reports.Push(rep)
				<-time.After(time.Duration(r.backoff) * time.Second)
				r.retries <- m
			}(m)
		}

		r.wg.Wait()
		close(r.retries)
		close(r.out)
	}()

	Logger.Debug("Message Handler ready")

	return r
}
873819
func NewLogoManager(r *http.Request) *LogoManager {
	session := db.GetDBSession(r)
	return &LogoManager{
		session:    session,
		collection: getLogoCollection(session),
	}
}
450188
func newPackageManager() (packageManager, error) {
	if m, ok := newDPKG(); ok {
		return m, nil
	}
	return nil, errors.New("failed to find package manager")
}
939038
func (db *Database) GetEncrypterManager(transformedKey []byte) (*EncrypterManager, error) {
	return NewEncrypterManager(
		buildMasterKey(db, transformedKey),
		db.Header.FileHeaders.EncryptionIV,
	)
}
809213
func getRetryAfter(resp *http.Response) string {
	if resp == nil {
		return ""
	}

	return resp.Header.Get("Retry-After")
}