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

pgwire: split more code into pre-serve and serve logic #92576

Merged
merged 10 commits into from
Jan 9, 2023

Conversation

@knz knz self-assigned this Nov 28, 2022
@cockroach-teamcity
Copy link
Member

cockroach-teamcity commented Nov 28, 2022

This change is Reviewable

@knz knz changed the title pgwire: lift readVersion + TLS handshake into the pre-serve handler pgwire: simple code movement - no functionality change Nov 28, 2022
@knz knz added the A-multitenancy Related to multi-tenancy label Nov 28, 2022
@knz knz marked this pull request as ready for review November 28, 2022 15:42
@knz knz requested a review from a team November 28, 2022 15:42
@knz knz requested a review from a team as a code owner November 28, 2022 15:42
@knz knz changed the title pgwire: simple code movement - no functionality change pgwire: split more code into pre-serve and serve logic Nov 28, 2022
@knz knz requested a review from rafiss November 28, 2022 16:57
@knz knz requested a review from a team November 29, 2022 14:58
@dhartunian dhartunian removed the request for review from a team November 29, 2022 16:48
Copy link
Collaborator

@rafiss rafiss 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/sql/pgwire/server.go line 987 at r3 (raw file):

	// Replace RemoteAddr if specified by client and we trust the client.
	if cp.clientProvidedRemoteAddr != "" {
		if !trustClientProvidedRemoteAddr {

since this trustClientProvidedRemoteAddr comes from an env var, i don't see why the client-provided address logic is tenant-specfic


pkg/sql/pgwire/server.go line 258 at r4 (raw file):

	// tenantConnMonitor is the pool where the memory usage for the
	// initial connection overhead is accounted for.
	tenantConnMonitor *mon.BytesMonitor

should this be called tenantSpecificConnMonitor? it seems like that tenantSpecificXYZ convention was used elsewhere

@knz knz force-pushed the 20221116-shared-sql-3 branch 2 times, most recently from 0402377 to 57e2215 Compare December 5, 2022 20:24
Copy link
Contributor Author

@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.

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


pkg/sql/pgwire/server.go line 987 at r3 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

since this trustClientProvidedRemoteAddr comes from an env var, i don't see why the client-provided address logic is tenant-specfic

You are very right. I'm moving it there in #92579.


pkg/sql/pgwire/server.go line 258 at r4 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

should this be called tenantSpecificConnMonitor? it seems like that tenantSpecificXYZ convention was used elsewhere

Done.

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 5 files at r5, 4 of 4 files at r8, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)

@knz knz requested a review from a team as a January 8, 2023 19:42
@knz knz requested review from a team, herkolategan and srosenberg and removed request for a team January 8, 2023 19:51
Prior to this patch, we were unconditionally applying a port offset
for secondary tenant servers, even when the port allocation for the KV
node was randomized. This resulted in the demo cluster trying to
reuse arbitrary TCP ports which may be already in use elsewhere in the
system.

This patch fixes it by ensuring that tenant servers also use random
allocation when the KV node ports were randomly allocated in the first
place.

It also adds demo networking tests that verify this via the
`--sql-port` / `--http-port` flags.

Release note: None
Some of the tests were not waiting for the prompt to start sending
their input. This was causing the input to be lost in some cases.

Release note: None
This commit introduces `PreServeConnHandler`, which will
handle the preparation of a SQL connection prior to handing it off to
a specific tenant server.

Release note (ops changes): The count of network bytes sent
to report re-authentication errors to a SQL client is now
reported via the metric `sql.pre_serve.bytesout` (instead of
`sql.bytesout` previously). The count of pre-authentication errors
is now reported via the metric `sql.pre_serve.conn.failures` (instead
of `sql.conn.failures` previously).

Release note (ops changes): The count of new SQL connections
is now also reported on `sql.pre_serve.new_conns`.
Release note (ops change): The bytes read from SQL clients
prior to authentication are now reported via the metric
`sql.pre_serve.bytesin` (instead of `sql.bytesin` previously).
We need the read/parse of the parameters to be tenant-independent,
so the function cannot contain tenant-specific configuration.

Release note: None
This commit extracts the memory reservation into
a tenant-independent memory pool.

Release note: None
@knz knz changed the base branch from 20221116-shared-sql-base to master January 8, 2023 22:18
craig bot pushed a commit that referenced this pull request Jan 9, 2023
92580: server,pgwire: use a single SQL listener for multiple tenants r=rafiss a=knz

Parent PRs:
- [x] #84608
- [x] #91739
- [x] #91744
- [x] #92574
- [x] #92575
- [x] #92576
- [x] #92577
- [x] #92578
- [x] #92579
- [ ] #94901

Fixes #84585.
Informs  #94310.
Epic: CRDB-14537

This commit implements tenant routing using a single SQL network listener.

The tenant name can be specified:

- via the client status param `options`, e.g. `options=-ccrdb:tenant=hello`
- via the database name, e.g. `crdb:tenant-hello.defaultdb`.

Release note (backward-incompatible change): If a SQL database is created with a name that starts with `crdb:tenant-` (e.g. `CREATE DATABASE "crdb:tenant-foo"`, clients will no longer be able to connect to it directly.

Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
@craig craig bot merged commit c7dd014 into master Jan 9, 2023
@craig craig bot deleted the 20221116-shared-sql-3 branch January 9, 2023 01:50
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.

3 participants