Skip to content

Commit

Permalink
cli: support --locality and --max-offset flags with sql tenant pods
Browse files Browse the repository at this point in the history
This commit adds support for the `--locality` and `--max-offset` flags to the
`cockroach mt start-sql` command.

The first of these is important because tenant SQL pods should know where they
reside. This will be important in the future for multi-region serverless and
also for projects like cockroachdb#72593.

The second of these is important because the SQL pod's max-offset setting needs
to be the same as the host cluster's. If we want to be able to configure the
host cluster's maximum clock offset to some non-default value, we'll need SQL
pods to be configured identically.

Validation of plumbing:
```sh
./cockroach start-single-node --insecure --max-offset=250ms
./cockroach sql --insecure -e 'select crdb_internal.create_tenant(2)'

 # verify --max-offset

./cockroach mt start-sql --insecure --tenant-id=2 --sql-addr=:26258 --http-addr=:0
 # CRDB crashes with error "locally configured maximum clock offset (250ms) does not match that of node [::]:62744 (500ms)"

./cockroach mt start-sql --insecure --tenant-id=2 --sql-addr=:26258 --http-addr=:0 --max-offset=250ms
 # successful

 # verify --locality

./cockroach sql --insecure --port=26258 -e 'select gateway_region()'

ERROR: gateway_region(): no region set on the locality flag on this node

./cockroach mt start-sql --insecure --tenant-id=2 --sql-addr=:26258 --http-addr=:0 --max-offset=250ms --locality=region=us-east1

./cockroach sql --insecure --port=26258 -e 'select gateway_region()'

  gateway_region
------------------
  us-east1
```
  • Loading branch information
nvanbenschoten authored and GustasValdavicius committed Jan 4, 2022
1 parent 0077ae9 commit d32ddb7
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,8 @@ func init() {
varFlag(f, addrSetter{&serverHTTPAddr, &serverHTTPPort}, cliflags.ListenHTTPAddr)
varFlag(f, addrSetter{&serverAdvertiseAddr, &serverAdvertisePort}, cliflags.AdvertiseAddr)

varFlag(f, &serverCfg.Locality, cliflags.Locality)
varFlag(f, &serverCfg.MaxOffset, cliflags.MaxOffset)
varFlag(f, &storeSpecs, cliflags.Store)
stringFlag(f, &startCtx.pidFile, cliflags.PIDFile)
stringFlag(f, &startCtx.geoLibsDir, cliflags.GeoLibsDir)
Expand Down

0 comments on commit d32ddb7

Please sign in to comment.