Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
98574: sql: support tenant configuration templates r=stevendanna,ecwall a=knz

Fixes #98573.
Epic: CRDB-23559
First commit from #98726.

This change introduces the LIKE clause to CREATE TENANT, which makes CREATE TENANT copy the parameters (but not the storage keyspace) from the tenant selected by LIKE.

Also if LIKE is not specified, but the (new) cluster setting `sql.create_tenant.default_template` is not empty, the value of the cluster setting is used implicitly as LIKE clause.

A proposed use of this is cluster-to-cluster replication, considering
cutover as well. On the target (sink) cluster, the operator would do:

```
CREATE TENANT application LIKE app_template
  FROM REPLICATION OF application ON ....
```

And then cutover would look something like the following if they
wanted the tenant to still be named "application"

```
ALTER TENANT application CUTOVER TO LATEST;
DROP TENANT application; -- if there's one already
ALTER TENANT application START SERVICE SHARED;
```

Release note: None

98721: go.mod: bump etcd-io/raft to 5fe1c31 r=tbg a=pavelkalinnikov

Fixes #97926
Epic: none
Release note (bug fix): fixed a rare panic in upstream etcd-io/raft when message appends race with log compaction

98747: kvserver: deflake TestReplicaProbeRequest r=pavelkalinnikov a=tbg

When we ignored an ambigous result but the probe didn't actually happen,
a later condition in the test would fail.

Retry the probe on ambiguous results instead; the test already only
expects the probe to happen "at least once", so we don't introduce
any new issues should a successful probe end up being retried.

Fixes #97136.

Epic: none
Release note: None


Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
Co-authored-by: Pavel Kalinnikov <pavel@cockroachlabs.com>
Co-authored-by: Tobias Grieger <tobias.b.grieger@gmail.com>
  • Loading branch information
