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

slstorage: support regional by row system.sqlliveness #90408

Merged

Conversation

jeffswenson
Copy link
Collaborator

@jeffswenson jeffswenson commented Oct 20, 2022

The COCKROACH_MR_SYSTEM_DATABASE environment variable was introduced to
control features added as part of #85736. The variable will be removed
once migrations and version gates are implemented for the multi-region
system database optimizations.

The sqlliveness table now supports an index format compatible with
regional by row tables. Multi region serverless is the motivation for
this change. When a sql server starts up, it must write its session to
the sqlliveness table. The remote session write can add ~400ms to a
servers startup time.

$ COCKROACH_MR_SYSTEM_DATABASE=1 ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sqlliveness;
  crdb_region |            session_uuid            |           expiration
--------------+------------------------------------+---------------------------------
  \x80        | \x5895d5d121984d86bcb81d6a89d5635d | 1667511355275484444.0000000000

$ COCKROACH_MR_SYSTEM_DATABASE=0 ./cockroach-short demo
[email protected]:26257/movr> select * from system.sqlliveness;
                 session_id                |           expiration
-------------------------------------------+---------------------------------
  \x0101805fc92bdb0e8d4cb4aec3e1527a3052b8 | 1667511392212781946.0000000000

Part of #85736

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jeffswenson
Copy link
Collaborator Author

Marking this as a draft for now. I'll remove the draft label once I implement the upgrade job.

@jeffswenson jeffswenson force-pushed the jeffswenson-mr-session-id-encoding branch from 584c260 to 77929ce Compare October 20, 2022 22:11
@jeffswenson
Copy link
Collaborator Author

@ajwerner it's not clear to me how I should fix the TestSystemTableLiterals test. I chose new column ids for the session_uuid and crdb_region columns. Also the new primary key index is using index id 2. I don't see a way to get a CREATE TABLE statement to use those ids and produce a deeply equal descriptor.

Here's my best idea so far:

  1. Rewrite the test to use SHOW CREATE TABLE for the system descriptors.
  2. Assert that the hard coded sql matches the SHOW CREATE TABLE output.

Anything else I should consider?

@jeffswenson jeffswenson force-pushed the jeffswenson-mr-session-id-encoding branch 3 times, most recently from 0ed264e to 9707e5e Compare October 21, 2022 17:54
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

Nice work and nice tests. Sorry I didn't give this a look until now. I'll give it a deeper read when I find a gap later this morning. One thing we'll need to sort out after this is the story to plumb the region for the current process into this code.

Another thing to note is some of this code is shifting underneath you with #90875 and #90586.

Regarding the system table literal test. I think there's a few options. One would be to do as you suggest with SHOW CREATE TABLE. I think that's a good fine idea either way. Another thing we can do is attach some special cases to muck with things and then make sure it matches. Like just for this case, attach a closure in a map that might go in and adjust the IDs after calling CreateTestTableDescriptor.

Reviewed 7 of 7 files at r1, 5 of 5 files at r2, 4 of 19 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @jaylim-crl and @jeffswenson)


pkg/sql/sqlliveness/slstorage/table.go line 49 at r3 (raw file):

// After the version gate is flipped, servers stop dual writing. The legacy RBT
// index is eventually cleaned up by deleteExpiredSessions.
type Table struct {

do the concepts in this file need to be exported?


pkg/sql/catalog/systemschema_test/testdata/bootstrap line 283 at r3 (raw file):

	FAMILY other (schedule_name, created, owner, schedule_expr, schedule_details, executor_type, execution_args)
);
CREATE TABLE public.sqlliveness (

one thing we could do is put a unique without index constraint on the primary index. That's implicitly what an RBR table does IIRC.


pkg/sql/sqlliveness/slstorage/sessionid_test.go line 25 at r1 (raw file):

)

