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

feat: cmd reset subscription to topic head #2210

Merged
merged 2 commits into from
Jul 31, 2024

Conversation

worstell
Copy link
Contributor

fixes #2175

@worstell worstell requested a review from alecthomas as a code owner July 31, 2024 00:48
@worstell worstell requested review from a team, deniseli and matt2e and removed request for a team July 31, 2024 00:48
@worstell worstell force-pushed the worstell/20240729-add-reset-subscription-cmd branch from e4a96fd to a0404e1 Compare July 31, 2024 00:48
@ftl-robot ftl-robot mentioned this pull request Jul 31, 2024
Copy link
Contributor

@deniseli deniseli left a comment

Choose a reason for hiding this comment

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

Niiiice! This was way easier to digest than I expected from that line count lol

Copy link
Collaborator

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

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

Awesome Lizzy, thanks.

@@ -127,6 +127,47 @@ func (d *DAL) CompleteEventForSubscription(ctx context.Context, module, name str
return nil
}

// ResetSubscription resets the subscription cursor to the topic's head.
func (d *DAL) ResetSubscription(ctx context.Context, module, name string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll need a named error return value in order for tx.CommitOrRollback() to work - super not obvious I know.

Suggested change
func (d *DAL) ResetSubscription(ctx context.Context, module, name string) error {
func (d *DAL) ResetSubscription(ctx context.Context, module, name string) (err error) {

@@ -0,0 +1,5 @@
package main
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's call the top level command pubsub? So maybe ftl pubsub subscription reset? A little verbose, but I think we'll likely want more pubsub related commands, and they're not all subscriptions.

subscriptionCursorAt("echo", "emailInvoices", 1),
Exec("ftl", "subscription", "reset", "echo.emailInvoices"),
topicHeadAt("time", "invoices", 2),
subscriptionCursorAt("echo", "emailInvoices", 2),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome.

@worstell worstell force-pushed the worstell/20240729-add-reset-subscription-cmd branch from c0365e8 to 073c639 Compare July 31, 2024 01:58
@worstell worstell force-pushed the worstell/20240729-add-reset-subscription-cmd branch from e319872 to a6d05c6 Compare July 31, 2024 02:01
@worstell worstell merged commit cf5d19b into main Jul 31, 2024
64 checks passed
@worstell worstell deleted the worstell/20240729-add-reset-subscription-cmd branch July 31, 2024 02:15
WHERE "key" = $2::topic_event_key
)
UPDATE topic_subscriptions
SET state = 'idle',
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this could cause a race condition, maybe?

  • Subscription is behind and currently consuming an event
  • Reset subscription command comes in sets the state to idle and updates the cursor to head
  • 2 new events are posted to the topic
  • New event starts being consumed by the subscription
  • Original event (from before the reset command) finishes being processed, sets the state to idle even though we are processing the other event still
  • Then pub sub triggers the next event to be processed (without knowing the other event is being processed still)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah interesting, do you think the solution would be to only update the cursor and not the state? so that if there are any outstanding async calls executing, they'd have to complete before any new ones are kicked off

Copy link
Collaborator

Choose a reason for hiding this comment

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

I honestly don't know, possibly! I added it as an issue because I'm not sure whether its a priority but didn't want it to be lost: #2261

@matt2e
Copy link
Collaborator

matt2e commented Jul 31, 2024

Looks good! 👏

@matt2e matt2e added the approved Marks an already closed PR as approved label Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Marks an already closed PR as approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to reset a subscription to the head of a topic
4 participants