4 people committed Mar 16, 2023
4 parents b6978e9 + 52f4ff9 + 6e4dd83 + 989e615 commit 7109264
Show file tree
Hide file tree
Showing 15 changed files with 523 additions and 88 deletions.
32 changes: 6 additions & 26 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1198,16 +1198,6 @@ def go_deps():
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/census-instrumentation/opencensus-proto/com_github_census_instrumentation_opencensus_proto-v0.2.1.zip",
],
)
go_repository(
name = "com_github_certifi_gocertifi",
build_file_proto_mode = "disable_global",
importpath = "github.com/certifi/gocertifi",
sha256 = "11d525844c3dd711fb0ae31acc9ebd8a4d602215f14ff24ad1764ecb48464849",
strip_prefix = "github.com/certifi/gocertifi@v0.0.0-20200922220541-2c3bb06c6054",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/certifi/gocertifi/com_github_certifi_gocertifi-v0.0.0-20200922220541-2c3bb06c6054.zip",
],
)
go_repository(
name = "com_github_cespare_xxhash",
build_file_proto_mode = "disable_global",
Expand Down Expand Up @@ -2812,16 +2802,6 @@ def go_deps():
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/getkin/kin-openapi/com_github_getkin_kin_openapi-v0.53.0.zip",
],
)
go_repository(
name = "com_github_getsentry_raven_go",
build_file_proto_mode = "disable_global",
importpath = "github.com/getsentry/raven-go",
sha256 = "eaffe69939612cd05f95e1846b8ddb4043655571be34cdb6412a66b41b6826eb",
strip_prefix = "github.com/getsentry/raven-go@v0.2.0",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/getsentry/raven-go/com_github_getsentry_raven_go-v0.2.0.zip",
],
)
go_repository(
name = "com_github_getsentry_sentry_go",
build_file_proto_mode = "disable_global",
Expand Down Expand Up @@ -8054,10 +8034,10 @@ def go_deps():
name = "com_github_stretchr_testify",
build_file_proto_mode = "disable_global",
importpath = "github.com/stretchr/testify",
sha256 = "36f64e4f229f87672ef8de1c756648c4165e76abd034362517578397e824856c",
strip_prefix = "github.com/stretchr/testify@v1.8.1",
sha256 = "400e18c88e5c4beb7ecca5d675048f1915a6e675b30fc03f8f563eb4dfde079a",
strip_prefix = "github.com/stretchr/testify@v1.8.2",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/stretchr/testify/com_github_stretchr_testify-v1.8.1.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/stretchr/testify/com_github_stretchr_testify-v1.8.2.zip",
],
)
go_repository(
Expand Down Expand Up @@ -10341,10 +10321,10 @@ def go_deps():
],
build_file_proto_mode = "default",
importpath = "go.etcd.io/raft/v3",
sha256 = "b27a4c7ddef64664745eaa5c817c80f3a7dc0d07d3b7837c02fde20993861ac7",
strip_prefix = "go.etcd.io/raft/v3@v3.0.0-20221221215055-65a0bf3b6779",
sha256 = "a20a4dc3311336d6cf64bf8a436a6bed8095748733af309435df8de3b794e36f",
strip_prefix = "go.etcd.io/raft/v3@v3.0.0-20230315220435-5fe1c31c5158",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/go.etcd.io/raft/v3/io_etcd_go_raft_v3-v3.0.0-20221221215055-65a0bf3b6779.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/go.etcd.io/raft/v3/io_etcd_go_raft_v3-v3.0.0-20230315220435-5fe1c31c5158.zip",
],
)
go_repository(
Expand Down
6 changes: 2 additions & 4 deletions build/bazelutil/distdir_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cenkalti/backoff/com_github_cenkalti_backoff-v2.2.1+incompatible.zip": "f8196815a1b4d25e5b8158029d5264801fc8aa5ff128ccf30752fd169693d43b",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cenkalti/backoff/v4/com_github_cenkalti_backoff_v4-v4.1.3.zip": "73ff572a901c0307aa1c16db43812da7ca2555aa403cfdd9d3a239ecbdad2274",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/census-instrumentation/opencensus-proto/com_github_census_instrumentation_opencensus_proto-v0.2.1.zip": "b3c09f3e635d47b4138695a547d1f2c7138f382cbe5a8b5865b66a8e08233461",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/certifi/gocertifi/com_github_certifi_gocertifi-v0.0.0-20200922220541-2c3bb06c6054.zip": "11d525844c3dd711fb0ae31acc9ebd8a4d602215f14ff24ad1764ecb48464849",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cespare/xxhash/com_github_cespare_xxhash-v1.1.0.zip": "fe98c56670b21631f7fd3305a29a3b17e86a6cce3876a2119460717a18538e2e",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cespare/xxhash/v2/com_github_cespare_xxhash_v2-v2.2.0.zip": "fc180cdb0c00fbffbd39b774a72cdb5f0c32ace25370d5135195918a8c3fbd25",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/charmbracelet/bubbles/com_github_charmbracelet_bubbles-v0.15.1-0.20230123181021-a6a12c4a31eb.zip": "72954af77ec32995cfdf218fd31e9357a0fbef96f252bb1a9e6f0b8f158d3531",
Expand Down Expand Up @@ -434,7 +433,6 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/garyburd/redigo/com_github_garyburd_redigo-v0.0.0-20150301180006-535138d7bcd7.zip": "7ed5f8194388955d2f086c170960cb096ee28d421b32bd12328d5f2a2b0ad488",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/gavv/httpexpect/com_github_gavv_httpexpect-v2.0.0+incompatible.zip": "3db05c59a5c70d11b9452727c529be6934ddf8b42f4bfdc3138441055f1529b1",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/getkin/kin-openapi/com_github_getkin_kin_openapi-v0.53.0.zip": "e3a00cb5828f8922087a0a74aad06c6177fa2eab44763a19aeec38f7fab7834b",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/getsentry/raven-go/com_github_getsentry_raven_go-v0.2.0.zip": "eaffe69939612cd05f95e1846b8ddb4043655571be34cdb6412a66b41b6826eb",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/getsentry/sentry-go/com_github_getsentry_sentry_go-v0.12.0.zip": "1d127ea620f897c64de60982882cea34a4bb9c1481a9c9a379226af7cfa454ba",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/ghemawat/stream/com_github_ghemawat_stream-v0.0.0-20171120220530-696b145b53b9.zip": "9c0a42cacc8e22024b58db15127886a6f8ddbcfbf89d4d062bfdc43dc40d80d5",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/ghodss/yaml/com_github_ghodss_yaml-v1.0.0.zip": "c3f295d23c02c0b35e4d3b29053586e737cf9642df9615da99c0bda9bbacc624",
Expand Down Expand Up @@ -928,7 +926,7 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/streadway/handy/com_github_streadway_handy-v0.0.0-20190108123426-d5acb3125c2a.zip": "f770ed96081220a9cbc5e975a06c2858b4f3d02820cb9902982116af491b171f",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/streadway/quantile/com_github_streadway_quantile-v0.0.0-20150917103942-b0c588724d25.zip": "45156bab62475784e2eacb349570c86bcf245a84d97825ce9ee2bf604a4438d5",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/stretchr/objx/com_github_stretchr_objx-v0.5.0.zip": "1a00b3bb5ad41cb72634ace06b7eb7df857404d77a7cab4e401a7c729561fe4c",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/stretchr/testify/com_github_stretchr_testify-v1.8.1.zip": "36f64e4f229f87672ef8de1c756648c4165e76abd034362517578397e824856c",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/stretchr/testify/com_github_stretchr_testify-v1.8.2.zip": "400e18c88e5c4beb7ecca5d675048f1915a6e675b30fc03f8f563eb4dfde079a",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/subosito/gotenv/com_github_subosito_gotenv-v1.2.0.zip": "21474df92536f36de6f91dfbf466995289445cc4e5a5900d9c40ae8776b8b0cf",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/syndtr/gocapability/com_github_syndtr_gocapability-v0.0.0-20200815063812-42c35b437635.zip": "91ff91da1936e17aa68fc13756e40ba4db1d7c9375a4ef0969fe19c9aa281195",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/tchap/go-patricia/com_github_tchap_go_patricia-v2.2.6+incompatible.zip": "948494017eae153a8c2d4ae9b450fd42abcb2578211f1c28e69ab71a2f27814d",
Expand Down Expand Up @@ -998,7 +996,7 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/cockroach-godeps/gomod/go.etcd.io/etcd/client/pkg/v3/io_etcd_go_etcd_client_pkg_v3-v3.5.0.zip": "c0ca209767c5734c6ed023888ba5be02aab5bd3c4d018999467f2bfa8bf65ee3",
"https://storage.googleapis.com/cockroach-godeps/gomod/go.etcd.io/etcd/client/v2/io_etcd_go_etcd_client_v2-v2.305.0.zip": "91fcb507fe8c193844b56bfb6c8741aaeb6ffa11ee9043de2af0f141173679f3",
"https://storage.googleapis.com/cockroach-godeps/gomod/go.etcd.io/etcd/io_etcd_go_etcd-v0.5.0-alpha.5.0.20200910180754-dd1b699fc489.zip": "d982ee501979b41b68625693bad77d15e4ae79ab9d0eae5f6028205f96a74e49",
"https://storage.googleapis.com/cockroach-godeps/gomod/go.etcd.io/raft/v3/io_etcd_go_raft_v3-v3.0.0-20221221215055-65a0bf3b6779.zip": "b27a4c7ddef64664745eaa5c817c80f3a7dc0d07d3b7837c02fde20993861ac7",
"https://storage.googleapis.com/cockroach-godeps/gomod/go.etcd.io/raft/v3/io_etcd_go_raft_v3-v3.0.0-20230315220435-5fe1c31c5158.zip": "a20a4dc3311336d6cf64bf8a436a6bed8095748733af309435df8de3b794e36f",
"https://storage.googleapis.com/cockroach-godeps/gomod/go.mongodb.org/mongo-driver/org_mongodb_go_mongo_driver-v1.5.1.zip": "446cff132e82c64af7ffcf48e268eb16ec81f694914aa6baecb06cbbae1be0d7",
"https://storage.googleapis.com/cockroach-godeps/gomod/go.mozilla.org/pkcs7/org_mozilla_go_pkcs7-v0.0.0-20200128120323-432b2356ecb1.zip": "3c4c1667907ff3127e371d44696326bad9e965216d4257917ae28e8b82a9e08d",
"https://storage.googleapis.com/cockroach-godeps/gomod/go.opencensus.io/io_opencensus_go-v0.24.0.zip": "203a767d7f8e7c1ebe5588220ad168d1e15b14ae70a636de7ca9a4a88a7e0d0c",
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ require (
github.com/spf13/afero v1.6.0
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.2
github.com/twpayne/go-geom v1.4.2
github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad
github.com/xdg-go/pbkdf2 v1.0.0
github.com/xdg-go/scram v1.1.2
github.com/xdg-go/stringprep v1.0.4
github.com/zabawaba99/go-gitignore v0.0.0-20200117185801-39e6bddfb292
go.etcd.io/raft/v3 v3.0.0-20221221215055-65a0bf3b6779
go.etcd.io/raft/v3 v3.0.0-20230315220435-5fe1c31c5158
go.opentelemetry.io/otel v1.0.0-RC3
go.opentelemetry.io/otel/exporters/jaeger v1.0.0-RC3
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.0.0-RC3
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2146,8 +2146,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
Expand Down Expand Up @@ -2277,8 +2278,8 @@ go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489/go.mod h1:yVHk9ub3C
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
go.etcd.io/raft/v3 v3.0.0-20221221215055-65a0bf3b6779 h1:GS8kfvdZ03yoCzHjYjZ2FV0CaNqhcnaAPjn0IHf565E=
go.etcd.io/raft/v3 v3.0.0-20221221215055-65a0bf3b6779/go.mod h1:eMshmuwXLWZrjHXN8ZgYrOMQRSbHqi5M84DEZWhG+o4=
go.etcd.io/raft/v3 v3.0.0-20230315220435-5fe1c31c5158 h1:JdVbiz8TIDFV4pyXRQ+z7dcJueHcqB4NwRGm7tnr4wo=
go.etcd.io/raft/v3 v3.0.0-20230315220435-5fe1c31c5158/go.mod h1:xa/jfCF4K9FpWEAXstT+Nw4ToWdmhJ8oeC5eburtypA=
go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
go.mongodb.org/mongo-driver v1.1.1/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
go.mongodb.org/mongo-driver v1.1.2/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
Expand Down
46 changes: 32 additions & 14 deletions pkg/ccl/streamingccl/streamingest/stream_ingestion_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func streamIngestionJobDescription(
ReplicationSourceTenantName: streamIngestion.ReplicationSourceTenantName,
ReplicationSourceAddress: tree.NewDString(redactedSourceAddr),
Options: streamIngestion.Options,
Like: streamIngestion.Like,
}
ann := p.ExtendedEvalContext().Annotations
return tree.AsStringWithFQNames(redactedCreateStmt, ann), nil
Expand All @@ -64,12 +65,20 @@ func ingestionTypeCheck(
if !ok {
return false, nil, nil
}
if err := exprutil.TypeCheck(ctx, "INGESTION", p.SemaCtx(),
toTypeCheck := []exprutil.ToTypeCheck{
exprutil.TenantSpec{TenantSpec: ingestionStmt.TenantSpec},
exprutil.TenantSpec{TenantSpec: ingestionStmt.ReplicationSourceTenantName},
exprutil.Strings{
ingestionStmt.ReplicationSourceAddress,
ingestionStmt.Options.Retention}); err != nil {
ingestionStmt.Options.Retention},
}
if ingestionStmt.Like.OtherTenant != nil {
toTypeCheck = append(toTypeCheck,
exprutil.TenantSpec{TenantSpec: ingestionStmt.Like.OtherTenant},
)
}

if err := exprutil.TypeCheck(ctx, "INGESTION", p.SemaCtx(), toTypeCheck...); err != nil {
return false, nil, err
}

Expand Down Expand Up @@ -119,6 +128,15 @@ func ingestionPlanHook(
return nil, nil, nil, false, err
}

var likeTenantID uint64
var likeTenantName string
if ingestionStmt.Like.OtherTenant != nil {
_, likeTenantID, likeTenantName, err = exprEval.TenantSpec(ctx, ingestionStmt.Like.OtherTenant)
if err != nil {
return nil, nil, nil, false, err
}
}

options, err := evalTenantReplicationOptions(ctx, ingestionStmt.Options, exprEval)
if err != nil {
return nil, nil, nil, false, err
Expand Down Expand Up @@ -164,20 +182,20 @@ func ingestionPlanHook(
sourceTenant, dstTenantName, dstTenantID)
}

// Determine which template will be used as config template to
// create the new tenant below.
tenantInfo, err := sql.GetTenantTemplate(ctx, p.ExecCfg().Settings, p.InternalSQLTxn(), nil, likeTenantID, likeTenantName)
if err != nil {
return err
}

// Create a new tenant for the replication stream.
jobID := p.ExecCfg().JobRegistry.MakeJobID()
tenantInfo := &mtinfopb.TenantInfoWithUsage{
ProtoInfo: mtinfopb.ProtoInfo{
TenantReplicationJobID: jobID,
},
SQLInfo: mtinfopb.SQLInfo{
// dstTenantID may be zero which will cause auto-allocation.
ID: dstTenantID,
DataState: mtinfopb.DataStateAdd,
ServiceMode: mtinfopb.ServiceModeNone,
Name: roachpb.TenantName(dstTenantName),
},
}
tenantInfo.TenantReplicationJobID = jobID
// dstTenantID may be zero which will cause auto-allocation.
tenantInfo.ID = dstTenantID
tenantInfo.DataState = mtinfopb.DataStateAdd
tenantInfo.Name = roachpb.TenantName(dstTenantName)

initialTenantZoneConfig, err := sql.GetHydratedZoneConfigForTenantsRange(ctx, p.Txn(), p.ExtendedEvalContext().Descs)
if err != nil {
Expand Down
30 changes: 16 additions & 14 deletions pkg/kv/kvserver/replica_probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,22 @@ func TestReplicaProbeRequest(t *testing.T) {
kvpb.RoutingPolicy_LEASEHOLDER,
kvpb.RoutingPolicy_NEAREST,
} {
var b kv.Batch
b.AddRawRequest(probeReq)
b.Header.RoutingPolicy = policy
err := db.Run(ctx, &b)
if errors.HasType(err, (*kvpb.AmbiguousResultError)(nil)) {
// Rare but it can happen that we're proposing on a replica
// that is just about to get a snapshot. In that case we'll
// get:
//
// result is ambiguous: unable to determine whether command was applied via snapshot
t.Logf("ignoring: %s", err)
err = nil
}
require.NoError(t, err)
testutils.SucceedsSoon(t, func() error {
var b kv.Batch
b.AddRawRequest(probeReq)
b.Header.RoutingPolicy = policy
err := db.Run(ctx, &b)
if errors.HasType(err, (*kvpb.AmbiguousResultError)(nil)) {
// Rare but it can happen that we're proposing on a replica
// that is just about to get a snapshot. In that case we'll
// get:
//
// result is ambiguous: unable to determine whether command was applied via snapshot
return errors.Wrapf(err, "retrying")
}
require.NoError(t, err)
return nil
})
}
}
// Check expected number of probes seen on each Replica in the apply loop.
Expand Down
19 changes: 17 additions & 2 deletions pkg/multitenant/mtinfopb/info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,23 @@ message UsageInfo {
// All-time consumption for this tenant. Each field has a corresponding column
// in system.tenant_usage.
optional roachpb.TenantConsumption consumption = 4 [(gogoproto.nullable) = false];

// Next ID: 5
}

// SettingOverride represents a cluster setting override for one tenant.
message SettingOverride {
option (gogoproto.equal) = true;

optional string name = 1 [(gogoproto.nullable) = false];
optional string value = 2 [(gogoproto.nullable) = false];
optional string value_type = 3 [(gogoproto.nullable) = false];
optional string reason = 4;
// Next ID: 5
}

// TenantInfoWithUsage contains the information for a tenant in a multi-tenant
// cluster plus metadata related to cost control and consumption.
// cluster plus metadata related to cost control and consumption and setting overrides.
message TenantInfoWithUsage {
option (gogoproto.equal) = true;

Expand All @@ -115,5 +128,7 @@ message TenantInfoWithUsage {

optional SQLInfo extra_columns = 3 [(gogoproto.embed) = true, (gogoproto.nullable) = false];

// Next ID: 4
repeated SettingOverride setting_overrides = 4;

// Next ID: 5
}
31 changes: 28 additions & 3 deletions pkg/sql/create_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,31 @@ package sql
import (
"context"

"github.com/cockroachdb/cockroach/pkg/multitenant/mtinfopb"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/errors"
)

type createTenantNode struct {
tenantSpec tenantSpec
tenantSpec tenantSpec
likeTenantSpec tenantSpec
}

func (p *planner) CreateTenantNode(ctx context.Context, n *tree.CreateTenant) (planNode, error) {
tspec, err := p.planTenantSpec(ctx, n.TenantSpec, "CREATE TENANT")
if err != nil {
return nil, err
}
var likeTenantSpec tenantSpec
if n.Like.OtherTenant != nil {
likeTenantSpec, err = p.planTenantSpec(ctx, n.Like.OtherTenant, "CREATE TENANT LIKE")
if err != nil {
return nil, err
}
}
return &createTenantNode{
tenantSpec: tspec,
tenantSpec: tspec,
likeTenantSpec: likeTenantSpec,
}, nil
}

Expand All @@ -36,6 +47,20 @@ func (n *createTenantNode) startExec(params runParams) error {
return err
}

var tmplInfo *mtinfopb.TenantInfo
if n.likeTenantSpec != nil {
tmplInfo, err = n.likeTenantSpec.getTenantInfo(params.ctx, params.p)
if err != nil {
return errors.Wrap(err, "retrieving record for LIKE configuration template")
}
}
configTemplate, err := GetTenantTemplate(params.ctx,
params.p.ExecCfg().Settings, params.p.InternalSQLTxn(),
tmplInfo, 0, "")
if err != nil {
return err
}

var ctcfg createTenantConfig
if tenantName != "" {
ctcfg.Name = (*string)(&tenantName)
Expand All @@ -44,7 +69,7 @@ func (n *createTenantNode) startExec(params runParams) error {
tenantID := tid.ToUint64()
ctcfg.ID = &tenantID
}
_, err = params.p.createTenantInternal(params.ctx, ctcfg)
_, err = params.p.createTenantInternal(params.ctx, ctcfg, configTemplate)
return err
}

Expand Down
Loading

0 comments on commit 7109264

Please sign in to comment.