func (s *StateStore) AllocsByJob(ws memdb.WatchSet, jobID string, all bool) ([]*structs.Allocation, error) {
	txn := s.db.Txn(false)

	// Get the job
	var job *structs.Job
	rawJob, err := txn.First("jobs", "id", jobID)
	if err != nil {
		return nil, err
	}
	if rawJob != nil {
		job = rawJob.(*structs.Job)
	}

	// Get an iterator over the node allocations
	iter, err := txn.Get("allocs", "job", jobID)
	if err != nil {
		return nil, err
	}

	ws.Add(iter.WatchCh())

	var out []*structs.Allocation
	for {
		raw := iter.Next()
		if raw == nil {
			break
		}

		alloc := raw.(*structs.Allocation)
		// If the allocation belongs to a job with the same ID but a different
		// create index and we are not getting all the allocations whose Jobs
		// matches the same Job ID then we skip it
		if !all && job != nil && alloc.Job.CreateIndex != job.CreateIndex {
			continue
		}
		out = append(out, raw.(*structs.Allocation))
	}
	return out, nil
}
// AllocsByJob returns all the allocations by job id
AllocsByJob returns all the allocations by job id
// AllocsByJob returns all the allocations by job id
func (s *StateStore) AllocsByJob(ws memdb.WatchSet, jobID string, all bool) ([]*structs.Allocation, error) {
	txn := s.db.Txn(false)
	var job *structs.Job
	rawJob, err := txn.First("jobs", "id", jobID)
	if err != nil {
		return nil, err
	}
	if rawJob != nil {
		job = rawJob.(*structs.Job)
	}
	iter, err := txn.Get("allocs", "job", jobID)
	if err != nil {
		return nil, err
	}
	ws.Add(iter.WatchCh())
	var out []*structs.Allocation
	for {
		raw := iter.Next()
		if raw == nil {
			break
		}
		alloc := raw.(*structs.Allocation)
		if !all && job != nil && alloc.Job.CreateIndex != job.CreateIndex {
			continue
		}
		out = append(out, raw.(*structs.Allocation))
	}
	return out, nil
}
func ( s * StateStore ) AllocsByJob ( ws memdb . WatchSet , jobID string , all bool ) ( [ ] * structs . Allocation , error ) { txn := s . db . Txn ( false ) var job * structs . Job rawJob , err := txn . First ( " " , " " , jobID ) if err != nil { return nil , err } if rawJob != nil { job = rawJob . ( * structs . Job ) } iter , err := txn . Get ( " " , " " , jobID ) if err != nil { return nil , err } ws . Add ( iter . WatchCh ( ) ) var out [ ] * structs . Allocation for { raw := iter . Next ( ) if raw == nil { break } alloc := raw . ( * structs . Allocation ) if ! all && job != nil && alloc . Job . CreateIndex != job . CreateIndex { continue } out = append ( out , raw . ( * structs . Allocation ) ) } return out , nil }
AllocsByJob returns all the allocations by job id
AllocsByJob returns all the allocations by job id
// Get the job // Get an iterator over the node allocations // If the allocation belongs to a job with the same ID but a different // create index and we are not getting all the allocations whose Jobs // matches the same Job ID then we skip it