-
Notifications
You must be signed in to change notification settings - Fork 833
Add hot-swap capability between count-based and size-based cache modes #6809
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
Add hot-swap capability between count-based and size-based cache modes #6809
Conversation
} | ||
cache.sizeByKey = make(map[interface{}]uint64, opts.InitialCapacity) | ||
if opts.IsSizeBased == nil { | ||
cache.isSizeBased = dynamicproperties.GetBoolPropertyFn(false) |
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 prefer to panic in this case. I'd like to have the behavior of cache to be completely managed by dynamic config. These implicit logic can make it hard to debug
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 want to add the panic logic later once we add feature flags for all the cache usages. For now, existing usage will be default to count based.
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'd avoid panic'ing in library level and instead return an error for missing mandatory options
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.
Thanks, I will add the error returning and make this into a mandatory flag once we add the feature flags for all other cache usage.
} | ||
cache.sizeByKey = make(map[interface{}]uint64, opts.InitialCapacity) | ||
if opts.IsSizeBased == nil { | ||
cache.isSizeBased = dynamicproperties.GetBoolPropertyFn(false) |
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'd avoid panic'ing in library level and instead return an error for missing mandatory options
if c.isSizeBased() { | ||
if valueSize > uint64(c.maxSize()) { | ||
// value is too big to be cached, we also don't want to evict everyone else | ||
return nil, ErrEntryTooBig |
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.
This is a good idea but we may need to update callers to work without caching for big workflow executions. Otherwise they will be stuck because caching the workflow execution is mandatory to process the workflow.
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, this is similar to when the cache is full of pinned elements and can't evict or add new entries. One way I can think of is to avoid that is by setting a minimum cache size that fits any workflow execution—for example, 50MB if the limit is 30MB.
I'll add a comment to cover this edge case in the cache usage logic.
What changed?
This PR introduces a hot-swap capability between count-based and size-based cache modes in the LRU cache implementation. The key changes include:
Why?
The current implementation requires a complete cache restart when switching between count-based and size-based modes, which:
This change enables smooth transitions between modes while maintaining cache contents, improving system stability and performance.
How did you test it?
I tested the logic with unit test and local testing.
Potential risks
Since it's the base cache, it could break every part that used this cache if there was a bug hidden. We need to rollback immediately if such things happens.
Release notes
Documentation Changes