-
Notifications
You must be signed in to change notification settings - Fork 3k
implement cache policy #14440
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
base: main
Are you sure you want to change the base?
implement cache policy #14440
Conversation
e315119 to
e2bbabf
Compare
gaborkaszab
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution @blcksrx !
Just thinking out loud but I'm wondering if this is something that requires configurability or if there is any benefit to keep the expireAfterAccess functionality instead of simply switching to expireAfterWrite without any new configs. Let's see what others say.
core/src/test/java/org/apache/iceberg/hadoop/TestCachingCatalog.java
Outdated
Show resolved
Hide resolved
Thank you very much. well my intention was not change the existing cache strategy, thats why I made it like that. |
|
Looking good, I do have a couple of questions. Would it make sense to provide a similar configuration option to the executor cache? Also, not sure on the etiquette in this repository, but it might be appropriate to tag some of the original reviewers from this PR - they might have some more context/opinions on how this should take shape #3543 I also quite like your suggestion of a pluggable caching strategy, but I think it is great to introduce some standard defaults for now and should solve my use case. |
|
Thank you very much for the input. I can provide the same PR on the ExecutorCache too. To getting this PR merge I need the community to vote and engage on it so I appreciate your support on it (please check the dev mailing archive of Iceberg). Regarding pluggable cache strategy, I saw that i would be much work to implement it at first, so I saw it as a MVP. First provide the solution then we can make it pluggable |
|
@jackye1995 @rdblue @findepi Since you have engaged on #3543, I do appreciate your input on this PR. thanks |
88270d4 to
a8721f9
Compare
|
@findepi @gaborkaszab I have applied the suggested changes, appreciate your review on it |
|
Let's invite @nastra too who chimed in on the Slack conversation. For me in general, |
|
@gaborkaszab that's a good point and a reason for pairing the two. I.e. likely anyone wanting to use "expire after access", would also want some cap on "expire after write" as well. |
|
@nastra I would appreciate your inputs on this |
|
@blcksrx I think this is a big enough change that would be good to bring up on the DEV mailing list in order to get more opinions about whether the community wants to make the caching policy pluggable or not |
I already did that and there were no reaction yet there. engagement here were much more |
|
I must have missed the ML thread. Could you please link it here? |
|
If we want this feature, then I'm fairly confident that we are going to the right direction with the change. |
flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java
Outdated
Show resolved
Hide resolved
3dd3313 to
9c7f67f
Compare
|
@blcksrx: If we want this feature included, I recommend raising it during the community sync—the next one is scheduled for December 17—or possibly in today’s Catalog Sync. |
|
Thanks, for now we have to disable the cache to works. |
Here is the link for the calendar: https://calendar.google.com/calendar/u/0/r/month/2025/12/1?cid=MzkwNWQ0OTJmMWI0NTBiYTA3MTJmMmFlNmFmYTc2ZWI3NTdmMTNkODUyMjBjYzAzYWE0NTI3ODg1YWRjNTYyOUBncm91cC5jYWxlbmRhci5nb29nbGUuY29t It appears that the Catalog Sync was either removed or I may have made an error when checking for the next scheduled session. Sorry |
gaborkaszab
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public static final boolean CACHE_CASE_SENSITIVE_DEFAULT = true; | ||
|
|
||
| /** | ||
| * Controls policy of table cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Controls policy of tale cache expiration
| /** | ||
| * Caching Catalog | ||
| * | ||
| * @deprecated will be removed in 1.12.0; use {@link #CachingCatalog(Catalog, boolean, long, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think instead of #CachingCatalog( simply CachingCatalog( also works.
| case EXPIRE_AFTER_WRITE: | ||
| return cacheBuilder.expireAfterWrite(Duration.ofMillis(expirationIntervalMillis)).build(); | ||
| case EXPIRE_AFTER_ACCESS: | ||
| return cacheBuilder.expireAfterAccess(Duration.ofMillis(expirationIntervalMillis)).build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think this was answered to #14440 (comment)
when using "expire after access" there still should be a way to set "expire after write" in order to limit staleness of values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, you mean using both of them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Giving this a second thought I think using both could make sense. We could cover the following setup:
- Have a "longer" ExpireAfterWrite that is aligned with the credential expiration time for the table obj (e.g. half of the credential expiration). This guarantees that the table won't be kept in cache so long that the credentials expire in the meantime.
- Have a "shorter" ExpireAfterAccess together with the above so that when there is no access for the table we could evict it sooner.
I'm wondering if softValues() is also something we want to tune, @findepi . E.g. now if the engine holds a table object only as long as aa query (or maybe query planning) lasts then if we don't have overlapping queries for the same table, the above setup won't do much. The table will be evicted from cache between two queries regardless of the above setups.
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions. |
a7ba422 to
9644e64
Compare
550b466 to
2cad72d
Compare
Signed-off-by: Hossein Torabi <sayed.torabi@ing.com> Signed-off-by: Hossein Torabi <blcksrx@pm.me> Signed-off-by: Hossein Torabi <sayed.torabi@ing.com>
2cad72d to
8903e25
Compare
Add configurable catalog cache expiration policy (expire-after-access vs expire-after-write)
This change introduces a configurable expiration policy for Iceberg’s catalog-level cache, allowing users to choose between:
EXPIRE_AFTER_ACCESS(current behavior: “hot” entries may never expire in continuously-accessed workloads)EXPIRE_AFTER_WRITE(TTL from creation/write time: entries refresh periodically even if accessed frequently)It addresses the pain described in Issue #14417: long-running Spark Structured Streaming jobs that repeatedly access reference tables can keep cache entries perpetually alive under
expireAfterAccess, preventing periodic refreshes unless caching is disabled (which is expensive).Background (why this exists)
In streaming patterns like stream-to-static joins against slowly changing reference data, you often want:
With
expireAfterAccess, frequent access can prevent expiry entirely, which makes “TTL” effectively meaningless in continuous workloads. Issue #14417 proposes making cache strategy configurable (or adding a smarter refresh mechanism).What changed in this PR
✅ New catalog property:
cache.expiration-policyA new catalog property is added to choose the cache expiration strategy:
cache.expiration-policyEXPIRE_AFTER_ACCESSEXPIRE_AFTER_ACCESS,EXPIRE_AFTER_WRITE.This works alongside the existing catalog cache TTL property:
cache.expiration-interval-ms(existing) controls how long entries are cachedcache.expiration-policy(new) controls what “expiration” means (access-based vs write-based)✅
CachingCatalogsupports policy selectionCachingCatalog.wrap(...)is extended so callers can pass aCacheExpirationPolicy, enablingexpireAfterWritesemantics when requested.✅ Engines pass the policy through (Flink + Spark integration points)
Flink catalog creation is updated to parse
cache.expiration-policyand pass it intoCachingCatalog.wrap(...).The PR also touches Spark integration (
SparkCatalog.javafor Spark 3.4 / 3.5 / 4.0 are included in the file list), indicating the same policy is wired through there as well.✅ Tests cover
EXPIRE_AFTER_WRITEA test validates that with
EXPIRE_AFTER_WRITE, accessing an entry does not extend its lifetime, and it expires based on write/creation time as expected.How to use it
Spark example
Use the property under your Spark catalog config: