-
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.ProtectedTimestampStateReader 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 ProtectedTimestampStateReader 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 EnableProtectedTimestampsForTenant has run. 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
8eaf8d2
commit 50619f0
Showing
21 changed files
with
426 additions
and
82 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
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
78 changes: 78 additions & 0 deletions
78
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,78 @@ | ||
# Create a database with some tables and write protected timestamps on the | ||
# tables and database. Check that span configurations are as we expect. | ||
# TODO(adityamaru): Add tests with Cluster, Tenant target once the translator | ||
# has been taught to generate SystemSpanConfigs. | ||
|
||
exec-sql | ||
CREATE DATABASE db; | ||
CREATE TABLE db.t1(id INT); | ||
CREATE TABLE db.t2(); | ||
---- | ||
|
||
# Schema object IDs | ||
# db: 54 | ||
# t1: 56 | ||
# t2: 57 | ||
|
||
# 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 record-id=1 ts=1 | ||
descs 56 | ||
---- | ||
|
||
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 record-id=2 ts=2 | ||
descs 54 | ||
---- | ||
|
||
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 record-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 record-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 record-id=3 ts=3 | ||
descs 56 | ||
---- | ||
|
||
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 | ||
|
75 changes: 75 additions & 0 deletions
75
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,75 @@ | ||
# 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(); | ||
---- | ||
|
||
# Schema object IDs | ||
# db: 54 | ||
# t1: 56 | ||
# t2: 57 | ||
|
||
# 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 record-id=1 ts=1 | ||
descs 56 | ||
---- | ||
|
||
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 record-id=2 ts=2 | ||
descs 54 | ||
---- | ||
|
||
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 record-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 record-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 record-id=3 ts=3 | ||
descs 56 | ||
---- | ||
|
||
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
Oops, something went wrong.