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

Added back exactly-once delivery for Postgres #28

Merged
merged 6 commits into from
Dec 19, 2023
Merged

Added back exactly-once delivery for Postgres #28

merged 6 commits into from
Dec 19, 2023

Conversation

roblaszczak
Copy link
Member

No description provided.

return Query{}
}

func (a DefaultPostgreSQLOffsetsAdapter) BeforeSubscribingQueries(topic string, consumerGroup string) []Query {

Choose a reason for hiding this comment

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

Hey @roblaszczak, what does this do? Sorry, I'm clearly an outsider to this codebase. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey @jcmfernandes!

It's required for exactly-once-delivery guarantee which I enabled in this version (see https://github.com/ThreeDotsLabs/watermill-sql/pull/28/files#diff-9c7c1342e6c9993e31c519e27f897bea0ffb721cb39fd7cf9bb70cfc4a56b6ebR530)

It adds "zero offsets" to the table with offsets. Without that, this lock

		Query: `
			SELECT 
    			offset_acked, 
    			last_processed_transaction_id 
			FROM ` + a.MessagesOffsetsTable(topic) + ` 
			WHERE consumer_group=$1 
			FOR UPDATE
		`,

won't work, because there is nothing to lock. If "zero offsets" won't be present and multiple concurrent subscribers will try to consume them it will lead to multiple delivery (because offsets are not locked).

I hope that makes sense! :)

Choose a reason for hiding this comment

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

Thank you, I believe I now understand. With that said, isn't "exactly-once-delivery" a misnomer here? You guarantee that multiple consumers don't concurrently deliver the message, but isn't the message delivered at least once? I.e., don't you attempt to redeliver if the message isn't acked?

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