summaryrefslogtreecommitdiffstats
path: root/store/sqlstore/channel_store.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2018-03-05 10:35:26 -0500
committerGitHub <noreply@github.com>2018-03-05 10:35:26 -0500
commit4a1802c039a0db2d97e8351c462963a99da857bf (patch)
treef083e9cd2c21434a6eba2dca7f90c127514bf727 /store/sqlstore/channel_store.go
parentfbff94f3be1bf596f2b94f593687d3b162413de9 (diff)
downloadchat-4a1802c039a0db2d97e8351c462963a99da857bf.tar.gz
chat-4a1802c039a0db2d97e8351c462963a99da857bf.tar.bz2
chat-4a1802c039a0db2d97e8351c462963a99da857bf.zip
MM-9664 Add invalidation metrics for store caches (#8340)
* Add invalidation metrics for store caches * Increment session invalidation metric * Fix tests
Diffstat (limited to 'store/sqlstore/channel_store.go')
-rw-r--r--store/sqlstore/channel_store.go47
1 files changed, 35 insertions, 12 deletions
diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go
index 131e5649b..c6d353959 100644
--- a/store/sqlstore/channel_store.go
+++ b/store/sqlstore/channel_store.go
@@ -43,12 +43,20 @@ var allChannelMembersNotifyPropsForChannelCache = utils.NewLru(ALL_CHANNEL_MEMBE
var channelCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
var channelByNameCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
-func ClearChannelCaches() {
+func (s SqlChannelStore) ClearCaches() {
channelMemberCountsCache.Purge()
allChannelMembersForUserCache.Purge()
allChannelMembersNotifyPropsForChannelCache.Purge()
channelCache.Purge()
channelByNameCache.Purge()
+
+ if s.metrics != nil {
+ s.metrics.IncrementMemCacheInvalidationCounter("Channel Member Counts - Purge")
+ s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members for User - Purge")
+ s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members Notify Props for Channel - Purge")
+ s.metrics.IncrementMemCacheInvalidationCounter("Channel - Purge")
+ s.metrics.IncrementMemCacheInvalidationCounter("Channel By Name - Purge")
+ }
}
func NewSqlChannelStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) store.ChannelStore {
@@ -308,12 +316,18 @@ func (s SqlChannelStore) GetChannelUnread(channelId, userId string) store.StoreC
})
}
-func (us SqlChannelStore) InvalidateChannel(id string) {
+func (s SqlChannelStore) InvalidateChannel(id string) {
channelCache.Remove(id)
+ if s.metrics != nil {
+ s.metrics.IncrementMemCacheInvalidationCounter("Channel - Remove by ChannelId")
+ }
}
-func (us SqlChannelStore) InvalidateChannelByName(teamId, name string) {
+func (s SqlChannelStore) InvalidateChannelByName(teamId, name string) {
channelByNameCache.Remove(teamId + name)
+ if s.metrics != nil {
+ s.metrics.IncrementMemCacheInvalidationCounter("Channel by Name - Remove by TeamId and Name")
+ }
}
func (s SqlChannelStore) Get(id string, allowFromCache bool) store.StoreChannel {
@@ -814,14 +828,17 @@ func (s SqlChannelStore) GetMember(channelId string, userId string) store.StoreC
})
}
-func (us SqlChannelStore) InvalidateAllChannelMembersForUser(userId string) {
+func (s SqlChannelStore) InvalidateAllChannelMembersForUser(userId string) {
allChannelMembersForUserCache.Remove(userId)
+ if s.metrics != nil {
+ s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members for User - Remove by UserId")
+ }
}
-func (us SqlChannelStore) IsUserInChannelUseCache(userId string, channelId string) bool {
+func (s SqlChannelStore) IsUserInChannelUseCache(userId string, channelId string) bool {
if cacheItem, ok := allChannelMembersForUserCache.Get(userId); ok {
- if us.metrics != nil {
- us.metrics.IncrementMemCacheHitCounter("All Channel Members for User")
+ if s.metrics != nil {
+ s.metrics.IncrementMemCacheHitCounter("All Channel Members for User")
}
ids := cacheItem.(map[string]string)
if _, ok := ids[channelId]; ok {
@@ -830,12 +847,12 @@ func (us SqlChannelStore) IsUserInChannelUseCache(userId string, channelId strin
return false
}
} else {
- if us.metrics != nil {
- us.metrics.IncrementMemCacheMissCounter("All Channel Members for User")
+ if s.metrics != nil {
+ s.metrics.IncrementMemCacheMissCounter("All Channel Members for User")
}
}
- if result := <-us.GetAllChannelMembersForUser(userId, true); result.Err != nil {
+ if result := <-s.GetAllChannelMembersForUser(userId, true); result.Err != nil {
l4g.Error("SqlChannelStore.IsUserInChannelUseCache: " + result.Err.Error())
return false
} else {
@@ -915,8 +932,11 @@ func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCac
})
}
-func (us SqlChannelStore) InvalidateCacheForChannelMembersNotifyProps(channelId string) {
+func (s SqlChannelStore) InvalidateCacheForChannelMembersNotifyProps(channelId string) {
allChannelMembersNotifyPropsForChannelCache.Remove(channelId)
+ if s.metrics != nil {
+ s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members Notify Props for Channel - Remove by ChannelId")
+ }
}
type allChannelMemberNotifyProps struct {
@@ -966,8 +986,11 @@ func (s SqlChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId str
})
}
-func (us SqlChannelStore) InvalidateMemberCount(channelId string) {
+func (s SqlChannelStore) InvalidateMemberCount(channelId string) {
channelMemberCountsCache.Remove(channelId)
+ if s.metrics != nil {
+ s.metrics.IncrementMemCacheInvalidationCounter("Channel Member Counts - Remove by ChannelId")
+ }
}
func (s SqlChannelStore) GetMemberCountFromCache(channelId string) int64 {