func FuzzSessionIDEncoding(f *testing.F) {

Cool! This is the first use of this I've seen

@jeffswenson jeffswenson force-pushed the jeffswenson-mr-session-id-encoding branch 2 times, most recently from ef2def5 to c7b5988 Compare November 3, 2022 21:27
@jeffswenson jeffswenson changed the title sqlliveness: migrate system.sqlliveness to an rbr table slstorage: support regional by row system.sqlliveness Nov 3, 2022
@jeffswenson jeffswenson force-pushed the jeffswenson-mr-session-id-encoding branch 3 times, most recently from 19e5fb0 to 68b34ba Compare November 3, 2022 21:37
Copy link
Collaborator Author

@jeffswenson jeffswenson left a comment

Choose a reason for hiding this comment

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

I've significantly changed the details of the implementation, but the end result is nearly the same. The big changes are:

  1. I removed the version gates and added the COCKROACH_MR_SYSTEM_DATABASE environment variable.
  2. I replaced Table with keyCodec. As I was refactoring to support both index formats, I decided Table wasn't really pulling it's weight as an abstraction, so I replaced it with the more minimum keyCodec API.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @jaylim-crl)


pkg/sql/catalog/systemschema_test/testdata/bootstrap line 283 at r3 (raw file):

Previously, ajwerner wrote…

one thing we could do is put a unique without index constraint on the primary index. That's implicitly what an RBR table does IIRC.

Can you elaborate? How would I define that in SQL and what is the advantage compared to the explicit primary key?


pkg/sql/sqlliveness/slstorage/table.go line 49 at r3 (raw file):

Previously, ajwerner wrote…

do the concepts in this file need to be exported?

Done

I was exporting Table so it could be used for tests. I replaced Table with keyCodec and now use slstorage.Storage in the multi region table test.

@jeffswenson jeffswenson force-pushed the jeffswenson-mr-session-id-encoding branch 2 times, most recently from 6c3888f to abe5048 Compare November 4, 2022 14:16
@jeffswenson jeffswenson requested a review from ajwerner November 4, 2022 17:40
@jeffswenson jeffswenson marked this pull request as ready for review November 4, 2022 17:40
@jeffswenson jeffswenson requested a review from a team as a code owner November 4, 2022 17:41
@jeffswenson jeffswenson requested a review from a team November 4, 2022 17:41
@jeffswenson jeffswenson force-pushed the jeffswenson-mr-session-id-encoding branch from abe5048 to 15f6438 Compare November 4, 2022 17:41
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

This is satisfyingly more simple! Just nits from me.

Reviewed 1 of 23 files at r5, 6 of 8 files at r6, 1 of 1 files at r7, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @jaylim-crl and @jeffswenson)


