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: exactly-once delivery support #550

Merged
merged 44 commits into from
Mar 4, 2022
Merged

Conversation

pradn
Copy link
Contributor

@pradn pradn commented Dec 13, 2021

  • 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 plamut December 13, 2021 22:12
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/python-pubsub API. label Dec 13, 2021
@pradn pradn changed the title Exactly-once changes (draft) feat: exactly-once changes (draft) Dec 13, 2021
Copy link
Contributor

@plamut plamut left a comment

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.

google/cloud/pubsub_v1/proto/pubsub.proto Show resolved Hide resolved
google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py Outdated Show resolved Hide resolved
google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py Outdated Show resolved Hide resolved
google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py Outdated Show resolved Hide resolved
google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py Outdated Show resolved Hide resolved
Copy link
Contributor

@plamut plamut left a comment

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.

google/cloud/pubsub_v1/subscriber/message.py Outdated Show resolved Hide resolved
google/cloud/pubsub_v1/subscriber/message.py Outdated Show resolved Hide resolved
google/cloud/pubsub_v1/subscriber/message.py Show resolved Hide resolved
google/cloud/pubsub_v1/subscriber/message.py Outdated Show resolved Hide resolved
google/pubsub_v1/types/pubsub.py Outdated Show resolved Hide resolved
Copy link
Contributor

@plamut plamut left a comment

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. :)

@plamut
Copy link
Contributor

plamut commented Jan 13, 2022

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

Copy link
Contributor Author

@pradn pradn left a comment

Choose a reason for hiding this comment

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

Pushed

google/cloud/pubsub_v1/subscriber/message.py Outdated Show resolved Hide resolved
google/cloud/pubsub_v1/subscriber/message.py Outdated Show resolved Hide resolved
google/cloud/pubsub_v1/subscriber/message.py Outdated Show resolved Hide resolved
@snippet-bot
Copy link

snippet-bot bot commented Feb 16, 2022

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

@acocuzzo acocuzzo marked this pull request as ready for review February 23, 2022 21:38
@acocuzzo acocuzzo requested review from a team as code owners February 23, 2022 21:38
@acocuzzo acocuzzo requested a review from nicain February 23, 2022 21:38
Copy link
Contributor

@acocuzzo acocuzzo left a comment

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.

@pradn pradn removed request for nicain and a team February 25, 2022 22:45
@pradn pradn changed the title feat: exactly-once changes (draft) feat: exactly-once changes Mar 1, 2022
@pradn pradn changed the title feat: exactly-once changes feat: exactly-once delivery support Mar 1, 2022
@pradn pradn merged commit 2fb6e15 into googleapis:main Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/python-pubsub API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants