func (n *Node) batchUpdate(future *batchFuture, updates []*structs.Allocation) {
	// Prepare the batch update
	batch := &structs.AllocUpdateRequest{
		Alloc:        updates,
		WriteRequest: structs.WriteRequest{Region: n.srv.config.Region},
	}

	// Commit this update via Raft
	var mErr multierror.Error
	_, index, err := n.srv.raftApply(structs.AllocClientUpdateRequestType, batch)
	if err != nil {
		n.srv.logger.Printf("[ERR] nomad.client: alloc update failed: %v", err)
		mErr.Errors = append(mErr.Errors, err)
	}

	// For each allocation we are updating check if we should revoke any
	// Vault Accessors
	var revoke []*structs.VaultAccessor
	for _, alloc := range updates {
		// Skip any allocation that isn't dead on the client
		if !alloc.Terminated() {
			continue
		}

		// Determine if there are any Vault accessors for the allocation
		ws := memdb.NewWatchSet()
		accessors, err := n.srv.State().VaultAccessorsByAlloc(ws, alloc.ID)
		if err != nil {
			n.srv.logger.Printf("[ERR] nomad.client: looking up accessors for alloc %q failed: %v", alloc.ID, err)
			mErr.Errors = append(mErr.Errors, err)
		}

		revoke = append(revoke, accessors...)
	}

	if l := len(revoke); l != 0 {
		n.srv.logger.Printf("[DEBUG] nomad.client: revoking %d accessors due to terminal allocations", l)
		if err := n.srv.vault.RevokeTokens(context.Background(), revoke, true); err != nil {
			n.srv.logger.Printf("[ERR] nomad.client: batched accessor revocation failed: %v", err)
			mErr.Errors = append(mErr.Errors, err)
		}
	}

	// Respond to the future
	future.Respond(index, mErr.ErrorOrNil())
}
// batchUpdate is used to update all the allocations
batchUpdate is used to update all the allocations
// batchUpdate is used to update all the allocations
func (n *Node) batchUpdate(future *batchFuture, updates []*structs.Allocation) {
	batch := &structs.AllocUpdateRequest{
		Alloc:        updates,
		WriteRequest: structs.WriteRequest{Region: n.srv.config.Region},
	}
	var mErr multierror.Error
	_, index, err := n.srv.raftApply(structs.AllocClientUpdateRequestType, batch)
	if err != nil {
		n.srv.logger.Printf("[ERR] nomad.client: alloc update failed: %v", err)
		mErr.Errors = append(mErr.Errors, err)
	}
	var revoke []*structs.VaultAccessor
	for _, alloc := range updates {
		if !alloc.Terminated() {
			continue
		}
		ws := memdb.NewWatchSet()
		accessors, err := n.srv.State().VaultAccessorsByAlloc(ws, alloc.ID)
		if err != nil {
			n.srv.logger.Printf("[ERR] nomad.client: looking up accessors for alloc %q failed: %v", alloc.ID, err)
			mErr.Errors = append(mErr.Errors, err)
		}
		revoke = append(revoke, accessors...)
	}
	if l := len(revoke); l != 0 {
		n.srv.logger.Printf("[DEBUG] nomad.client: revoking %d accessors due to terminal allocations", l)
		if err := n.srv.vault.RevokeTokens(context.Background(), revoke, true); err != nil {
			n.srv.logger.Printf("[ERR] nomad.client: batched accessor revocation failed: %v", err)
			mErr.Errors = append(mErr.Errors, err)
		}
	}
	future.Respond(index, mErr.ErrorOrNil())
}
func ( n * Node ) batchUpdate ( future * batchFuture , updates [ ] * structs . Allocation ) { batch := & structs . AllocUpdateRequest { Alloc : updates , WriteRequest : structs . WriteRequest { Region : n . srv . config . Region } , } var mErr multierror . Error _ , index , err := n . srv . raftApply ( structs . AllocClientUpdateRequestType , batch ) if err != nil { n . srv . logger . Printf ( " " , err ) mErr . Errors = append ( mErr . Errors , err ) } var revoke [ ] * structs . VaultAccessor for _ , alloc := range updates { if ! alloc . Terminated ( ) { continue } ws := memdb . NewWatchSet ( ) accessors , err := n . srv . State ( ) . VaultAccessorsByAlloc ( ws , alloc . ID ) if err != nil { n . srv . logger . Printf ( " " , alloc . ID , err ) mErr . Errors = append ( mErr . Errors , err ) } revoke = append ( revoke , accessors ... ) } if l := len ( revoke ) ; l != 0 { n . srv . logger . Printf ( " " , l ) if err := n . srv . vault . RevokeTokens ( context . Background ( ) , revoke , true ) ; err != nil { n . srv . logger . Printf ( " " , err ) mErr . Errors = append ( mErr . Errors , err ) } } future . Respond ( index , mErr . ErrorOrNil ( ) ) }
batchUpdate is used to update all the allocations
batchUpdate is used to update all the allocations
// Prepare the batch update // Commit this update via Raft // For each allocation we are updating check if we should revoke any // Vault Accessors // Skip any allocation that isn't dead on the client // Determine if there are any Vault accessors for the allocation // Respond to the future