// GetDDLJobByIdx returns the corresponding DDL job by the index.
// The length of jobListKeys can only be 1 or 0.
// If its length is 1, we need to replace m.jobListKey with jobListKeys[0].
// Otherwise, we use m.jobListKey directly.
559747
func (m *Meta) GetDDLJobByIdx(index int64, jobListKeys ...JobListKeyType) (*model.Job, error) {
	listKey := m.jobListKey
	if len(jobListKeys) != 0 {
		listKey = jobListKeys[0]
	}

	startTime := time.Now()
	job, err := m.getDDLJob(listKey, index)
	metrics.MetaHistogram.WithLabelValues(metrics.GetDDLJobByIdx, metrics.RetLabel(err)).Observe(time.Since(startTime).Seconds())
	return job, errors.Trace(err)
}
304146
func formatJobModifyIndex(jobModifyIndex uint64, jobName string) string {
	help := fmt.Sprintf(jobModifyIndexHelp, jobModifyIndex, jobName)
	out := fmt.Sprintf("[reset][bold]Job Modify Index: %d[reset]\n%s", jobModifyIndex, help)
	return out
}
576258
func (e *engineImpl) GetVisibleJobBatch(c context.Context, jobIDs []string) (map[string]*Job, error) {
	// TODO(vadimsh): This can be parallelized to be single GetMulti RPC to fetch
	// jobs and single filterForRole to check ACLs. In practice O(len(jobIDs)) is
	// small, so there's no pressing need to do this.
	visible := make(map[string]*Job, len(jobIDs))
	for _, id := range jobIDs {
		switch job, err := e.GetVisibleJob(c, id); {
		case err == nil:
			visible[id] = job
		case err != ErrNoSuchJob:
			return nil, err
		}
	}
	return visible, nil
}
340121
func getParentUIDFromJob(j batchv1.Job) (types.UID, bool) {
	controllerRef := metav1.GetControllerOf(&j)

	if controllerRef == nil {
		return types.UID(""), false
	}

	if controllerRef.Kind != "CronJob" {
		klog.V(4).Infof("Job with non-CronJob parent, name %s namespace %s", j.Name, j.Namespace)
		return types.UID(""), false
	}

	return controllerRef.UID, true
}
706191
func (d *Disque) GetJobDetails(jobID string) (jobDetails *JobDetails, err error) {
	var jobDetailsMap []interface{}
	if jobDetailsMap, err = redis.Values(d.call("SHOW", redis.Args{}.Add(jobID))); err == nil {
		var repl, ttl, delay, retry, nextRequeueWithin, nextAwakeWithin int
		var ctime, nacks, additionalDeliveries int64
		var nodesDelivered, nodesConfirmed []string

		repl, err = redis.Int(jobDetailsMap[7], err)
		ttl, err = redis.Int(jobDetailsMap[9], err)
		ctime, err = redis.Int64(jobDetailsMap[11], err)
		delay, err = redis.Int(jobDetailsMap[13], err)
		retry, err = redis.Int(jobDetailsMap[15], err)
		nacks, err = redis.Int64(jobDetailsMap[17], err)
		additionalDeliveries, err = redis.Int64(jobDetailsMap[19], err)
		nodesDelivered, err = redis.Strings(jobDetailsMap[21], err)
		nodesConfirmed, err = redis.Strings(jobDetailsMap[23], err)
		nextRequeueWithin, err = redis.Int(jobDetailsMap[25], err)
		nextAwakeWithin, err = redis.Int(jobDetailsMap[27], err)

		if err == nil {
			jobDetails = &JobDetails{
				JobID:                string(jobDetailsMap[1].([]byte)),
				QueueName:            string(jobDetailsMap[3].([]byte)),
				State:                string(jobDetailsMap[5].([]byte)),
				ReplicationFactor:    repl,
				TTL:                  time.Duration(ttl) * time.Second,
				CreatedAt:            time.Unix(0, ctime),
				Delay:                time.Duration(delay) * time.Second,
				Retry:                time.Duration(retry) * time.Second,
				Nacks:                nacks,
				AdditionalDeliveries: additionalDeliveries,
				NodesDelivered:       nodesDelivered,
				NodesConfirmed:       nodesConfirmed,
				NextRequeueWithin:    time.Duration(nextRequeueWithin/1000) * time.Second,
				NextAwakeWithin:      time.Duration(nextAwakeWithin/1000) * time.Second,
				Message:              string(jobDetailsMap[29].([]byte)),
			}
		}
	}
	return
}
577490
func (j *Jenkins) GetAllBuildIds(job string) ([]JobBuild, error) {
	jobObj, err := j.GetJob(job)
	if err != nil {
		return nil, err
	}
	return jobObj.GetAllBuildIds()
}
805584
func getJob(c context.Context, id JobID) (*Job, error) {
	job := &Job{ID: id}
	switch err := datastore.Get(c, job); {
	case err == datastore.ErrNoSuchEntity:
		return nil, ErrNoSuchJob
	case err != nil:
		return nil, errors.Annotate(err, "transient datastore error").Tag(transient.Tag).Err()
	default:
		return job, nil
	}
}
389975
func (worker *Worker) GetRegisteredJob(name string) *Job {
	for _, job := range worker.Jobs {
		if job.Name == name {
			return job
		}
	}
	return nil
}
920011
func (s *SchedulerServer) GetJobs(ctx context.Context, in *scheduler.JobsRequest) (*scheduler.JobsReply, error) {
	if in.GetCursor() != "" {
		// Paging in GetJobs isn't implemented until we have enough jobs to care.
		// Until then, not empty cursor implies no more jobs to return.
		return &scheduler.JobsReply{Jobs: []*scheduler.Job{}, NextCursor: ""}, nil
	}
	var ejobs []*engine.Job
	var err error
	if in.GetProject() == "" {
		ejobs, err = s.Engine.GetVisibleJobs(ctx)
	} else {
		ejobs, err = s.Engine.GetVisibleProjectJobs(ctx, in.GetProject())
	}
	if err != nil {
		return nil, status.Errorf(codes.Internal, "internal error: %s", err)
	}

	jobs := make([]*scheduler.Job, len(ejobs))
	for i, ej := range ejobs {
		traits, err := presentation.GetJobTraits(ctx, s.Catalog, ej)
		if err != nil {
			return nil, status.Errorf(codes.Internal, "failed to get traits: %s", err)
		}
		jobs[i] = &scheduler.Job{
			JobRef: &scheduler.JobRef{
				Project: ej.ProjectID,
				Job:     ej.JobName(),
			},
			Schedule: ej.Schedule,
			State: &scheduler.JobState{
				UiStatus: string(presentation.GetPublicStateKind(ej, traits)),
			},
			Paused: ej.Paused,
		}
	}
	return &scheduler.JobsReply{Jobs: jobs, NextCursor: ""}, nil
}
947225
func FindById(id string) (*Job, error) {
	job := &Job{}
	t := newTransaction()
	t.scanJobById(id, job)
	if err := t.exec(); err != nil {
		switch e := err.(type) {
		case ErrorJobNotFound:
			// If the job was not found, add the id to the error
			// so that the caller can get a more useful error message.
			e.id = id
			return nil, e
		default:
			return nil, err
		}
	}
	return job, nil
}
1190809
func (window *Window) GetDisplayIndex() (int, error) {
	i := int(C.SDL_GetWindowDisplayIndex(window.cptr()))
	return i, errorFromInt(i)
}
822829
func (m *Map) Get(id int64) *Package {
	m.lock.Lock()
	defer m.lock.Unlock()

	val := m.jobs[id]

	return val
}
715542
func (ctl *Controller) GetJob(c context.Context, id JobID) (*Job, error) {
	// Even though we could have made getJob public, we want to force API users
	// to use Controller as a single facade.
	return getJob(c, id)
}
800266
func (d *ddl) addDDLJob(ctx sessionctx.Context, job *model.Job) error {
	startTime := time.Now()
	job.Version = currentVersion
	job.Query, _ = ctx.Value(sessionctx.QueryString).(string)
	err := kv.RunInNewTxn(d.store, true, func(txn kv.Transaction) error {
		t := newMetaWithQueueTp(txn, job.Type.String())
		var err error
		job.ID, err = t.GenGlobalID()
		if err != nil {
			return errors.Trace(err)
		}
		job.StartTS = txn.StartTS()
		if err = buildJobDependence(t, job); err != nil {
			return errors.Trace(err)
		}
		err = t.EnQueueDDLJob(job)

		return errors.Trace(err)
	})
	metrics.DDLWorkerHistogram.WithLabelValues(metrics.WorkerAddDDLJob, job.Type.String(), metrics.RetLabel(err)).Observe(time.Since(startTime).Seconds())
	return errors.Trace(err)
}
428735
func (w *worker) finishDDLJob(t *meta.Meta, job *model.Job) (err error) {
	startTime := time.Now()
	defer func() {
		metrics.DDLWorkerHistogram.WithLabelValues(metrics.WorkerFinishDDLJob, job.Type.String(), metrics.RetLabel(err)).Observe(time.Since(startTime).Seconds())
	}()

	if !job.IsCancelled() {
		switch job.Type {
		case model.ActionAddIndex:
			if job.State != model.JobStateRollbackDone {
				break
			}

			// After rolling back an AddIndex operation, we need to use delete-range to delete the half-done index data.
			err = w.deleteRange(job)
		case model.ActionDropSchema, model.ActionDropTable, model.ActionTruncateTable, model.ActionDropIndex, model.ActionDropTablePartition, model.ActionTruncateTablePartition:
			err = w.deleteRange(job)
		}
	}
	switch job.Type {
	case model.ActionRecoverTable:
		err = finishRecoverTable(w, t, job)
	}
	if err != nil {
		return errors.Trace(err)
	}

	_, err = t.DeQueueDDLJob()
	if err != nil {
		return errors.Trace(err)
	}

	job.BinlogInfo.FinishedTS = t.StartTS
	logutil.Logger(w.logCtx).Info("[ddl] finish DDL job", zap.String("job", job.String()))
	err = t.AddHistoryDDLJob(job)
	return errors.Trace(err)
}
1181346
func (table *Table) GetColumnIdx(name string, idx int) *Column {
	if c, ok := table.columnsMap[strings.ToLower(name)]; ok {
		if idx < len(c) {
			return c[idx]
		}
	}
	return nil
}
923337
func (i *Index) partitionIdx(key []byte) int {
	return int(xxhash.Sum64(key) & (i.PartitionN - 1))
}