Skip to content

Commit 16a40c7

Browse files
committed
sql: add TTL on inspect error entries
To bound the footprint of the `system.inspect_errors` table, this change adds a row-level TTL. The cluster-level setting configures the TTL period on new entries; changes to the setting are not effected on new entries immediately nor are they applied retroactively. Epic: CRDB-30356 Fixes: #148270 Release note: None
1 parent a73404b commit 16a40c7

File tree

8 files changed

+50
-36
lines changed

8 files changed

+50
-36
lines changed

pkg/sql/catalog/bootstrap/testdata/testdata

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

pkg/sql/catalog/systemschema/system.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,10 +1338,11 @@ CREATE TABLE public.inspect_errors (
13381338
id OID NOT NULL,
13391339
primary_key STRING NULL,
13401340
details STRING NOT NULL,
1341+
crdb_internal_expiration TIMESTAMPTZ NOT NULL DEFAULT current_timestamp():::TIMESTAMPTZ + '90 days':::INTERVAL ON UPDATE current_timestamp():::TIMESTAMPTZ + '90 days':::INTERVAL,
13411342
CONSTRAINT "primary" PRIMARY KEY (error_id ASC),
13421343
INDEX object_idx (id ASC),
1343-
FAMILY "primary" (error_id, job_id, error_type, database_id, schema_id, id, primary_key, details)
1344-
);`
1344+
FAMILY "primary" (error_id, job_id, error_type, database_id, schema_id, id, primary_key, details, crdb_internal_expiration)
1345+
) WITH (ttl_expire_after = '90 days');`
13451346
)
13461347

13471348
func pk(name string) descpb.IndexDescriptor {
@@ -5228,6 +5229,8 @@ var (
52285229
),
52295230
)
52305231

5232+
inspectErrorsExpirationString = "current_timestamp():::TIMESTAMPTZ + '90 days':::INTERVAL"
5233+
52315234
InspectErrorsTable = makeSystemTable(
52325235
InspectErrorsTableSchema,
52335236
systemTable(
@@ -5242,13 +5245,14 @@ var (
52425245
{Name: "id", ID: 6, Type: types.Oid},
52435246
{Name: "primary_key", ID: 7, Type: types.String, Nullable: true},
52445247
{Name: "details", ID: 8, Type: types.String},
5248+
{Name: "crdb_internal_expiration", ID: 9, Type: types.TimestampTZ, DefaultExpr: &inspectErrorsExpirationString, OnUpdateExpr: &inspectErrorsExpirationString},
52455249
},
52465250
[]descpb.ColumnFamilyDescriptor{
52475251
{
52485252

52495253
Name: "primary",
5250-
ColumnNames: []string{"error_id", "job_id", "error_type", "database_id", "schema_id", "id", "primary_key", "details"},
5251-
ColumnIDs: []descpb.ColumnID{1, 2, 3, 4, 5, 6, 7, 8},
5254+
ColumnNames: []string{"error_id", "job_id", "error_type", "database_id", "schema_id", "id", "primary_key", "details", "crdb_internal_expiration"},
5255+
ColumnIDs: []descpb.ColumnID{1, 2, 3, 4, 5, 6, 7, 8, 9},
52525256
},
52535257
},
52545258
descpb.IndexDescriptor{
@@ -5270,6 +5274,10 @@ var (
52705274
KeySuffixColumnIDs: []descpb.ColumnID{1},
52715275
},
52725276
),
5277+
func(tbl *descpb.TableDescriptor) {
5278+
tbl.RowLevelTTL = &catpb.RowLevelTTL{
5279+
DurationExpr: catpb.Expression("'90 days':::INTERVAL")}
5280+
},
52735281
)
52745282
)
52755283

pkg/sql/catalog/systemschema_test/testdata/bootstrap_system

Lines changed: 5 additions & 4 deletions
Large diffs are not rendered by default.

pkg/sql/catalog/systemschema_test/testdata/bootstrap_tenant

Lines changed: 5 additions & 4 deletions
Large diffs are not rendered by default.

