From 936540ea587631d63fe2c2e77458f212156c1b2c Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Mon, 15 Mar 2021 19:51:49 +0530 Subject: [PATCH] MM-33789: Revert fallback to master for GetAllProfilesInChannel (#17119) * MM-33789: Revert fallback to master for GetAllProfilesInChannel This fixes a regression introduced in https://github.com/mattermost/mattermost-server/pull/16911. It was causing problems with too many invalidations and overloading the writer instance for big installations. Reverting this does not affect correctness at all because it was done out of abundance of caution and the idea at that point was it was to be done for all caches. https://mattermost.atlassian.net/browse/MM-33789 ```release-note NONE ``` * fix gofmt issues --- store/localcachelayer/layer.go | 7 +++---- store/localcachelayer/user_layer.go | 26 +++----------------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/store/localcachelayer/layer.go b/store/localcachelayer/layer.go index 513837778b..7bc26eac6b 100644 --- a/store/localcachelayer/layer.go +++ b/store/localcachelayer/layer.go @@ -289,10 +289,9 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf return } localCacheStore.user = &LocalCacheUserStore{ - UserStore: baseStore.User(), - rootStore: &localCacheStore, - userProfileByIdsInvalidations: make(map[string]bool), - profilesInChannelInvalidations: make(map[string]bool), + UserStore: baseStore.User(), + rootStore: &localCacheStore, + userProfileByIdsInvalidations: make(map[string]bool), } // Teams diff --git a/store/localcachelayer/user_layer.go b/store/localcachelayer/user_layer.go index 1a19b66aa6..1fac2cf2f1 100644 --- a/store/localcachelayer/user_layer.go +++ b/store/localcachelayer/user_layer.go @@ -15,11 +15,9 @@ import ( type LocalCacheUserStore struct { store.UserStore - rootStore *LocalCacheStore - userProfileByIdsMut sync.Mutex - userProfileByIdsInvalidations map[string]bool - profilesInChannelMut sync.Mutex - profilesInChannelInvalidations map[string]bool + rootStore *LocalCacheStore + userProfileByIdsMut sync.Mutex + userProfileByIdsInvalidations map[string]bool } func (s *LocalCacheUserStore) handleClusterInvalidateScheme(msg *model.ClusterMessage) { @@ -37,9 +35,6 @@ func (s *LocalCacheUserStore) handleClusterInvalidateProfilesInChannel(msg *mode if msg.Data == ClearCacheMessageData { s.rootStore.profilesInChannelCache.Purge() } else { - s.profilesInChannelMut.Lock() - s.profilesInChannelInvalidations[msg.Data] = true - s.profilesInChannelMut.Unlock() s.rootStore.profilesInChannelCache.Remove(msg.Data) } } @@ -72,9 +67,6 @@ func (s *LocalCacheUserStore) InvalidateProfilesInChannelCacheByUser(userId stri var userMap map[string]*model.User if err = s.rootStore.profilesInChannelCache.Get(key, &userMap); err == nil { if _, userInCache := userMap[userId]; userInCache { - s.profilesInChannelMut.Lock() - s.profilesInChannelInvalidations[key] = true - s.profilesInChannelMut.Unlock() s.rootStore.doInvalidateCacheCluster(s.rootStore.profilesInChannelCache, key) if s.rootStore.metrics != nil { s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Profiles in Channel - Remove by User") @@ -86,9 +78,6 @@ func (s *LocalCacheUserStore) InvalidateProfilesInChannelCacheByUser(userId stri } func (s *LocalCacheUserStore) InvalidateProfilesInChannelCache(channelID string) { - s.profilesInChannelMut.Lock() - s.profilesInChannelInvalidations[channelID] = true - s.profilesInChannelMut.Unlock() s.rootStore.doInvalidateCacheCluster(s.rootStore.profilesInChannelCache, channelID) if s.rootStore.metrics != nil { s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Profiles in Channel - Remove by Channel") @@ -103,15 +92,6 @@ func (s *LocalCacheUserStore) GetAllProfilesInChannel(ctx context.Context, chann } } - // If it was invalidated, then we need to query master. - s.profilesInChannelMut.Lock() - if s.profilesInChannelInvalidations[channelId] { - ctx = sqlstore.WithMaster(ctx) - // And then remove the key from the map. - delete(s.profilesInChannelInvalidations, channelId) - } - s.profilesInChannelMut.Unlock() - userMap, err := s.UserStore.GetAllProfilesInChannel(ctx, channelId, allowFromCache) if err != nil { return nil, err