-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spanconfigsqltranslator: populate protected_timestamps in SpanConfig
This change teaches the SQLTranslator to hydrate the SpanConfigs for a table with protected timestamps that apply to that table. Concretely, this change initializes a `spanconfig.ProtectedTimestampTableReader` in the txn in which the translation is taking place, thereby providing a transactional view of the `system.protected_ts_records` table. After generating the span configurations based on the zone configurations that apply to the table, we hydrate the newly introduced `protected_timestamps` field on each span configuration with all the protected timestamps that apply to this table. This includes protected timestamp records that directly target this table, as well as records targetting the table's parent database. This information is obtained from the `ProtectedTimestampTableReader` mentioned above. Additionally, this change modifies `StartTenant` to allow secondary tenants to interact with the protected timestamp subsystem using a "real" `protectedts.Provider` provided the migration `AlterSystemProtectedTimestampAddColumn` has run. This is sound because this migration will only run after span config reconciliation has started in tenants. For testing purposes, this change teaches the data driven framework of two additional commands `protect` and `release`. Informs: #73727 Release note: None
- Loading branch information
1 parent
080e7ae
commit 84786e3
Showing
11 changed files
with
323 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/protectedts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Create a database with some tables and write protected timestamps on the | ||
# tables and database. Check that span configurations are as we expect. | ||
|
||
exec-sql | ||
CREATE DATABASE db; | ||
CREATE TABLE db.t1(id INT); | ||
CREATE TABLE db.t2(); | ||
---- | ||
|
||
query-sql | ||
SELECT id FROM system.namespace WHERE name='t1' | ||
---- | ||
56 | ||
|
||
query-sql | ||
SELECT id FROM system.namespace WHERE name='t2' | ||
---- | ||
57 | ||
|
||
# We only expect there to be span config entries for tables t1 and t2. | ||
translate database=db | ||
---- | ||
/Table/5{6-7} range default | ||
/Table/5{7-8} range default | ||
|
||
# Alter zone config fields on the database and one of the tables to ensure | ||
# things are cascading. | ||
exec-sql | ||
ALTER DATABASE db CONFIGURE ZONE USING num_replicas=7; | ||
ALTER TABLE db.t1 CONFIGURE ZONE USING num_voters=5; | ||
---- | ||
|
||
# Write a protected timestamp on t1. | ||
protect database=db table=t1 id=1 ts=1 | ||
---- | ||
|
||
translate database=db | ||
---- | ||
/Table/5{6-7} num_replicas=7 num_voters=5 pts=[1] | ||
/Table/5{7-8} num_replicas=7 | ||
|
||
# Write a protected timestamp on db, so we should see it on both t1 and t2. | ||
protect database=db id=2 ts=2 | ||
---- | ||
|
||
translate database=db | ||
---- | ||
/Table/5{6-7} num_replicas=7 num_voters=5 pts=[1 2] | ||
/Table/5{7-8} num_replicas=7 pts=[2] | ||
|
||
# Release the protected timestamp on table t1 | ||
release id=1 | ||
---- | ||
|
||
translate database=db | ||
---- | ||
/Table/5{6-7} num_replicas=7 num_voters=5 pts=[2] | ||
/Table/5{7-8} num_replicas=7 pts=[2] | ||
|
||
# Release the protected timestamp on database db | ||
release id=2 | ||
---- | ||
|
||
translate database=db | ||
---- | ||
/Table/5{6-7} num_replicas=7 num_voters=5 | ||
/Table/5{7-8} num_replicas=7 | ||
|
||
# Create an index on t1 to ensure that subzones also see protected timestamps. | ||
exec-sql | ||
CREATE INDEX idx ON db.t1(id); | ||
ALTER INDEX db.t1@idx CONFIGURE ZONE USING gc.ttlseconds = 1; | ||
---- | ||
|
||
protect database=db table=t1 id=3 ts=3 | ||
---- | ||
|
||
translate database=db | ||
---- | ||
/Table/56{-/2} num_replicas=7 num_voters=5 pts=[3] | ||
/Table/56/{2-3} ttl_seconds=1 num_replicas=7 num_voters=5 pts=[3] | ||
/Table/5{6/3-7} num_replicas=7 num_voters=5 pts=[3] | ||
/Table/5{7-8} num_replicas=7 | ||
|
83 changes: 83 additions & 0 deletions
83
pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/tenant/protectedts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Create a database with some tables and write protected timestamps on the | ||
# tables and database. Check that span configurations are as we expect. | ||
|
||
exec-sql | ||
CREATE DATABASE db; | ||
CREATE TABLE db.t1(id INT); | ||
CREATE TABLE db.t2(); | ||
---- | ||
|
||
query-sql | ||
SELECT id FROM system.namespace WHERE name='t1' | ||
---- | ||
56 | ||
|
||
query-sql | ||
SELECT id FROM system.namespace WHERE name='t2' | ||
---- | ||
57 | ||
|
||
# We only expect there to be span config entries for tables t1 and t2. | ||
translate database=db | ||
---- | ||
/Tenant/10/Table/5{6-7} range default | ||
/Tenant/10/Table/5{7-8} range default | ||
|
||
# Alter zone config fields on the database and one of the tables to ensure | ||
# things are cascading. | ||
exec-sql | ||
ALTER DATABASE db CONFIGURE ZONE USING num_replicas=7; | ||
ALTER TABLE db.t1 CONFIGURE ZONE USING num_voters=5; | ||
---- | ||
|
||
# Write a protected timestamp on t1. | ||
protect database=db table=t1 id=1 ts=1 | ||
---- | ||
|
||
translate database=db | ||
---- | ||
/Tenant/10/Table/5{6-7} num_replicas=7 num_voters=5 pts=[1] | ||
/Tenant/10/Table/5{7-8} num_replicas=7 | ||
|
||
# Write a protected timestamp on db, so we should see it on both t1 and t2. | ||
protect database=db id=2 ts=2 | ||
---- | ||
|
||
translate database=db | ||
---- | ||
/Tenant/10/Table/5{6-7} num_replicas=7 num_voters=5 pts=[1 2] | ||
/Tenant/10/Table/5{7-8} num_replicas=7 pts=[2] | ||
|
||
# Release the protected timestamp on table t1 | ||
release id=1 | ||
---- | ||
|
||
translate database=db | ||
---- | ||
/Tenant/10/Table/5{6-7} num_replicas=7 num_voters=5 pts=[2] | ||
/Tenant/10/Table/5{7-8} num_replicas=7 pts=[2] | ||
|
||
# Release the protected timestamp on database db | ||
release id=2 | ||
---- | ||
|
||
translate database=db | ||
---- | ||
/Tenant/10/Table/5{6-7} num_replicas=7 num_voters=5 | ||
/Tenant/10/Table/5{7-8} num_replicas=7 | ||
|
||
# Create an index on t1 to ensure that subzones also see protected timestamps. | ||
exec-sql | ||
CREATE INDEX idx ON db.t1(id); | ||
ALTER INDEX db.t1@idx CONFIGURE ZONE USING gc.ttlseconds = 1; | ||
---- | ||
|
||
protect database=db table=t1 id=3 ts=3 | ||
---- | ||
|
||
translate database=db | ||
---- | ||
/Tenant/10/Table/56{-/2} num_replicas=7 num_voters=5 pts=[3] | ||
/Tenant/10/Table/56/{2-3} ttl_seconds=1 num_replicas=7 num_voters=5 pts=[3] | ||
/Tenant/10/Table/5{6/3-7} num_replicas=7 num_voters=5 pts=[3] | ||
/Tenant/10/Table/5{7-8} num_replicas=7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.