Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-21.1: cli/demo: assorted backports #63535

4 changes: 2 additions & 2 deletions pkg/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func Example_demo() {

testData := [][]string{
{`demo`, `-e`, `show database`},
{`demo`, `-e`, `show database`, `--empty`},
{`demo`, `-e`, `show database`, `--no-example-database`},
{`demo`, `-e`, `show application_name`},
{`demo`, `--format=table`, `-e`, `show database`},
{`demo`, `-e`, `select 1 as "1"`, `-e`, `select 3 as "3"`},
Expand Down Expand Up @@ -448,7 +448,7 @@ func Example_demo() {
// demo -e show database
// database
// movr
// demo -e show database --empty
// demo -e show database --no-example-database
// database
// defaultdb
// demo -e show application_name
Expand Down
12 changes: 9 additions & 3 deletions pkg/cli/cliflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,10 +1186,16 @@ If set, disable cockroach demo from attempting to obtain a temporary license.`,
}

UseEmptyDatabase = FlagInfo{
Name: "empty",
Name: "empty",
Description: `Deprecated in favor of --no-example-database`,
}

NoExampleDatabase = FlagInfo{
Name: "no-example-database",
EnvVar: "COCKROACH_NO_EXAMPLE_DATABASE",
Description: `
Start with an empty database: avoid pre-loading a default dataset in
the demo shell.`,
Disable the creation of a default dataset in the demo shell.
This makes 'cockroach demo' faster to start.`,
}

GeoLibsDir = FlagInfo{
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ var demoCtx struct {
cacheSize int64
disableTelemetry bool
disableLicenseAcquisition bool
useEmptyDatabase bool
noExampleDatabase bool
runWorkload bool
localities demoLocalityList
geoPartitionedReplicas bool
Expand All @@ -585,7 +585,7 @@ func setDemoContextDefaults() {
demoCtx.nodes = 1
demoCtx.sqlPoolMemorySize = 128 << 20 // 128MB, chosen to fit 9 nodes on 2GB machine.
demoCtx.cacheSize = 64 << 20 // 64MB, chosen to fit 9 nodes on 2GB machine.
demoCtx.useEmptyDatabase = false
demoCtx.noExampleDatabase = false
demoCtx.simulateLatency = false
demoCtx.runWorkload = false
demoCtx.localities = nil
Expand Down
46 changes: 31 additions & 15 deletions pkg/cli/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Start an in-memory, standalone, single-node CockroachDB instance, and open an
interactive SQL prompt to it. Various datasets are available to be preloaded as
subcommands: e.g. "cockroach demo startrek". See --help for a full list.

By default, the 'movr' dataset is pre-loaded. You can also use --empty
By default, the 'movr' dataset is pre-loaded. You can also use --no-example-database
to avoid pre-loading a dataset.

cockroach demo attempts to connect to a Cockroach Labs server to obtain a
Expand Down Expand Up @@ -105,14 +105,23 @@ func insertPair(pair regionPair, latency int) {
regionToLatency[pair.regionB] = latency
}

// Round-trip latencies collected from http://cloudping.co on 2019-09-11.
var regionRoundTripLatencies = map[regionPair]int{
{regionA: "us-east1", regionB: "us-west1"}: 66,
{regionA: "us-east1", regionB: "europe-west1"}: 64,
{regionA: "us-west1", regionB: "europe-west1"}: 146,
}

var regionOneWayLatencies = make(map[regionPair]int)

func init() {
// We record one-way latencies next, because the logic in our delayingConn
// and delayingListener is in terms of one-way network delays.
for pair, latency := range regionRoundTripLatencies {
regionOneWayLatencies[pair] = latency / 2
}
regionToRegionToLatency = make(map[string]map[string]int)
// Latencies collected from http://cloudping.co on 2019-09-11.
for pair, latency := range map[regionPair]int{
{regionA: "us-east1", regionB: "us-west1"}: 66,
{regionA: "us-east1", regionB: "europe-west1"}: 64,
{regionA: "us-west1", regionB: "europe-west1"}: 146,
} {
for pair, latency := range regionOneWayLatencies {
insertPair(pair, latency)
insertPair(regionPair{
regionA: pair.regionB,
Expand Down Expand Up @@ -175,14 +184,14 @@ func incrementTelemetryCounters(cmd *cobra.Command) {
func checkDemoConfiguration(
cmd *cobra.Command, gen workload.Generator,
) (workload.Generator, error) {
if gen == nil && !demoCtx.useEmptyDatabase {
// Use a default dataset unless prevented by --empty.
if gen == nil && !demoCtx.noExampleDatabase {
// Use a default dataset unless prevented by --no-example-database.
gen = defaultGenerator
}

// Make sure that the user didn't request a workload and an empty database.
if demoCtx.runWorkload && demoCtx.useEmptyDatabase {
return nil, errors.New("cannot run a workload against an empty database")
if demoCtx.runWorkload && demoCtx.noExampleDatabase {
return nil, errors.New("cannot run a workload when generation of the example database is disabled")
}

// Make sure the number of nodes is valid.
Expand All @@ -208,9 +217,9 @@ func checkDemoConfiguration(
return nil, errors.Newf("enterprise features are needed for this demo (%s)", geoFlag)
}

// Make sure that the user didn't request to have a topology and an empty database.
if demoCtx.useEmptyDatabase {
return nil, errors.New("cannot setup geo-partitioned replicas topology on an empty database")
// Make sure that the user didn't request to have a topology and disable the example database.
if demoCtx.noExampleDatabase {
return nil, errors.New("cannot setup geo-partitioned replicas topology without generating an example database")
}

// Make sure that the Movr database is selected when automatically partitioning.
Expand Down Expand Up @@ -284,12 +293,19 @@ func runDemo(cmd *cobra.Command, gen workload.Generator) (err error) {
checkInteractive(cmdIn)

if cliCtx.isInteractive {
fmt.Printf(`#
printfUnlessEmbedded(`#
# Welcome to the CockroachDB demo database!
#
# You are connected to a temporary, in-memory CockroachDB cluster of %d node%s.
`, demoCtx.nodes, util.Pluralize(int64(demoCtx.nodes)))

if demoCtx.simulateLatency {
printfUnlessEmbedded(
"#\n# WARNING: the use of --%s is experimental. Some features may not work as expected.\n",
cliflags.Global.Name,
)
}

// Only print details about the telemetry configuration if the
// user has control over it.
if demoCtx.disableTelemetry {
Expand Down
Loading