// buildSecondaryList is used for handling ON DUPLICATE DMLs, or those that change the PK.
502824
func buildSecondaryList(table *schema.Table, pkList [][]sqltypes.Value, secondaryList []sqltypes.PlanValue, bindVars map[string]*querypb.BindVariable) ([][]sqltypes.Value, error) {
	if secondaryList == nil {
		return nil, nil
	}
	secondaryRows, err := sqltypes.ResolveRows(secondaryList, bindVars)
	if err != nil {
		return nil, err
	}
	rows := make([][]sqltypes.Value, len(pkList))
	for i, row := range pkList {
		// If secondaryRows has only one row, then that
		// row should be duplicated for every row in pkList.
		// Otherwise, we use the individual values.
		var changedValues []sqltypes.Value
		if len(secondaryRows) == 1 {
			changedValues = secondaryRows[0]
		} else {
			changedValues = secondaryRows[i]
		}
		rows[i] = make([]sqltypes.Value, len(row))
		for j, value := range row {
			if changedValues[j].IsNull() {
				rows[i][j] = value
			} else {
				rows[i][j] = changedValues[j]
			}
		}
	}
	return rows, nil
}
725970
func (c *BuildConfigController) buildConfigUpdated(old, cur interface{}) {
	bc := cur.(*buildv1.BuildConfig)
	c.enqueueBuildConfig(bc)
}
1337996
func buildEtcdBackupManagerContainer(c *EtcdCluster) *v1.Container {
	command := []string{"/etcd-backup"}
	command = append(command, "--backup-store", c.BackupStore)
	command = append(command, "--cluster-name", c.ClusterName)
	command = append(command, "--data-dir", "/var/etcd/"+c.DataDirName)

	if c.isTLS() {
		command = append(command, "--client-url", "https://127.0.0.1:4001")
		command = append(command, "--client-ca-file", c.TLSCA)
		command = append(command, "--client-cert-file", c.TLSCert)
		command = append(command, "--client-key-file", c.TLSKey)
	}

	container := v1.Container{
		Name:    "etcd-backup",
		Image:   c.BackupImage,
		Command: command,
	}

	// TODO: TLS options
	// TODO: Liveness probe?

	// volume should already have been registered
	container.VolumeMounts = append(container.VolumeMounts, v1.VolumeMount{
		Name:      "varetcdata",
		MountPath: "/var/etcd/" + c.DataDirName,
		ReadOnly:  false,
	})

	if c.isTLS() {
		for _, dirname := range buildCertificateDirectories(c) {
			normalized := strings.Replace(dirname, "/", "", -1)

			// pod volume already registered for etcd container above
			container.VolumeMounts = append(container.VolumeMounts, v1.VolumeMount{
				Name:      normalized,
				MountPath: dirname,
				ReadOnly:  true,
			})
		}
	}

	return &container
}
1172898
func buildNodeIDMapFromAnnotation(node *v1.Node) (map[string]string, error) {
	var previousAnnotationValue string
	if node.ObjectMeta.Annotations != nil {
		previousAnnotationValue =
			node.ObjectMeta.Annotations[annotationKeyNodeID]
	}

	var existingDriverMap map[string]string
	if previousAnnotationValue != "" {
		// Parse previousAnnotationValue as JSON
		if err := json.Unmarshal([]byte(previousAnnotationValue), &existingDriverMap); err != nil {
			return nil, fmt.Errorf(
				"failed to parse node's %q annotation value (%q) err=%v",
				annotationKeyNodeID,
				previousAnnotationValue,
				err)
		}
	}

	if existingDriverMap == nil {
		return make(map[string]string), nil
	}
	return existingDriverMap, nil
}
972386
func (c *compaction) newIterator() iterator.Iterator {
	// Creates iterator slice.
	icap := len(c.levels)
	if c.sourceLevel == 0 {
		// Special case for level-0.
		icap = len(c.levels[0]) + 1
	}
	its := make([]iterator.Iterator, 0, icap)

	// Options.
	ro := &opt.ReadOptions{
		DontFillCache: true,
		Strict:        opt.StrictOverride,
	}
	strict := c.s.o.GetStrict(opt.StrictCompaction)
	if strict {
		ro.Strict |= opt.StrictReader
	}

	for i, tables := range c.levels {
		if len(tables) == 0 {
			continue
		}

		// Level-0 is not sorted and may overlaps each other.
		if c.sourceLevel+i == 0 {
			for _, t := range tables {
				its = append(its, c.s.tops.newIterator(t, nil, ro))
			}
		} else {
			it := iterator.NewIndexedIterator(tables.newIndexIterator(c.s.tops, c.s.icmp, nil, ro), strict)
			its = append(its, it)
		}
	}

	return iterator.NewMergedIterator(its, c.s.icmp, strict)
}
1152976
func (r *crdHandler) GetCustomResourceListerCollectionDeleter(crd *apiextensions.CustomResourceDefinition) (finalizer.ListerCollectionDeleter, error) {
	info, err := r.getOrCreateServingInfoFor(crd)
	if err != nil {
		return nil, err
	}
	return info.storages[info.storageVersion].CustomResource, nil
}
1316341
func (p *propertySet) buildNodeMap(allocs []*structs.Allocation) (map[string]*structs.Node, error) {
	// Get all the nodes that have been used by the allocs
	nodes := make(map[string]*structs.Node)
	ws := memdb.NewWatchSet()
	for _, alloc := range allocs {
		if _, ok := nodes[alloc.NodeID]; ok {
			continue
		}

		node, err := p.ctx.State().NodeByID(ws, alloc.NodeID)
		if err != nil {
			return nil, fmt.Errorf("failed to lookup node ID %q: %v", alloc.NodeID, err)
		}

		nodes[alloc.NodeID] = node
	}

	return nodes, nil
}
959475
func (s *ImageStoreService) NewListSecondaryStagingStoresParams() *ListSecondaryStagingStoresParams {
	p := &ListSecondaryStagingStoresParams{}
	p.p = make(map[string]interface{})
	return p
}
1175465
func (s *ImageStoreService) CreateSecondaryStagingStore(p *CreateSecondaryStagingStoreParams) (*CreateSecondaryStagingStoreResponse, error) {
	resp, err := s.cs.newRequest("createSecondaryStagingStore", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r CreateSecondaryStagingStoreResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
267713
func (b *EtcdManagerBuilder) Build(c *fi.ModelBuilderContext) error {
	for _, etcdCluster := range b.Cluster.Spec.EtcdClusters {
		if etcdCluster.Provider != kops.EtcdProviderTypeManager {
			continue
		}

		name := etcdCluster.Name
		version := etcdCluster.Version

		backupStore := ""
		if etcdCluster.Backups != nil {
			backupStore = etcdCluster.Backups.BackupStore
		}
		if backupStore == "" {
			return fmt.Errorf("backupStore must be set for use with etcd-manager")
		}

		manifest, err := b.buildManifest(etcdCluster)
		if err != nil {
			return err
		}

		manifestYAML, err := k8scodecs.ToVersionedYaml(manifest)
		if err != nil {
			return fmt.Errorf("error marshaling manifest to yaml: %v", err)
		}

		c.AddTask(&fitasks.ManagedFile{
			Contents:  fi.WrapResource(fi.NewBytesResource(manifestYAML)),
			Lifecycle: b.Lifecycle,
			Location:  fi.String("manifests/etcd/" + name + ".yaml"),
			Name:      fi.String("manifests-etcdmanager-" + name),
		})

		info := &etcdClusterSpec{
			EtcdVersion: version,
			MemberCount: int32(len(etcdCluster.Members)),
		}

		d, err := json.MarshalIndent(info, "", "  ")
		if err != nil {
			return err
		}

		format := string(fi.KeysetFormatV1Alpha2)

		c.AddTask(&fitasks.ManagedFile{
			Contents:  fi.WrapResource(fi.NewBytesResource(d)),
			Lifecycle: b.Lifecycle,
			// TODO: We need this to match the backup base (currently)
			Location: fi.String("backups/etcd/" + etcdCluster.Name + "/control/etcd-cluster-spec"),
			Name:     fi.String("etcd-cluster-spec-" + name),
		})

		// We create a CA keypair to enable secure communication
		c.AddTask(&fitasks.Keypair{
			Name:    fi.String("etcd-manager-ca-" + etcdCluster.Name),
			Subject: "cn=etcd-manager-ca-" + etcdCluster.Name,
			Type:    "ca",
			Format:  format,
		})

		// We create a CA for etcd peers and a separate one for clients
		c.AddTask(&fitasks.Keypair{
			Name:    fi.String("etcd-peers-ca-" + etcdCluster.Name),
			Subject: "cn=etcd-peers-ca-" + etcdCluster.Name,
			Type:    "ca",
			Format:  format,
		})

		// Because API server can only have a single client-cert, we need to share a client CA
		if err := c.EnsureTask(&fitasks.Keypair{
			Name:    fi.String("etcd-clients-ca"),
			Subject: "cn=etcd-clients-ca",
			Type:    "ca",
			Format:  format,
		}); err != nil {
			return err
		}
	}

	return nil
}
194454
func NewAddPaperDocUser(DocId string, Members []*AddMember) *AddPaperDocUser {
	s := new(AddPaperDocUser)
	s.DocId = DocId
	s.Members = Members
	s.Quiet = false
	return s
}
451938
func BuildConfigBuilds(c buildlister.BuildLister, namespace, name string, filterFunc buildFilter) ([]*buildv1.Build, error) {
	result, err := c.Builds(namespace).List(BuildConfigSelector(name))
	if err != nil {
		return nil, err
	}
	if filterFunc == nil {
		return result, nil
	}
	var filteredList []*buildv1.Build
	for _, b := range result {
		if filterFunc(b) {
			filteredList = append(filteredList, b)
		}
	}
	return filteredList, nil
}
1356218
func S3ArtifactPublisherDecorator(bucket gocf.Stringable,
	key gocf.Stringable,
	data map[string]interface{}) sparta.ServiceDecoratorHookHandler {

	// Setup the CF distro
	artifactDecorator := func(context map[string]interface{},
		serviceName string,
		template *gocf.Template,
		S3Bucket string,
		S3Key string,
		buildID string,
		awsSession *session.Session,
		noop bool,
		logger *logrus.Logger) error {

		// Ensure the custom action handler...
		sourceArnExpr := gocf.Join("",
			gocf.String("arn:aws:s3:::"),
			bucket.String(),
			gocf.String("/*"))

		configuratorResName, err := sparta.EnsureCustomResourceHandler(serviceName,
			cfCustomResources.S3ArtifactPublisher,
			sourceArnExpr,
			[]string{},
			template,
			S3Bucket,
			S3Key,
			logger)

		if err != nil {
			return err
		}

		// Create the invocation of the custom action...
		s3PublishResource := &cfCustomResources.S3ArtifactPublisherResource{}
		s3PublishResource.ServiceToken = gocf.GetAtt(configuratorResName, "Arn")
		s3PublishResource.Bucket = bucket.String()
		s3PublishResource.Key = key.String()
		s3PublishResource.Body = data

		// Name?
		resourceInvokerName := sparta.CloudFormationResourceName("ArtifactS3",
			fmt.Sprintf("%v", bucket.String()),
			fmt.Sprintf("%v", key.String()))

		// Add it
		template.AddResource(resourceInvokerName, s3PublishResource)
		return nil
	}
	return sparta.ServiceDecoratorHookFunc(artifactDecorator)
}
769477
func (s *UpdateProjectInput) SetSecondarySources(v []*ProjectSource) *UpdateProjectInput {
	s.SecondarySources = v
	return s
}
966060
func (b *Builder) Build() (*FileSorter, error) {
	// Sanity checks
	if b.sc == nil {
		return nil, errors.New("StatementContext is nil")
	}
	if b.keySize != len(b.byDesc) {
		return nil, errors.New("mismatch in key size and byDesc slice")
	}
	if b.keySize <= 0 {
		return nil, errors.New("key size is not positive")
	}
	if b.valSize <= 0 {
		return nil, errors.New("value size is not positive")
	}
	if b.bufSize <= 0 {
		return nil, errors.New("buffer size is not positive")
	}
	_, err := os.Stat(b.tmpDir)
	if err != nil {
		if os.IsNotExist(err) {
			return nil, errors.New("tmpDir does not exist")
		}
		return nil, errors.Trace(err)
	}

	rh := &rowHeap{sc: b.sc,
		ims:    make([]*item, 0),
		byDesc: b.byDesc,
	}

	return &FileSorter{sc: b.sc,
		keySize: b.keySize,
		valSize: b.valSize,
		bufSize: b.bufSize,
		buf:     make([]*comparableRow, 0, b.bufSize),
		files:   make([]string, 0),
		byDesc:  b.byDesc,
		rowHeap: rh,
		tmpDir:  b.tmpDir,
		fds:     make([]*os.File, 0),
	}, nil
}
180388
func (c *Client) Builder() (packer.Builder, error) {
	client, err := c.packrpcClient()
	if err != nil {
		return nil, err
	}

	return &cmdBuilder{client.Builder(), c}, nil
}
247501
func (s *Project) SetSecondarySources(v []*ProjectSource) *Project {
	s.SecondarySources = v
	return s
}