github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cmd/roachtest/indexes.go (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package main
    12  
    13  import (
    14  	"context"
    15  	"fmt"
    16  	"strconv"
    17  	"strings"
    18  )
    19  
    20  func registerNIndexes(r *testRegistry, secondaryIndexes int) {
    21  	const nodes = 6
    22  	geoZones := []string{"us-west1-b", "us-east1-b", "us-central1-a"}
    23  	geoZonesStr := strings.Join(geoZones, ",")
    24  	r.Add(testSpec{
    25  		Name:    fmt.Sprintf("indexes/%d/nodes=%d/multi-region", secondaryIndexes, nodes),
    26  		Owner:   OwnerKV,
    27  		Cluster: makeClusterSpec(nodes+1, cpu(16), geo(), zones(geoZonesStr)),
    28  		// Uses CONFIGURE ZONE USING ... COPY FROM PARENT syntax.
    29  		MinVersion: `v19.1.0`,
    30  		Run: func(ctx context.Context, t *test, c *cluster) {
    31  			firstAZ := geoZones[0]
    32  			roachNodes := c.Range(1, nodes)
    33  			gatewayNodes := c.Range(1, nodes/3)
    34  			loadNode := c.Node(nodes + 1)
    35  
    36  			c.Put(ctx, cockroach, "./cockroach", roachNodes)
    37  			c.Put(ctx, workload, "./workload", loadNode)
    38  			c.Start(ctx, t, roachNodes)
    39  
    40  			t.Status("running workload")
    41  			m := newMonitor(ctx, c, roachNodes)
    42  			m.Go(func(ctx context.Context) error {
    43  				secondary := " --secondary-indexes=" + strconv.Itoa(secondaryIndexes)
    44  				initCmd := "./workload init indexes" + secondary + " {pgurl:1}"
    45  				c.Run(ctx, loadNode, initCmd)
    46  
    47  				// Set lease preferences so that all leases for the table are
    48  				// located in the availability zone with the load generator.
    49  				if !local {
    50  					leasePrefs := fmt.Sprintf(`ALTER TABLE indexes.indexes
    51  						                       CONFIGURE ZONE USING
    52  						                       constraints = COPY FROM PARENT,
    53  						                       lease_preferences = '[[+zone=%s]]'`, firstAZ)
    54  					c.Run(ctx, c.Node(1), `./cockroach sql --insecure -e "`+leasePrefs+`"`)
    55  				}
    56  
    57  				payload := " --payload=256"
    58  				concurrency := ifLocal("", " --concurrency="+strconv.Itoa(nodes*32))
    59  				duration := " --duration=" + ifLocal("10s", "10m")
    60  				runCmd := fmt.Sprintf("./workload run indexes --histograms="+perfArtifactsDir+"/stats.json"+
    61  					payload+concurrency+duration+" {pgurl%s}", gatewayNodes)
    62  				c.Run(ctx, loadNode, runCmd)
    63  				return nil
    64  			})
    65  			m.Wait()
    66  		},
    67  	})
    68  }
    69  
    70  func registerIndexes(r *testRegistry) {
    71  	registerNIndexes(r, 2)
    72  }
    73  
    74  func registerIndexesBench(r *testRegistry) {
    75  	for i := 0; i <= 10; i++ {
    76  		registerNIndexes(r, i)
    77  	}
    78  }