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

ttl: refactor storage param Setter to not modify TableDescriptor TTL settings directly #88497

Merged
merged 1 commit into from
Sep 23, 2022
Merged

ttl: refactor storage param Setter to not modify TableDescriptor TTL settings directly #88497

merged 1 commit into from
Sep 23, 2022

Conversation

ecwall
Copy link
Contributor

@ecwall ecwall commented Sep 22, 2022

refs #88254

Changes the storage param Setter to modify UpdatedRowLevelTTL instead of the TableDescriptor directly so that the update can more easily be moved into a schema changer mutation if necessary.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@ecwall ecwall changed the title ttl: refactor storage param Setter to not modify TableDescriptor TTL ttl: refactor storage param Setter to not modify TableDescriptor TTL settings directly Sep 22, 2022
if (before != nil && before.HasDurationExpr()) && (after == nil || !after.HasDurationExpr()) {
telemetry.Inc(sqltelemetry.RowLevelTTLDropped)

if before.HasDurationExpr() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is redundant with the conditional above.


// UpdatedRowLevelTTL is kept separate from the RowLevelTTL in TableDesc
// in case changes need to be made in schema changer.
UpdatedRowLevelTTL *catpb.RowLevelTTL
Copy link
Contributor Author

@ecwall ecwall Sep 22, 2022

Choose a reason for hiding this comment

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

Instead of always modifying the TableDesc in Set()/Reset() and possibly unsetting it in handleTTLStorageParams() if there is a mutation. It will only be set in handleTTLStorageParams() if it is not done in a mutation.

@ecwall ecwall marked this pull request as ready for review September 22, 2022 20:21
@ecwall ecwall requested review from a team, rafiss, otan and ajwerner September 22, 2022 20:21
@ecwall
Copy link
Contributor Author

ecwall commented Sep 22, 2022

This is the just code refactor from #88260, but does not contain any bug fixes to make reviewing easier.

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 @ajwerner, @ecwall, and @otan)


pkg/sql/alter_table.go line 1960 at r1 (raw file):

		telemetry.Inc(sqltelemetry.RowLevelTTLDropped)

		if before.HasDurationExpr() {

i didn't follow why this got removed


pkg/sql/alter_table.go line 1983 at r1 (raw file):

	// Validate the type and volatility of ttl_expiration_expression.
	if after != nil && after.HasExpirationExpr() {

or why this got removed


pkg/sql/create_table.go line 1337 at r1 (raw file):

	}
	updatedRowLevelTTL := setter.UpdatedRowLevelTTL
	if updatedRowLevelTTL != nil {

nit: you could inline this with if updatedRowLevelTTL := setter.UpdatedRowLevelTTL; updatedRowLevelTTL != nil { ... }

Copy link
Contributor Author

@ecwall ecwall 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, @ecwall, @otan, and @rafiss)


pkg/sql/alter_table.go line 1960 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

i didn't follow why this got removed

It will always be true because it is already checked inside (before != nil && before.HasDurationExpr()) && (after == nil || !after.HasDurationExpr()).


pkg/sql/alter_table.go line 1983 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

or why this got removed

ValidateTTLExpirationExpression() already has this check inside it.

func ValidateTTLExpirationExpression(
	ctx context.Context,
	tableDesc catalog.TableDescriptor,
	semaCtx *tree.SemaContext,
	tableName *tree.TableName,
	ttl *catpb.RowLevelTTL,
) error {

	if !ttl.HasExpirationExpr() {
		return nil
	}
        ...

settings directly

refs #88254

Changes the storage param Setter to modify UpdatedRowLevelTTL instead of
the TableDescriptor directly so that the update can more easily be moved
into a schema changer mutation if necessary.

Release note: None
Copy link
Contributor Author

@ecwall ecwall 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, @otan, and @rafiss)


pkg/sql/create_table.go line 1337 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

nit: you could inline this with if updatedRowLevelTTL := setter.UpdatedRowLevelTTL; updatedRowLevelTTL != nil { ... }

Yeah that looks cleaner.

Code quote:

updatedRowLevelTTL := setter.UpdatedRowLevelTTL

@ecwall ecwall requested a review from rafiss September 22, 2022 21:37
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.

lgtm! good cleanup

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @ecwall, @otan, and @rafiss)


pkg/sql/alter_table.go line 1960 at r1 (raw file):

Previously, ecwall (Evan Wall) wrote…

It will always be true because it is already checked inside (before != nil && before.HasDurationExpr()) && (after == nil || !after.HasDurationExpr()).

ah thanks


pkg/sql/alter_table.go line 1983 at r1 (raw file):

Previously, ecwall (Evan Wall) wrote…

ValidateTTLExpirationExpression() already has this check inside it.

func ValidateTTLExpirationExpression(
	ctx context.Context,
	tableDesc catalog.TableDescriptor,
	semaCtx *tree.SemaContext,
	tableName *tree.TableName,
	ttl *catpb.RowLevelTTL,
) error {

	if !ttl.HasExpirationExpr() {
		return nil
	}
        ...

nice

@ecwall
Copy link
Contributor Author

ecwall commented Sep 22, 2022

bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Sep 23, 2022

Build succeeded:

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