Skip to content

Add auto expiry for DynamoDB backend#5805

Merged
thedrow merged 13 commits into
celery:masterfrom
sveniu:dynamodb-autoexpire
Nov 25, 2019
Merged

Add auto expiry for DynamoDB backend#5805
thedrow merged 13 commits into
celery:masterfrom
sveniu:dynamodb-autoexpire

Conversation

@sveniu

@sveniu sveniu commented Oct 30, 2019

Copy link
Copy Markdown
Contributor

Description

This adds auto-expire support for the DynamoDB backend, via the DynamoDB Time to Live feature.

Highlighting OG DynamoDB backend author @georgepsarakis in case he wants to take a look as well.

Sven Ulland added 2 commits October 30, 2019 20:38
This adds auto-expire support for the DynamoDB backend, via the DynamoDB
Time to Live feature.
boto3 version 1.9.178 requires botocore>=1.12.178.

botocore version 1.12.178 introduces support for the DynamoDB
UpdateTimeToLive call.

The UpdateTimeToLive call is used by the DynamoDB backend to enable TTL
support on a newly created table.
@codecov

codecov Bot commented Oct 30, 2019

Copy link
Copy Markdown

Codecov Report

Merging #5805 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5805      +/-   ##
==========================================
+ Coverage   83.13%   83.19%   +0.06%     
==========================================
  Files         144      144              
  Lines       17022    17089      +67     
  Branches     2095     2106      +11     
==========================================
+ Hits        14151    14218      +67     
  Misses       2656     2656              
  Partials      215      215
Impacted Files Coverage Δ
celery/backends/dynamodb.py 97.8% <100%> (+1.16%) ⬆️
celery/app/task.py 96.68% <0%> (+0.02%) ⬆️
celery/worker/consumer/events.py 96.87% <0%> (+0.1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8973030...b0c56a8. Read the comment docs.

@georgepsarakis georgepsarakis 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.

Great work! Thank you very much for your contribution.

I noted a few observations that may be problematic, but overall this seems at a very good state.

Comment thread celery/backends/dynamodb.py Outdated
Comment thread celery/backends/dynamodb.py Outdated
Comment thread celery/backends/dynamodb.py
Handle TTL enabling/disabling separately from the table get-or-create
function.

Improve handling of cases where the TTL is already set to the desired
state.

DynamoDB only allows a single TTL update action within a fairly long
time window, so some problematic cases (changing the TTL attribute,
enabling/disabling TTL when it was recently modified) will raise
exceptions that have to be dealt with.
@georgepsarakis

Copy link
Copy Markdown
Contributor

@sveniu will this work with existing installations? I am quite sure it will, but please let's consider backwards compatibility.

Sven Ulland added 2 commits November 1, 2019 21:30
If the boto3 TTL methods are not found, log an informative error. If the
user wants to enable TTL, raise an exception; if TTL should be disabled,
simply return.
- Handle exceptions by logging the error and re-raising

- Log (level debug) when the desired TTL state is already in place
@sveniu

sveniu commented Nov 1, 2019

Copy link
Copy Markdown
Contributor Author

@sveniu will this work with existing installations? I am quite sure it will, but please let's consider backwards compatibility.

I've added some code to gracefully handle older boto3 versions not supporting the TTL methods. This is in addition to the earlier commit that bumps the requirements file to require a boto3 version that actually has TTL support.

As for server-side compatibility: There may be users who use older versions of the downloadable local DynamoDB without support for TTL. I think all AWS regions have TTL support at this moment. In any case, there would be a "normal" exception from boto3 and it would be logged in the exception handler.

@georgepsarakis georgepsarakis 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.

Thanks for addressing the comments, I added a few more observations for possible enhancements, but overall this should be ready for merge.

Comment thread celery/backends/dynamodb.py Outdated
Comment thread celery/backends/dynamodb.py Outdated
Comment thread celery/backends/dynamodb.py Outdated
Comment thread docs/userguide/configuration.rst
Sven Ulland added 2 commits November 4, 2019 11:56
Additional changes:

- Handle exceptions when calling boto3's describe_time_to_live()

- Fix test cases for missing TTL methods

@georgepsarakis georgepsarakis 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.

Other than the last two comments, I think this should be ready for merge. Nice work @sveniu !

Comment thread celery/backends/dynamodb.py Outdated
@auvipy

auvipy commented Nov 9, 2019

Copy link
Copy Markdown
Member

this should be on hold for 4.5

@sveniu

sveniu commented Nov 11, 2019

Copy link
Copy Markdown
Contributor Author

@georgepsarakis With this nearing completion, how does merging work - should I squash (and possibly rewrite the commit message properly) and force-push a single commit, or does squashing happen from your side? I'd like to flesh out the commit message a bit, but no big deal if it's left as it was written in the first commit.

Comment thread celery/backends/dynamodb.py Outdated
"boto3 method '{method}' not found; ensure that "
"boto3>=1.9.178 and botocore>=1.12.178 are installed"
).format(method=method)
if not self._has_ttl():

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can't this part stand on its own as a guard? Even at debug level, the log can be a distraction when its not really used.

@reutsharabani reutsharabani Nov 12, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also, maybe consider if moving the boto validation code elsewhere is nicer.

And then you could do:

self._validate_boto_version()

It would make the code more direct. This method verification is a necessary nuisance which isn't at the heart of this operation and has enough code to justify its own method.

(it would also be nice to see all missing methods and not just the first, but that is also not a big deal).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed.