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

server: add ./cockroach mt start-sql #49908

Merged
merged 1 commit into from
Jun 10, 2020
Merged

server: add ./cockroach mt start-sql #49908

merged 1 commit into from
Jun 10, 2020

Conversation

tbg
Copy link
Member

@tbg tbg commented Jun 5, 2020

This adds a CLI command to start a SQL tenant in a standalone process.

The tenant currently communicates with the KV layer "as a node"; this
will only change with #47898. As is, the tenant has full access to the
KV layer and so a few things may work that shouldn't as a result of
that.

Additionally, the tenant runs a Gossip client as a temporary stopgap
until we have removed the remaining dependencies on it (#49693 has
the details on what those are).

Apart from that, though, this is the real thing and can be used to
start setting up end-to-end testing of ORMs as well as the deploy-
ments.

A word on the choice of the mt command: mt is an abbreviation for
multi-tenant which was considered too long; just tenant was
considered misleading - there will be multiple additional subcommands
housing the other services required for running the whole infrastructure
including certs generation, the KV auth broker server, and the SQL
proxy. Should a lively bikeshed around naming break out we can rename
the commands later when consensus has been reached.

For those curious to try it out the following will be handy:

rm -rf ~/.cockroach-certs cockroach-data &&
killall -9 cockroach && \
export COCKROACH_CA_KEY=$HOME/.cockroach-certs/ca.key && \
./cockroach cert create-ca && \
./cockroach cert create-client root && \
./cockroach cert create-node 127.0.0.1 && \
./cockroach start --host 127.0.0.1 --background && \
./cockroach sql --host 127.0.0.1 -e 'select crdb_internal.create_tenant(123);'
./cockroach mt start-sql --tenant-id 123 --kv-addrs 127.0.0.1:26257 --sql-addr :5432 &
sleep 1 && \
./cockroach sql --host 127.0.0.1 --port 5432

This roughly matches what the newly introduced acceptance/multitenant
roachtest does as well.

cc @nvanbenschoten @asubiotto

Release note: None

@tbg tbg added the A-multitenancy Related to multi-tenancy label Jun 5, 2020
@tbg tbg requested a review from knz June 5, 2020 09:21
@tbg tbg requested a review from a team as a code owner June 5, 2020 09:21
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 8 of 8 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @tbg)


pkg/cli/flags.go, line 726 at r1 (raw file):

		// NB: serverInsecure populates baseCfg.{Insecure,SSLCertsDir} in this the following method
		// (which is a PreRun for this command):
		_ = extraServerFlagInit

I think that's missing ...() at the end


pkg/cli/flags.go, line 732 at r1 (raw file):

		VarFlag(f, addrSetter{&serverSQLAddr, &serverSQLPort}, cliflags.ListenSQLAddr)

		StringSlice(f, &serverCfg.SQLConfig.TenantKVAddrs, cliflags.KVAddrs, []string{"127.0.0.1:26257"})

the default value should be assigned to TenantKVAddrs in context.go


pkg/cmd/roachtest/multitenant.go, line 41 at r1 (raw file):

			"--tenant-id", "123",
			"--kv-addrs", strings.Join(kvAddrs, ","),
			"--sql-addr", "0.0.0.0:36257",

I don't understand "0.0.0.0" here - why do you need to listen on all interfaces?

@tbg tbg force-pushed the sqlcli branch 2 times, most recently from 0b4e6dc to 98134e5 Compare June 5, 2020 16:20
@tbg tbg requested a review from knz June 5, 2020 17:43
Copy link
Member Author

@tbg tbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)


pkg/cli/flags.go, line 726 at r1 (raw file):

Previously, knz (kena) wrote…

I think that's missing ...() at the end

No, I didn't want to call it - this is just an anchor to make it easier to navigate to the method (and it prevents rot should the method get renamed).


pkg/cli/flags.go, line 732 at r1 (raw file):

Previously, knz (kena) wrote…

the default value should be assigned to TenantKVAddrs in context.go

Done.


pkg/cmd/roachtest/multitenant.go, line 41 at r1 (raw file):

Previously, knz (kena) wrote…

I don't understand "0.0.0.0" here - why do you need to listen on all interfaces?

I don't, but I want to make sure I listen on the external one in case this is running in roachtest. What do you want to see here? I can make it 127.0.0.1 if local if that's the concern. (Done).

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend ensuring that the output of cockroach mt help and the --help outputs for the sub-commands highlight that the feature is experimental (our code word for "we don't support this externally")

LGTM otherwise

Reviewed 4 of 4 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained


pkg/cmd/roachtest/multitenant.go, line 41 at r1 (raw file):

Previously, tbg (Tobias Grieger) wrote…

I don't, but I want to make sure I listen on the external one in case this is running in roachtest. What do you want to see here? I can make it 127.0.0.1 if local if that's the concern. (Done).

Ok I simply did not understand.
In that case, I'd suggest simplifying to "--sql-addr", ":36257" without an address prefix, in which case it should default to all-interfaces already.