pkg/sql/logictest/testdata/logic_test/gen_test_objects

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -198,26 +198,26 @@ WHERE table_catalog = 'newdb2' AND table_schema = 'public'
198198
ORDER BY table_name, column_name
199199
LIMIT 20
200200
----
201-
"insp""ect_err""ors" "error_id" uuid
202-
"insp""ect_err""ors" "databas😩e_!id😝" oid
203-
"insp""ect_err""ors" details text
204-
"insp""ect_err""ors" er_ror_type text
205-
"insp""ect_err""ors" "id \v" oid
206-
"insp""ect_err""ors" "j%vob_id͐" bigint
207-
"insp""ect_err""ors" primary_key text
208-
"insp""ect_err""ors" rowid bigint
209-
"insp""ect_err""ors" schema_id oid
210-
jobs claim_instance_id bigint
211-
jobs claim_session_id bytea
212-
jobs "cre\\xa7a%6bted_b,y_type" text
213-
jobs created timestamp without time zone
214-
jobs created_by_id bigint
215-
jobs description text
216-
jobs error_msg text
217-
jobs "finiShed" timestamp with time zone
218-
jobs id bigint
219-
jobs "job._type" text
220-
jobs "la%55st_run" timestamp without time zone
201+
"insp""ect_err""ors" "error_id" uuid
202+
"insp""ect_err""ors" "crdb_internal_exp iration" timestamp with time zone
203+
"insp""ect_err""ors" "databas😩e_!id😝" oid
204+
"insp""ect_err""ors" details text
205+
"insp""ect_err""ors" er_ror_type text
206+
"insp""ect_err""ors" "id \v" oid
207+
"insp""ect_err""ors" "j%vob_id͐" bigint
208+
"insp""ect_err""ors" primary_key text
209+
"insp""ect_err""ors" rowid bigint
210+
"insp""ect_err""ors" schema_id oid
211+
jobs claim_instance_id bigint
212+
jobs claim_session_id bytea
213+
jobs "cre\\xa7a%6bted_b,y_type" text
214+
jobs created timestamp without time zone
215+
jobs created_by_id bigint
216+
jobs description text
217+
jobs error_msg text
218+
jobs "finiShed" timestamp with time zone
219+
jobs id bigint
220+
jobs "job._type" text
221221

222222
subtest templates/different_templates_in_each_db
223223

pkg/sql/logictest/testdata/logic_test/information_schema

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,7 @@ system public 29_73_2_not_null
15711571
system public 29_73_3_not_null error_type IS NOT NULL
15721572
system public 29_73_6_not_null id IS NOT NULL
15731573
system public 29_73_8_not_null details IS NOT NULL
1574+
system public 29_73_9_not_null crdb_internal_expiration IS NOT NULL
15741575
system public 29_7_1_not_null value IS NOT NULL
15751576
system public 29_8_1_not_null id IS NOT NULL
15761577
system public 29_9_1_not_null crdb_region IS NOT NULL
@@ -1897,6 +1898,7 @@ system public 29_73_2_not_null
18971898
system public 29_73_3_not_null error_type IS NOT NULL
18981899
system public 29_73_6_not_null id IS NOT NULL
18991900
system public 29_73_8_not_null details IS NOT NULL
1901+
system public 29_73_9_not_null crdb_internal_expiration IS NOT NULL
19001902
system public 29_7_1_not_null value IS NOT NULL
19011903
system public 29_8_1_not_null id IS NOT NULL
19021904
system public 29_9_1_not_null crdb_region IS NOT NULL

pkg/sql/opt/testutils/testcat/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ go_library(
4747
"//pkg/sql/privilege",
4848
"//pkg/sql/roleoption",
4949
"//pkg/sql/rowenc",
50+
"//pkg/sql/sem/builtins",
5051
"//pkg/sql/sem/catconstants",
5152
"//pkg/sql/sem/catid",
5253
"//pkg/sql/sem/eval",

pkg/sql/opt/testutils/testcat/vtable.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package testcat
88
import (
99
"github.com/cockroachdb/cockroach/pkg/sql/catalog/systemschema"
1010
"github.com/cockroachdb/cockroach/pkg/sql/parser"
11+
_ "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins"
1112
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
1213
"github.com/cockroachdb/cockroach/pkg/sql/vtable"
1314
"github.com/cockroachdb/errors"

0 commit comments

Comments
 (0)