-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
refactor: optimize argocd-application-controller redis usage #5345
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cache | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// NewTwoLevelClient creates cache client that proxies requests to given external cache and tries to minimize | ||
// number of requests to external client by storing cache entries in local in-memory cache. | ||
func NewTwoLevelClient(client CacheClient, inMemoryExpiration time.Duration) *twoLevelClient { | ||
return &twoLevelClient{inMemoryCache: NewInMemoryCache(inMemoryExpiration), externalCache: client} | ||
} | ||
|
||
type twoLevelClient struct { | ||
inMemoryCache *InMemoryCache | ||
externalCache CacheClient | ||
} | ||
|
||
// Set stores the given value in both in-memory and external cache. | ||
// Skip storing the value in external cache if the same value already exists in memory to avoid requesting external cache. | ||
func (c *twoLevelClient) Set(item *Item) error { | ||
has, err := c.inMemoryCache.HasSame(item.Key, item.Object) | ||
if has { | ||
return nil | ||
} | ||
if err != nil { | ||
log.Warnf("Failed to check key '%s' in in-memory cache: %v", item.Key, err) | ||
} | ||
err = c.inMemoryCache.Set(item) | ||
if err != nil { | ||
log.Warnf("Failed to save key '%s' in in-memory cache: %v", item.Key, err) | ||
} | ||
return c.externalCache.Set(item) | ||
} | ||
|
||
// Get returns cache value from in-memory cache if it present. Otherwise loads it from external cache and persists | ||
// in memory to avoid future requests to external cache. | ||
func (c *twoLevelClient) Get(key string, obj interface{}) error { | ||
err := c.inMemoryCache.Get(key, obj) | ||
if err == nil { | ||
return nil | ||
} | ||
|
||
err = c.externalCache.Get(key, obj) | ||
if err == nil { | ||
_ = c.inMemoryCache.Set(&Item{Key: key, Object: obj}) | ||
} | ||
return err | ||
} | ||
|
||
// Delete deletes cache for given key in both in-memory and external cache. | ||
func (c *twoLevelClient) Delete(key string) error { | ||
err := c.inMemoryCache.Delete(key) | ||
if err != nil { | ||
return err | ||
} | ||
return c.externalCache.Delete(key) | ||
} | ||
|
||
func (c *twoLevelClient) OnUpdated(ctx context.Context, key string, callback func() error) error { | ||
return c.externalCache.OnUpdated(ctx, key, callback) | ||
} | ||
|
||
func (c *twoLevelClient) NotifyUpdated(key string) error { | ||
return c.externalCache.NotifyUpdated(key) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this a bug fix?
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.
Oh, yes. It appears that UI might break if pod appears before the parent resource in
ApplicationTree.Nodes
list. After introducing node sorting in backend this reproduces consistently.