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

Make conditional vs unconditional updates clearer #48359

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

hugoShaka
Copy link
Contributor

When implementing AU services we mistakenly used unconditional updates instead of conditional updates.
This PR renames UpdateResource into UnconditionalUpdateResource to make it clearer that this might be unsafe and there's a ConditionalUpdateResource option.

@hugoShaka hugoShaka added no-changelog Indicates that a PR does not require a changelog entry backport/branch/v17 labels Nov 4, 2024
@hugoShaka hugoShaka force-pushed the hugo/clarify-unconditional-updates branch from 9bd32cd to 2e081a1 Compare November 4, 2024 15:24
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-48359.d3pp5qlev8mo18.amplifyapp.com

@marcoandredinis marcoandredinis removed their request for review November 4, 2024 15:40
// UpdateResource updates an existing resource.
func (s ServiceWrapper[T]) UpdateResource(ctx context.Context, resource T) (T, error) {
// UnconditionalUpdateResource updates an existing resource without checking the provided resource revision.
// This is faster and cheaper than ConditionalUpdateResource but can cause data loss on concurrent writes.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this description is particularly useful:

  • the backend Update operation by itself itself is not really faster or cheaper than ConditionalUpdate
  • the operation doesn't cause data loss, the usage pattern does
  • this description doesn't describe when it should be used (pretty much never), what the tradeoffs are, and what the alternative is

adapter, err := s.service.UpdateResource(ctx, newResourceMetadataAdapter(resource))
return adapter.resource, trace.Wrap(err)
}

// ConditionalUpdateResource updates an existing resource if the provided
// resource and the existing resource have matching revisions.
// This is safer than UnconditionalUpdateResource but more expensive and might not suit high-load scenarios.
Copy link
Contributor

Choose a reason for hiding this comment

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

More expensive than what? In a lot of backends the cost of the storage operation itself is pretty much the same, it's the usage pattern around optimistic locking that's more expensive than blindly upserting a value.

Without expanding too much in the docs here (unless you think it's useful) we could just link to https://github.com/gravitational/teleport/blob/master/rfd/0126-backend-migrations.md#optimistic-locking and https://github.com/gravitational/teleport/blob/master/rfd/0153-resource-guidelines.md#update-1 . WDYT?

@hugoShaka hugoShaka requested a review from espadolini November 5, 2024 14:26
@hugoShaka hugoShaka force-pushed the hugo/clarify-unconditional-updates branch from 64866cb to e8edf1d Compare November 5, 2024 16:59
@hugoShaka hugoShaka enabled auto-merge November 5, 2024 17:00
@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from kimlisa November 5, 2024 17:00
@hugoShaka hugoShaka added this pull request to the merge queue Nov 5, 2024
Merged via the queue into master with commit a85119b Nov 5, 2024
40 checks passed
@hugoShaka hugoShaka deleted the hugo/clarify-unconditional-updates branch November 5, 2024 17:49
@public-teleport-github-review-bot

@hugoShaka See the table below for backport results.

Branch Result
branch/v17 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/branch/v17 no-changelog Indicates that a PR does not require a changelog entry size/sm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants