Add auto expiry for DynamoDB backend#5805
Conversation
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 Report
@@ 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
Continue to review full report at Codecov.
|
georgepsarakis
left a comment
There was a problem hiding this comment.
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.
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.
|
@sveniu will this work with existing installations? I am quite sure it will, but please let's consider backwards compatibility. |
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
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
left a comment
There was a problem hiding this comment.
Thanks for addressing the comments, I added a few more observations for possible enhancements, but overall this should be ready for merge.
Additional changes: - Handle exceptions when calling boto3's describe_time_to_live() - Fix test cases for missing TTL methods
georgepsarakis
left a comment
There was a problem hiding this comment.
Other than the last two comments, I think this should be ready for merge. Nice work @sveniu !
|
this should be on hold for 4.5 |
|
@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. |
| "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(): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
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.