// NewVerticalSplitDiffWorker returns a new VerticalSplitDiffWorker object.
970748
func NewVerticalSplitDiffWorker(wr *wrangler.Wrangler, cell, keyspace, shard string, minHealthyRdonlyTablets, parallelDiffsCount int, destintationTabletType topodatapb.TabletType) Worker {
	return &VerticalSplitDiffWorker{
		StatusWorker:            NewStatusWorker(),
		wr:                      wr,
		cell:                    cell,
		keyspace:                keyspace,
		shard:                   shard,
		minHealthyRdonlyTablets: minHealthyRdonlyTablets,
		destinationTabletType:   destintationTabletType,
		parallelDiffsCount:      parallelDiffsCount,
		cleaner:                 &wrangler.Cleaner{},
	}
}
564803
func (scw *SplitCloneWorker) createKeyResolver(td *tabletmanagerdatapb.TableDefinition) (keyspaceIDResolver, error) {
	if scw.cloneType == verticalSplit {
		// VerticalSplitClone currently always has exactly one destination shard
		// and therefore does not require routing between multiple shards.
		return nil, nil
	}

	if *useV3ReshardingMode {
		return newV3ResolverFromTableDefinition(scw.keyspaceSchema, td)
	}
	return newV2Resolver(scw.destinationKeyspaceInfo, td)
}
992669
func NewBalancerBuilder(name string, pb PickerBuilder) balancer.Builder {
	return NewBalancerBuilderWithConfig(name, pb, Config{})
}
999329
func NewSplitDiffWorker(wr *wrangler.Wrangler, cell, keyspace, shard string, sourceUID uint32, excludeTables []string, minHealthyRdonlyTablets, parallelDiffsCount int, tabletType topodatapb.TabletType) Worker {
	return &SplitDiffWorker{
		StatusWorker:            NewStatusWorker(),
		wr:                      wr,
		cell:                    cell,
		keyspace:                keyspace,
		shard:                   shard,
		sourceUID:               sourceUID,
		excludeTables:           excludeTables,
		minHealthyRdonlyTablets: minHealthyRdonlyTablets,
		destinationTabletType:   tabletType,
		parallelDiffsCount:      parallelDiffsCount,
		cleaner:                 &wrangler.Cleaner{},
	}
}
738218
func NewWorker(config lease.ManagerConfig) (worker.Worker, error) {
	return lease.NewManager(config)
}
689226
func symmetricDifference(hostIDs []string, lbInstances []*cloudstack.VirtualMachine) ([]string, []string) {
	new := make(map[string]bool)
	for _, hostID := range hostIDs {
		new[hostID] = true
	}

	var remove []string
	for _, instance := range lbInstances {
		if new[instance.Id] {
			delete(new, instance.Id)
			continue
		}

		remove = append(remove, instance.Id)
	}

	var assign []string
	for hostID := range new {
		assign = append(assign, hostID)
	}

	return assign, remove
}
643708
func (vsdw *VerticalSplitDiffWorker) Run(ctx context.Context) error {
	resetVars()
	err := vsdw.run(ctx)

	vsdw.SetState(WorkerStateCleanUp)
	cerr := vsdw.cleaner.CleanUp(vsdw.wr)
	if cerr != nil {
		if err != nil {
			vsdw.wr.Logger().Errorf2(cerr, "CleanUp failed in addition to job error")
		} else {
			err = cerr
		}
	}
	if err != nil {
		vsdw.SetState(WorkerStateError)
		return err
	}
	vsdw.SetState(WorkerStateDone)
	return nil
}
145534
func NewWorker(srv *Server) (*Worker, error) {
	w := &Worker{
		srv:    srv,
		logger: srv.logger.ResetNamed("worker"),
		start:  time.Now(),
	}
	w.pauseCond = sync.NewCond(&w.pauseLock)
	go w.run()
	return w, nil
}
799855
func newUpgradeWorker(config Config, targetVersion int) (worker.Worker, error) {
	currentVersion, err := config.Facade.ModelEnvironVersion(config.ModelTag)
	if err != nil {
		return nil, errors.Trace(err)
	}

	return jujuworker.NewSimpleWorker(func(<-chan struct{}) error {
		// NOTE(axw) the abort channel is ignored, because upgrade
		// steps are not interruptible. If we find they need to be
		// interruptible, we should consider passing through a
		// context.Context for cancellation, and cancelling it if
		// the abort channel is signalled.
		setVersion := func(v int) error {
			return config.Facade.SetModelEnvironVersion(config.ModelTag, v)
		}
		setStatus := func(s status.Status, info string) error {
			return config.Facade.SetModelStatus(config.ModelTag, s, info, nil)
		}
		if targetVersion > currentVersion {
			if err := setStatus(status.Busy, fmt.Sprintf(
				"upgrading environ from version %d to %d",
				currentVersion, targetVersion,
			)); err != nil {
				return errors.Trace(err)
			}
		}
		if err := runEnvironUpgradeSteps(
			config.Environ,
			config.ControllerTag,
			config.ModelTag,
			currentVersion,
			targetVersion,
			setVersion,
			common.NewCloudCallContext(config.CredentialAPI, nil),
		); err != nil {
			info := fmt.Sprintf("failed to upgrade environ: %s", err)
			if err := setStatus(status.Error, info); err != nil {
				logger.Warningf("failed to update model status: %v", err)
			}
			return errors.Annotate(err, "upgrading environ")
		}
		if err := setStatus(status.Available, ""); err != nil {
			return errors.Trace(err)
		}
		config.GateUnlocker.Unlock()
		return nil
	}), nil
}
707100
func NewSimpleWorker(doWork func(stopCh <-chan struct{}) error) worker.Worker {
	w := &simpleWorker{}
	w.tomb.Go(func() error {
		return doWork(w.tomb.Dying())
	})
	return w
}
419708
func NewWorker() worker.Worker {
	var w terminationWorker
	c := make(chan os.Signal, 1)
	signal.Notify(c, TerminationSignal)
	w.tomb.Go(func() error {
		defer signal.Stop(c)
		return w.loop(c)
	})
	return &w
}
646773
func newWorker(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
	t := a.CurrentConfig().Tag()
	tag, ok := t.(names.MachineTag)
	if !ok {
		return nil, errors.Errorf("expected MachineTag, got %#v", t)
	}

	api := apidiskmanager.NewState(apiCaller, tag)

	return NewWorker(DefaultListBlockDevices, api), nil
}
454696
func NewProvisioner(disembedFunc func(string) ([]byte, error)) astilectron.Provisioner {
	return astilectron.NewDisembedderProvisioner(disembedFunc, filepath.Join(vendorDirectoryName, zipNameAstilectron), filepath.Join(vendorDirectoryName, zipNameElectron))
}
1319960
func NewMultiLevelSkipListWriter(spi MultiLevelSkipListWriterSPI,
	skipInterval, skipMultiplier, maxSkipLevels, df int) *MultiLevelSkipListWriter {

	numberOfSkipLevels := 1
	// calculate the maximum number of skip levels for this document frequency
	if df > skipInterval {
		numberOfSkipLevels = 1 + util.Log(int64(df/skipInterval), skipMultiplier)
	}
	// make sure it does not exceed maxSkipLevels
	if numberOfSkipLevels > maxSkipLevels {
		numberOfSkipLevels = maxSkipLevels
	}
	return &MultiLevelSkipListWriter{
		spi:                spi,
		skipInterval:       skipInterval,
		skipMultiplier:     skipMultiplier,
		numberOfSkipLevels: numberOfSkipLevels,
	}
}
465257
func NewInspectWorkerArgs(versionID string) *InspectWorkerArgs {
	args := new(InspectWorkerArgs)
	args.VersionID = versionID
	return args
}
545134
func NewCeleryWorker(broker CeleryBroker, backend CeleryBackend, numWorkers int) *CeleryWorker {
	return &CeleryWorker{
		broker:          broker,
		backend:         backend,
		numWorkers:      numWorkers,
		registeredTasks: map[string]interface{}{},
		rateLimitPeriod: 100 * time.Millisecond,
	}
}
1288050
func NewWorker(cfg Config) (worker.Worker, error) {
	w, err := NewFirewaller(cfg)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return w, nil
}