@tbg tbg requested a review from knz June 5, 2020 20:31
Copy link
Member Author

@tbg tbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend ensuring that the output of cockroach mt help and the --help outputs for the sub-commands highlight that the feature is experimental (our code word for "we don't support this externally")

Done (the mt command is also hidden).

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)


pkg/cmd/roachtest/multitenant.go, line 41 at r1 (raw file):

Previously, knz (kena) wrote…

Ok I simply did not understand.
In that case, I'd suggest simplifying to "--sql-addr", ":36257" without an address prefix, in which case it should default to all-interfaces already.

Are you opposed to the current code? I think it's kind of nice to not listen everywhere on --local runs.

@knz
Copy link
Contributor

knz commented Jun 5, 2020

Are you opposed to the current code? I think it's kind of nice to not listen everywhere on --local runs.

No objection.

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing major in the review. This is exciting to see!

Reviewed 3 of 8 files at r1, 4 of 4 files at r2, 2 of 2 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @tbg)


pkg/cli/cli_mt.go, line 1 at r3 (raw file):

// Copyright 2020 The Cockroach Authors.

nit: why prefix the filename with cli_? We don't seem to do that anywhere else.


pkg/cli/cli_mt.go, line 16 at r3 (raw file):

func init() {
	cockroachCmd.AddCommand(mtCmd)

I'm assuming you deliberately did not place this in the list of all other commands in cli.go?


pkg/cli/flags.go, line 741 at r3 (raw file):

		return errors.Wrap(err, "invalid tenant ID")
	}
	*w.tenID = roachpb.MakeTenantID(tenID)

This is going to blow up with a tenID of 0. Are you ok with that?


pkg/cli/cliflags/flags_mt.go, line 23 at r3 (raw file):

	KVAddrs = FlagInfo{
		Name:        "kv-addrs",
		Shorthand:   "",

nit: why specify this?


pkg/cmd/roachtest/acceptance.go, line 45 at r3 (raw file):

		{name: "gossip/restart-node-one", fn: runGossipRestartNodeOne},
		{name: "gossip/locality-address", fn: runCheckLocalityIPAddress},
		{name: "multitenant", fn: runAcceptanceMultitenant},

We need a minVersion here, right?


pkg/server/testserver.go, line 629 at r3 (raw file):

}

// StartTenant starts a stand-alone SQL server against a dedicated KV backend.

What does "dedicated" mean here? The KV backend can and is still running its own SQL server, right?

This adds a CLI command to start a SQL tenant in a standalone process.

The tenant currently communicates with the KV layer "as a node"; this
will only change with cockroachdb#47898. As is, the tenant has full access to the
KV layer and so a few things may work that shouldn't as a result of
that.

Additionally, the tenant runs a Gossip client as a temporary stopgap
until we have removed the remaining dependencies on it (cockroachdb#49693 has
the details on what those are).

Apart from that, though, this is the real thing and can be used to
start setting up end-to-end testing of ORMs as well as the deploy-
ments.

A word on the choice of the `mt` command: `mt` is an abbreviation for
`multi-tenant` which was considered too long; just `tenant` was
considered misleading - there will be multiple additional subcommands
housing the other services required for running the whole infrastructure
including certs generation, the KV auth broker server, and the SQL
proxy. Should a lively bikeshed around naming break out we can rename
the commands later when consensus has been reached.

For those curious to try it out the following will be handy:

```bash
rm -rf ~/.cockroach-certs cockroach-data &&
killall -9 cockroach && \
export COCKROACH_CA_KEY=$HOME/.cockroach-certs/ca.key && \
./cockroach cert create-ca && \
./cockroach cert create-client root && \
./cockroach cert create-node 127.0.0.1 && \
./cockroach start --host 127.0.0.1 --background && \
./cockroach sql --host 127.0.0.1 -e 'select crdb_internal.create_tenant(123);'
./cockroach mt start-sql --tenant-id 123 --kv-addrs 127.0.0.1:26257 --sql-addr :5432 &
sleep 1 && \
./cockroach sql --host 127.0.0.1 --port 5432
```

This roughly matches what the newly introduced `acceptance/multitenant`
roachtest does as well.

Release note: None
Copy link
Member Author

@tbg tbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

TFTR! Addressed all of the comments.

bors r=knz,nvanbenschoten

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @knz and @nvanbenschoten)


pkg/cli/flags.go, line 741 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

This is going to blow up with a tenID of 0. Are you ok with that?

I'm basically OK with it but I added a check to make things look nice.


pkg/cli/cli_mt.go, line 16 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

I'm assuming you deliberately did not place this in the list of all other commands in cli.go?

Correct.

@craig
Copy link
Contributor

craig bot commented Jun 10, 2020

Build succeeded

@craig craig bot merged commit 8bbec62 into cockroachdb:master Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-multitenancy Related to multi-tenancy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants