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: do not use InitPut with FailOnTombstones on Insert #138706

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

yuzefovich
Copy link
Member

This commit switches the usage of InitPut KV request when inserting a new sql liveness session from FailOnTombstones=true to FailOnTombstones=false. The contract of the Insert method is that the caller should never provide previously used session ID which is achieved by generating a random V4 UUID, so the probability of ever generating a duplicate is miniscule. The usage of FailOnTombstones=true option provides additional protection if the same session ID is reused within the GC TTL of the relevant range (because tombstones would get removed on MVCC garbage collection and/or compactions in pebble). This usage was introduced in 686f323 where we switched from SQL INSERT statement - which behaved similar to FailOnTombstones=false.

My main motivation behind this change is that this is the only place where we use FailOnTombstones=true option of the InitPut, and we're about to deprecate the InitPuts in favor of CPuts, yet CPuts don't have this option which would make the deprecation process more involved.

Also I think the current handling of this scenario by the code is partially broken. Namely, if previously used session ID is provided while there is a tombstone on the relevant key, the ConditionFailedError would be returned, and the loop in Instance.createSession would exceed the retry duration because on this error type we do not reset session.id field. This will result in not being able to create a session by the SQL instance, so it will fatal the process. On a quick search via Glean we never encountered this fatal before though.

With the change in this commit in the case of inserting the previously used session ID the behavior is undefined (I think one possible scenario is that other SQL instances won't be able to see this new instance because they have cached the session ID in the deadSessions cache, so the new instance won't be used for distributed queries; there are probably other consequences too).

Still, it seems reasonable to me to rely on randomly-generated UUIDs never repeating without additional - but only temporary - protection of FailOnTombstones.

Informs: #71074.
Epic: None

Release note: None

This commit switches the usage of `InitPut` KV request when inserting
a new sql liveness session from `FailOnTombstones=true` to
`FailOnTombstones=false`. The contract of the `Insert` method is that
the caller should never provide previously used session ID which is
achieved by generating a random V4 UUID, so the probability of ever
generating a duplicate is miniscule. The usage of
`FailOnTombstones=true` option provides additional protection if the
same session ID is reused within the GC TTL of the relevant range
(because tombstones would get removed on MVCC garbage collection and/or
compactions in pebble). This usage was introduced in
686f323 where we switched from SQL
INSERT statement - which behaved similar to `FailOnTombstones=false`.

My main motivation behind this change is that this is the only place
where we use `FailOnTombstones=true` option of the InitPut, and we're
about to deprecate the InitPuts in favor of CPuts, yet CPuts don't have
this option which would make the deprecation process more involved.

Also I think the current handling of this scenario by the code is
partially broken. Namely, if previously used session ID is provided
while there is a tombstone on the relevant key, the ConditionFailedError
would be returned, and the loop in `Instance.createSession` would exceed
the retry duration because on this error type we do not reset
`session.id` field. This will result in not being able to create
a session by the SQL instance, so it will fatal the process. On a quick
search via Glean we never encountered this fatal before though.

With the change in this commit in the case of inserting the previously
used session ID the behavior is undefined (I think one possible scenario
is that other SQL instances won't be able to see this new instance
because they have cached the session ID in the deadSessions cache, so
the new instance won't be used for distributed queries; there are
probably other consequences too).

Still, it seems reasonable to me to rely on randomly-generated UUIDs
never repeating without additional - but only temporary - protection of
`FailOnTombstones`.

Release note: None
@yuzefovich yuzefovich requested review from rafiss, fqazi and a team January 9, 2025 01:15
Copy link

blathers-crl bot commented Jan 9, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

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.

thanks for this investigation!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @fqazi and @yuzefovich)


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

		}
		v := encodeValue(expiration)
		batch.InitPut(k, &v, false /* failOnTombstones */)

super nit: comment mentioning that we're relying on UUID uniqueness may be useful, but also if this is changing to a CPut soon anyway, perhaps it's not necessary.

Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

TFTR!

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @fqazi and @rafiss)


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

Previously, rafiss (Rafi Shamim) wrote…

super nit: comment mentioning that we're relying on UUID uniqueness may be useful, but also if this is changing to a CPut soon anyway, perhaps it's not necessary.

Yeah, we'll switch this to CPut shortly, so I won't add a comment.

@craig craig bot merged commit c603477 into cockroachdb:master Jan 9, 2025
22 checks passed
@yuzefovich yuzefovich deleted the init-put-tombstones branch January 9, 2025 18:22
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