pkg/sql/catalog/systemschema/system.go line 2010 at r7 (raw file):

	// SqllivenessTable is the descriptor for the sqlliveness table.
	SqllivenessTable = func() catalog.TableDescriptor {
		if SupportMultiRegion() {

can you add another sentence for any wayward souls who find themselves in this file to answer what this ceremony is about and to inform them that this is not intended to be long for this world. Or just direct them to SupportsMultiRegion.

Code quote:

	SqllivenessTable = func() catalog.TableDescriptor {
		if SupportMultiRegion() {

pkg/sql/catalog/systemschema/system.go line 2689 at r7 (raw file):

// TODO(jeffswenson): remove SupportMultiRegion after implementing migrations
// and version gates to migrate to the new regional by row compatible schemas.
func SupportMultiRegion() bool {

How about calling this thing TestingSupportMultiRegion or something like that to make it double clear it's a hack


pkg/sql/catalog/systemschema/system.go line 2690 at r7 (raw file):

// and version gates to migrate to the new regional by row compatible schemas.
func SupportMultiRegion() bool {
	val, ok := envutil.EnvString("COCKROACH_MR_SYSTEM_DATABASE", 0)

Why not envutil.EnvOrDefaultBool?


pkg/sql/sqlliveness/slstorage/key_encoder.go line 30 at r7 (raw file):

	encode(sid sqlliveness.SessionID) (roachpb.Key, error)
	decode(key roachpb.Key) (sqlliveness.SessionID, error)
	prefix() roachpb.Key

use some commentary to describe the meaning of prefix and its relationship to what you pass to decode and what comes out of encode.


pkg/sql/sqlliveness/slstorage/key_encoder.go line 40 at r7 (raw file):

		return &rbrEncoder{codec.IndexPrefix(uint32(tableID), uint32(rbrIndex))}
	}
	return &rbtEncoder{codec.IndexPrefix(uint32(tableID), 1)}

nit: using consts for the index ID and the 0 family ID below will make the code feel a touch less magical.


pkg/ccl/multiregionccl/multiregion_system_table_test.go line 68 at r7 (raw file):

	defer leaktest.AfterTest(t)()
	defer log.Scope(t).Close(t)
	defer envutil.TestSetEnv(t, "COCKROACH_MR_SYSTEM_DATABASE", "1")()

This works because we aren't using the system database's table, right?

The COCKROACH_MR_SYSTEM_DATABASE environment variable was introduced to
control features added as part of cockroachdb#85736. The variable will be removed
once migrations and version gates are implemented for the multi-region
system database optimizations.

The sqlliveness table now supports an index format compatible with
regional by row tables. Multi region serverless is the motivation for
this change. When a sql server starts up, it must write its session to
the sqlliveness table. The remote session write can add ~400ms to a
servers startup time.

```
$ COCKROACH_MR_SYSTEM_DATABASE=1 ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sqlliveness;
  crdb_region |            session_uuid            |           expiration
--------------+------------------------------------+---------------------------------
  \x80        | \x5895d5d121984d86bcb81d6a89d5635d | 1667511355275484444.0000000000

$ COCKROACH_MR_SYSTEM_DATABASE=0 ./cockroach-short demo
[email protected]:26257/movr> select * from system.sqlliveness;
                 session_id                |           expiration
-------------------------------------------+---------------------------------
  \x0101805fc92bdb0e8d4cb4aec3e1527a3052b8 | 1667511392212781946.0000000000
```

Part of cockroachdb#85736

Release note: None
@jeffswenson jeffswenson force-pushed the jeffswenson-mr-session-id-encoding branch from 15f6438 to 1947dc2 Compare November 8, 2022 21:14
Copy link
Collaborator Author

@jeffswenson jeffswenson 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 @ajwerner and @jaylim-crl)


pkg/sql/catalog/systemschema/system.go line 2010 at r7 (raw file):

Previously, ajwerner wrote…

can you add another sentence for any wayward souls who find themselves in this file to answer what this ceremony is about and to inform them that this is not intended to be long for this world. Or just direct them to SupportsMultiRegion.

Done


pkg/sql/catalog/systemschema/system.go line 2689 at r7 (raw file):

Previously, ajwerner wrote…

How about calling this thing TestingSupportMultiRegion or something like that to make it double clear it's a hack

Done


pkg/sql/catalog/systemschema/system.go line 2690 at r7 (raw file):

Previously, ajwerner wrote…

Why not envutil.EnvOrDefaultBool?

Done

Thanks! I did not know about EnvOrDefaultBool.


pkg/sql/sqlliveness/slstorage/key_encoder.go line 30 at r7 (raw file):

Previously, ajwerner wrote…

use some commentary to describe the meaning of prefix and its relationship to what you pass to decode and what comes out of encode.

Done

I also renamed the method to indexPrefix


pkg/sql/sqlliveness/slstorage/key_encoder.go line 40 at r7 (raw file):

Previously, ajwerner wrote…

nit: using consts for the index ID and the 0 family ID below will make the code feel a touch less magical.

Done


pkg/ccl/multiregionccl/multiregion_system_table_test.go line 68 at r7 (raw file):

Previously, ajwerner wrote…

This works because we aren't using the system database's table, right?

Exactly. The actual system database table is determined by the value of the environment variable set at process start time.

jeffswenson added a commit to jeffswenson/cockroach that referenced this pull request Nov 17, 2022
The sql_instances table now supports an index format compatible with
regional by row tables. This is building on the work from cockroachdb#90408.

```
$ COCKROACH_MR_SYSTEM_DATABASE=true ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality              | crdb_region
-----+-----------------+------------------------------------------+-----------------------------------+--------------
   1 | 127.0.0.1:26257 | \x0101800c678f05d4114b3aa17bcd61d336308a | {"Tiers": "region=us-east1,az=b"} | \x80
   2 |                 | NULL                                     | NULL                              | \x80
(2 rows)

$ COCKROACH_MR_SYSTEM_DATABASE=false ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality
-----+-----------------+------------------------------------------+------------------------------------
   1 | 127.0.0.1:26257 | \x010180fb9227b38ca9445ba27ac8b1f5a2204d | {"Tiers": "region=us-east1,az=b"}
   2 |                 | NULL                                     | NULL
(2 rows)
```

Part of cockroachdb#85736
jeffswenson added a commit to jeffswenson/cockroach that referenced this pull request Nov 18, 2022
The sql_instances table now supports an index format compatible with
regional by row tables. This is building on the work from cockroachdb#90408.

```
$ COCKROACH_MR_SYSTEM_DATABASE=true ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality              | crdb_region
-----+-----------------+------------------------------------------+-----------------------------------+--------------
   1 | 127.0.0.1:26257 | \x0101800c678f05d4114b3aa17bcd61d336308a | {"Tiers": "region=us-east1,az=b"} | \x80
   2 | NULL            | NULL                                     | NULL                              | \x80
(2 rows)

$ COCKROACH_MR_SYSTEM_DATABASE=false ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality
-----+-----------------+------------------------------------------+------------------------------------
   1 | 127.0.0.1:26257 | \x010180fb9227b38ca9445ba27ac8b1f5a2204d | {"Tiers": "region=us-east1,az=b"}
   2 | NULL            | NULL                                     | NULL
(2 rows)
```

Part of cockroachdb#85736
jeffswenson added a commit to jeffswenson/cockroach that referenced this pull request Nov 18, 2022
The sql_instances table now supports an index format compatible with
regional by row tables. This is building on the work from cockroachdb#90408.

```
$ COCKROACH_MR_SYSTEM_DATABASE=true ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality              | crdb_region
-----+-----------------+------------------------------------------+-----------------------------------+--------------
   1 | 127.0.0.1:26257 | \x0101800c678f05d4114b3aa17bcd61d336308a | {"Tiers": "region=us-east1,az=b"} | \x80
   2 | NULL            | NULL                                     | NULL                              | \x80
(2 rows)

$ COCKROACH_MR_SYSTEM_DATABASE=false ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality
-----+-----------------+------------------------------------------+------------------------------------
   1 | 127.0.0.1:26257 | \x010180fb9227b38ca9445ba27ac8b1f5a2204d | {"Tiers": "region=us-east1,az=b"}
   2 | NULL            | NULL                                     | NULL
(2 rows)
```

Part of cockroachdb#85736
jaylim-crl added a commit to jaylim-crl/cockroach that referenced this pull request Nov 21, 2022
Follow up on cockroachdb#90408 and cockroachdb#91019.

Previously, the sqlliveness subsystem was using enum.One when constructing the
session ID since it doesn't have the regional data yet. This commit implements
that missing part of it by ensuring that the regional representation is
plumbed all the way to the sqlliveness subsystem whenever the SQL pod is
started, and use it to construct the session ID. This will enable our REGIONAL
BY ROW work to put the data in the right region.

The multi-region enum for the system database will be read during startup for
that to work. Since doing this already requires loading the system DB's
descriptor (which indirectly tests whether the system DB has been bootstrapped)
for the tenant, we can remove the call to checkTenantExists.

Epic: None

Release note: None
jaylim-crl pushed a commit to jaylim-crl/cockroach that referenced this pull request Nov 21, 2022
The sql_instances table now supports an index format compatible with
regional by row tables. This is building on the work from cockroachdb#90408.

```
$ COCKROACH_MR_SYSTEM_DATABASE=true ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality              | crdb_region
-----+-----------------+------------------------------------------+-----------------------------------+--------------
   1 | 127.0.0.1:26257 | \x0101800c678f05d4114b3aa17bcd61d336308a | {"Tiers": "region=us-east1,az=b"} | \x80
   2 | NULL            | NULL                                     | NULL                              | \x80
(2 rows)

$ COCKROACH_MR_SYSTEM_DATABASE=false ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality
-----+-----------------+------------------------------------------+------------------------------------
   1 | 127.0.0.1:26257 | \x010180fb9227b38ca9445ba27ac8b1f5a2204d | {"Tiers": "region=us-east1,az=b"}
   2 | NULL            | NULL                                     | NULL
(2 rows)
```

Part of cockroachdb#85736
jeffswenson added a commit to jeffswenson/cockroach that referenced this pull request Nov 21, 2022
The sql_instances table now supports an index format compatible with
regional by row tables. This is building on the work from cockroachdb#90408.

```
$ COCKROACH_MR_SYSTEM_DATABASE=true ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality              | crdb_region
-----+-----------------+------------------------------------------+-----------------------------------+--------------
   1 | 127.0.0.1:26257 | \x0101800c678f05d4114b3aa17bcd61d336308a | {"Tiers": "region=us-east1,az=b"} | \x80
   2 | NULL            | NULL                                     | NULL                              | \x80
(2 rows)

$ COCKROACH_MR_SYSTEM_DATABASE=false ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality
-----+-----------------+------------------------------------------+------------------------------------
   1 | 127.0.0.1:26257 | \x010180fb9227b38ca9445ba27ac8b1f5a2204d | {"Tiers": "region=us-east1,az=b"}
   2 | NULL            | NULL                                     | NULL
(2 rows)
```

Part of cockroachdb#85736
jeffswenson added a commit to jeffswenson/cockroach that referenced this pull request Nov 21, 2022
The sql_instances table now supports an index format compatible with
regional by row tables. This is building on the work from cockroachdb#90408.

```
$ COCKROACH_MR_SYSTEM_DATABASE=true ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality              | crdb_region
-----+-----------------+------------------------------------------+-----------------------------------+--------------
   1 | 127.0.0.1:26257 | \x0101800c678f05d4114b3aa17bcd61d336308a | {"Tiers": "region=us-east1,az=b"} | \x80
   2 | NULL            | NULL                                     | NULL                              | \x80
(2 rows)

$ COCKROACH_MR_SYSTEM_DATABASE=false ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality
-----+-----------------+------------------------------------------+------------------------------------
   1 | 127.0.0.1:26257 | \x010180fb9227b38ca9445ba27ac8b1f5a2204d | {"Tiers": "region=us-east1,az=b"}
   2 | NULL            | NULL                                     | NULL
(2 rows)
```

Part of cockroachdb#85736
craig bot pushed a commit that referenced this pull request Nov 21, 2022
91604: tenant: add support to Log endpoints to status server r=abarganier,knz a=dhartunian

Previously, the tenant status server did not support the log-file related
endpoints leading to missing logs in the debug.zip when generating for a tenant
server.

This commit migrates the implementations from the standard status server into
the tenant, adjusts for fanout to instances instead of nodes, and leaves the
rest as-is.

Resolves: #91992
Epic: CC-5168

Release note (ops change): generating a debug.zip for a tenant server will now
include logs in the zip file.

92010: systemschema: support rbr system.sql_instances r=JeffSwenson a=JeffSwenson

## instancestorage: clean up codec interface
Refactor the codec interface. The new codec interface will be used to
support the legacy index format and the RBR compatible index format.

Part of #85736

## systemschema: support rbr system.sql_instances
The sql_instances table now supports an index format compatible with
regional by row tables. This is building on the work from #90408.

```
$ COCKROACH_MR_SYSTEM_DATABASE=true ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality              | crdb_region
-----+-----------------+------------------------------------------+-----------------------------------+--------------
   1 | 127.0.0.1:26257 | \x0101800c678f05d4114b3aa17bcd61d336308a | {"Tiers": "region=us-east1,az=b"} | \x80
   2 |                 | NULL                                     | NULL                              | \x80
(2 rows)

$ COCKROACH_MR_SYSTEM_DATABASE=false ./cockroach-short demo
[email protected]:26257/movr> SELECT * FROM system.sql_instances LIMIT 2;
  id |      addr       |                session_id                |             locality
-----+-----------------+------------------------------------------+------------------------------------
   1 | 127.0.0.1:26257 | \x010180fb9227b38ca9445ba27ac8b1f5a2204d | {"Tiers": "region=us-east1,az=b"}
   2 |                 | NULL                                     | NULL
(2 rows)
```

Part of #85736

92280: dev-inf: Add T-multitenant label to multi-tenant r=knz a=ajstorm

Added the t-multitenant lable to the multi-tenant section of TEAMS.yaml

Release note: None

Epic: None

Co-authored-by: David Hartunian <[email protected]>
Co-authored-by: Jeff <[email protected]>
Co-authored-by: Adam Storm <[email protected]>
jaylim-crl added a commit to jaylim-crl/cockroach that referenced this pull request Nov 22, 2022
Follow up on cockroachdb#90408 and cockroachdb#91019.

Previously, the sqlliveness subsystem was using enum.One when constructing the
session ID since it doesn't have the regional data yet. This commit implements
that missing part of it by ensuring that the regional representation is
plumbed all the way to the sqlliveness subsystem whenever the SQL pod is
started, and use it to construct the session ID. This will enable our REGIONAL
BY ROW work to put the data in the right region.

The multi-region enum for the system database will be read during startup for
that to work. Since doing this already requires loading the system DB's
descriptor (which indirectly tests whether the system DB has been bootstrapped)
for the tenant, we can remove the call to checkTenantExists.

Epic: None

Release note: None
jaylim-crl added a commit to jaylim-crl/cockroach that referenced this pull request Nov 23, 2022
Follow up on cockroachdb#90408 and cockroachdb#91019.

Previously, the sqlliveness subsystem was using enum.One when constructing the
session ID since it doesn't have the regional data yet. This commit implements
that missing part of it by ensuring that the regional representation is
plumbed all the way to the sqlliveness subsystem whenever the SQL pod is
started, and use it to construct the session ID. This will enable our REGIONAL
BY ROW work to put the data in the right region.

The multi-region enum for the system database will be read during startup for
that to work. Since doing this already requires loading the system DB's
descriptor (which indirectly tests whether the system DB has been bootstrapped)
for the tenant, we can remove the call to checkTenantExists.

Epic: None

Release note: None
craig bot pushed a commit that referenced this pull request Nov 23, 2022
91694: sqlliveness: embed current region into session ID r=JeffSwenson,ajwerner a=jaylim-crl

Follow up on #90408 and #91019.

Previously, the sqlliveness subsystem was using enum.One when constructing the
session ID since it doesn't have the regional data yet. This commit implements
that missing part of it by ensuring that the regional representation is
plumbed all the way to the sqlliveness subsystem whenever the SQL pod is
started, and use it to construct the session ID. This will enable our REGIONAL
BY ROW work to put the data in the right region.

The multi-region enum for the system database will be read during startup for
that to work. Since doing this already requires loading the system DB's
descriptor (which indirectly tests whether the system DB has been bootstrapped)
for the tenant, we can remove the call to checkTenantExists.

Epic: None

Release note: None

92320: sql: remove Txn() from JobExecContext r=adityamaru a=stevendanna

This removes Txn() from JobExecContext. This method would always
return a nil txn, making it a bit error prone to actually use in
jobs.

Epic: None

Release note: None

Co-authored-by: Jay <[email protected]>
Co-authored-by: Steven Danna <[email protected]>
jeffswenson added a commit to jeffswenson/cockroach that referenced this pull request Dec 5, 2022
crdb_internal.unsafe_optimize_system_database optimizes the system
database for multi region deployments by configuring latency critical
tables as global or regional by row. Tables that are sensitive to read
latency were converted to global. Table that are sensitive to write
latency were converted to regional by row.

system.sqlliveness and system.sql_instances were reworked by (cockroachdb#90408)
and (cockroachdb#92010) to have a primary key index that is binary compatible with
regional by row tables. The conversion to regional by row is
implemented as a built in function because it is not possible to use
`ALTER TABLE ... SET LOCALITY REGIONAL BY ROW` to perform the conversion.
Using alter table to convert the RBR tables has two challenges:
1. There is no way to convert the crdb_region column from []byte to the
   region enum type.
2. Changing the locality to RBR always rewrites the primary index. The
   sqlliveness and sql_instance subsystems use the raw kv API and expect a
   specific index ID. Rewriting the primary index changes the ID and breaks
   the subsystems.

Release note: None

Part of cockroachdb#85736
jeffswenson added a commit to jeffswenson/cockroach that referenced this pull request Dec 6, 2022
crdb_internal.unsafe_optimize_system_database optimizes the system
database for multi region deployments by configuring latency critical
tables as global or regional by row. Tables that are sensitive to read
latency were converted to global. Table that are sensitive to write
latency were converted to regional by row.

system.sqlliveness and system.sql_instances were reworked by (cockroachdb#90408)
and (cockroachdb#92010) to have a primary key index that is binary compatible with
regional by row tables. The conversion to regional by row is
implemented as a built in function because it is not possible to use
`ALTER TABLE ... SET LOCALITY REGIONAL BY ROW` to perform the conversion.
Using alter table to convert the RBR tables has two challenges:
1. There is no way to convert the crdb_region column from []byte to the
   region enum type.
2. Changing the locality to RBR always rewrites the primary index. The
   sqlliveness and sql_instance subsystems use the raw kv API and expect a
   specific index ID. Rewriting the primary index changes the ID and breaks
   the subsystems.

Release note: None

Part of cockroachdb#85736
jeffswenson added a commit to jeffswenson/cockroach that referenced this pull request Dec 6, 2022
crdb_internal.unsafe_optimize_system_database optimizes the system
database for multi region deployments by configuring latency critical
tables as global or regional by row. Tables that are sensitive to read
latency were converted to global. Table that are sensitive to write
latency were converted to regional by row.

system.sqlliveness and system.sql_instances were reworked by (cockroachdb#90408)
and (cockroachdb#92010) to have a primary key index that is binary compatible with
regional by row tables. The conversion to regional by row is
implemented as a built in function because it is not possible to use
`ALTER TABLE ... SET LOCALITY REGIONAL BY ROW` to perform the conversion.
Using alter table to convert the RBR tables has two challenges:
1. There is no way to convert the crdb_region column from []byte to the
   region enum type.
2. Changing the locality to RBR always rewrites the primary index. The
   sqlliveness and sql_instance subsystems use the raw kv API and expect a
   specific index ID. Rewriting the primary index changes the ID and breaks
   the subsystems.

Release note: None

Part of cockroachdb#85736
craig bot pushed a commit that referenced this pull request Dec 6, 2022
92395: multiregionccl: add unsafe_optimize_system_database r=JeffSwenson a=JeffSwenson

crdb_internal.unsafe_optimize_system_database optimizes the system
database for multi region deployments by configuring latency critical
tables as global or regional by row. Tables that are sensitive to read
latency were converted to global. Table that are sensitive to write
latency were converted to regional by row.

system.sqlliveness and system.sql_instances were reworked by (#90408)
and (#92010) to have a primary key index that is binary compatible with
regional by row tables. The conversion to regional by row is
implemented as a built in function because it is not possible to use 
`ALTER TABLE ... SET LOCALITY REGIONAL BY ROW` to perform the conversion.
Using alter table to convert the RBR tables has two challenges:
1. There is no way to convert the crdb_region column from []byte to the
   region enum type.
2. Changing the locality to RBR always rewrites the primary index. The
   sqlliveness and sql_instance subsystems use the raw kv API and expect a
   specific index ID. Rewriting the primary index changes the ID and breaks
   the subsystems.

Release note: None

Part of #85736

Co-authored-by: Jeff <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants