<#6451 Add support for cache TTL> Pull request ope...
# flyte-github
c
#6451 Add support for cache TTL Pull request opened by Sovietaced ## Tracking issue Closes #3305 ## Why are the changes needed? Flyte data may be stored in S3 buckets that have retention policies. If those retention policies delete the underlying data in S3 the entries in Flyte data catalog are stale and point to nonexistent buckets. This results in errors at task runtime in flytekit. ## What changes were proposed in this pull request? This pull request modifies Flyte data catalog such that artifacts in the catalog can expire and no longer be valid. The general approach is to allow for multiple rows with the same artifact key but to only retain one non-expired row ideally. I chose to allow for multiple rows to exist so that cleanup of expired artifacts could be done asynchronously. Also, there are multiple tables that hold references to the artifact table and ensuring these dependents were also expired seemed challenging. #### Data Model 1. A new column is added to the artifacts table,
expires_at
. This dictates when the artifact is no longer valid. 2. The composite primary key for artifacts was broadened to include
created_at
such that there can be multiple rows with the same artifact key (ideally with one and only one non-expired entry if insertions are done carefully and atomically). 3. The compose primary kettle for tag was breaded to include
artifact_id
such that multiple tags can exist with the same artifact key but can only point to one artifact. #### Data Layer 1. The data layer was updated to filter expired artifacts in get/list operations, this propagates to tags as well. 2. The data layer was updated such that non-expired artifacts are searched before creating new ones. #### Manager Layer 1. The TTL is used with a pluggable clock to generated the
expires_at
value for records. #### Propeller Updated propeller to plumb the cache TTL from the task metadata to Flyte data catalog API calls. #### Future Updates At a high level I'd like to follow up on this work with a background job of some sort that queries the DB for expired cache entries and then thoroughly cleans them up by deleting the contents if possible and then later removing the rows from Postgres. Similar to what is done in #4655 I realize flytekit changes will need to follow up here as well but I think those will be relatively trivial and this change is entirely backwards compatible. ## How was this patch tested? Unit tests, for now. ### Labels Please add one or more of the following labels to categorize your PR: • added: For new features. • changed: For changes in existing functionality. • deprecated: For soon-to-be-removed features. • removed: For features being removed. • fixed: For any bug fixed. • security: In case of vulnerabilities This is important to improve the readability of release notes. ### Setup process ### Screenshots ## Check all the applicable boxes • I updated the documentation accordingly. • All new and existing tests passed. • All commits are signed-off. ## Related PRs ## Docs link https://bito.ai#summarystart| ### Summary by Bito This pull request enhances the Flyte data catalog by introducing support for cache TTL, allowing artifacts to expire and preventing stale entries that could lead to runtime errors. Key modifications include the addition of an 'expires_at' column in the artifacts table and updates to the data layer for filtering expired artifacts. The implementation is designed to be backward compatible and includes unit tests to validate the new functionality. flyteorg/flyte
a