Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

feat: exactly-once delivery support - #550

Merged
pradn merged 44 commits into
googleapis:mainfrom
pradn:exactly-once2
Mar 4, 2022
Merged

feat: exactly-once delivery support#550
pradn merged 44 commits into
googleapis:mainfrom
pradn:exactly-once2

Conversation

@pradn

@pradnpradn commented Dec 13, 2021

Copy link
Copy Markdown
Contributor
  • Add new field to SubscriptionProperties and modify the GAPIC layer with just this one change. This change will come from the auto-GAPIC generated code once the proto change is public.
  • Add async ack/modack/nack methods to the Message class. Exactly-once users have to use this to get the status of ack/modack/nack requests. The futures returned by these methods may be completed by the AcknowledgeError exception (with detailed AcknowledgeStatus status code) or a success AcknowledgeStatus code. These futures are of a new type, one used only on the subscriber-side for propagating exactly-once errors. This future mirrors the publishing-side future that already exists. The futures are completed immediately if exactly-once delivery is not enabled, upon successful ack/modack completion, and when errors/exceptions occur.
  • Split unary ack/modack methods into two in the subscriber manager. Some repeated code but it's simpler this way.
  • Keep track of whether exactly-once is enabled for a subscription by looking at the subscription's SubscriptionProperties, returned in the streaming response.
  • Set the minimum ack deadline to 60 secs if exactly-once is known to be turned on. This deadline is used by the leaser.
  • Add new min-lease-extension parameter. If the user sets this, it overrides the auto-set param based on whether exactly-once is enabled or not.
  • Retry unary ack/modacks if we get errors in the GRPC call's ErrorInfo (no retry delays as of yet since the server will eventually fail them if the ack expires). This is done in the dispatcher, which retries only the acks/modacks that have failed temporarily. Permanent failures are surfaced to the user as future exceptions. These retries use an exponential backoff with a max of 10 min, which is sufficient since the server allows ack/modacks for 10 mins max. These retries are triggered on a new thread to prevent the dispatcher thread from being blocked by retry-wait sleeps.
  • Retry lease modacks, both immediately upon receipt of messages and also in the background. If retries fail or if permanent errors arise, we log the errors but don't otherwise disrupt user code.
  • Send a new ack deadline via stream_ack_deadline_seconds whenever the exactly_once setting for a stream changes.
  • Add tests ensuring 100% coverage
  • Usage sample for this feature added at samples: sample for receiving messages with exactly-once delivery enabled #588

@pradn
pradn requested a review from plamutDecember 13, 2021 22:12
@product-auto-labelproduct-auto-labelBot added the api: pubsub Issues related to the googleapis/python-pubsub API. label Dec 13, 2021
@pradnpradn changed the title Exactly-once changes (draft)feat: exactly-once changes (draft)Dec 13, 2021

@plamutplamut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is only a partial feedback, I have not gone through the entire PR yet.

The think we need to be careful about is to not block any worker threads for too long, e.g. when retrying failed requests.

Comment threadgoogle/cloud/pubsub_v1/proto/pubsub.proto
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py Outdated

@plamutplamut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Round two, added some additional comments.

Will review the streaming pull manager tests later.

Comment threadgoogle/cloud/pubsub_v1/subscriber/message.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/message.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/message.py
Comment threadgoogle/cloud/pubsub_v1/subscriber/message.py Outdated
Comment threadgoogle/pubsub_v1/types/pubsub.py Outdated
Comment threadtests/unit/pubsub_v1/subscriber/test_dispatcher.py

@plamutplamut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Went through the rest of the PR, this should be it for the first review round. :)

Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py Outdated
Comment threadtests/unit/pubsub_v1/subscriber/test_streaming_pull_manager.py Outdated
Comment threadtests/unit/pubsub_v1/subscriber/test_streaming_pull_manager.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py Outdated
@plamut

Copy link
Copy Markdown
Contributor

@pradn I see a lot of comments marked as resolved, but no changes in the code - is there a git push missing? :)

@pradnpradn left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Pushed

Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/message.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/message.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/message.py Outdated
Comment threadtests/unit/pubsub_v1/subscriber/test_dispatcher.py
Comment threadtests/unit/pubsub_v1/subscriber/test_streaming_pull_manager.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/message.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py Outdated
@snippet-bot

snippet-botBot commented Feb 16, 2022

Copy link
Copy Markdown

No region tags are edited in this PR.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Comment threadtests/unit/pubsub_v1/subscriber/test_futures_subscriber.py Outdated
@acocuzzo
acocuzzo marked this pull request as ready for review February 23, 2022 21:38
@acocuzzo
acocuzzo requested a review from a teamFebruary 23, 2022 21:38
@acocuzzo
acocuzzo requested a review from a team as a code ownerFebruary 23, 2022 21:38
@acocuzzo
acocuzzo requested review from a team and nicainFebruary 23, 2022 21:38

@acocuzzoacocuzzo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

After conversation: https://github.com/googleapis/python-pubsub/pull/550/files#r769774809
is resolved, and all checks pass, LGTM.

Comment threadsamples/snippets/subscriber.py Outdated
Comment threadsamples/snippets/subscriber.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py Outdated
Comment threadgoogle/cloud/pubsub_v1/subscriber/message.py
Comment threadgoogle/cloud/pubsub_v1/subscriber/message.py
Comment threadgoogle/cloud/pubsub_v1/subscriber/message.py
Comment threadgoogle/cloud/pubsub_v1/subscriber/message.py
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/requests.py
Comment threadgoogle/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py
@pradn
pradn removed request for a team and nicainFebruary 25, 2022 22:45
@pradnpradn changed the title feat: exactly-once changes (draft)feat: exactly-once changesMar 1, 2022
@pradnpradn changed the title feat: exactly-once changesfeat: exactly-once delivery supportMar 1, 2022
@pradn
pradn merged commit 2fb6e15 into googleapis:mainMar 4, 2022
This was referenced Mar 4, 2022
@release-pleaserelease-pleaseBot mentioned this pull request Aug 11, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: pubsubIssues related to the googleapis/python-pubsub API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@pradn@plamut@tswast@maheshgattani@anguillanneuf@acocuzzo