MM-60413: Fix issues due to incorrect cache provider (#28181)
We were using a mock cache provider which mixed up LRU caches with each other. This led to incorrect unmarshalling method calls. We fix this by using the real cache provider. https://mattermost.atlassian.net/browse/MM-60413 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1909206e16
Коммит
f18323980f
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||||
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
|
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
|
||||||
"github.com/mattermost/mattermost/server/v8/channels/store/storetest"
|
"github.com/mattermost/mattermost/server/v8/channels/store/storetest"
|
||||||
|
"github.com/mattermost/mattermost/server/v8/platform/services/cache"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -108,7 +109,7 @@ func initStores(logger mlog.LoggerIFace) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
st.Store, err = NewLocalCacheLayer(st.SqlStore, nil, nil, getMockCacheProvider(), logger)
|
st.Store, err = NewLocalCacheLayer(st.SqlStore, nil, nil, cache.NewProvider(), logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,8 +84,7 @@ func (s *LocalCacheUserStore) InvalidateProfilesInChannelCacheByUser(userId stri
|
|||||||
|
|
||||||
toPass := make([]any, 0, len(keys))
|
toPass := make([]any, 0, len(keys))
|
||||||
for i := 0; i < len(keys); i++ {
|
for i := 0; i < len(keys); i++ {
|
||||||
// Note: keep https://github.com/mattermost/mattermost/pull/27830 in mind.
|
var userMap model.UserMap
|
||||||
var userMap map[string]*model.User
|
|
||||||
toPass = append(toPass, &userMap)
|
toPass = append(toPass, &userMap)
|
||||||
}
|
}
|
||||||
errs := s.rootStore.doMultiReadCache(s.rootStore.profilesInChannelCache, keys, toPass)
|
errs := s.rootStore.doMultiReadCache(s.rootStore.profilesInChannelCache, keys, toPass)
|
||||||
@@ -96,7 +95,7 @@ func (s *LocalCacheUserStore) InvalidateProfilesInChannelCacheByUser(userId stri
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
gotMap := *(toPass[i].(*map[string]*model.User))
|
gotMap := *(toPass[i].(*model.UserMap))
|
||||||
if gotMap == nil {
|
if gotMap == nil {
|
||||||
s.rootStore.logger.Warn("Found nil userMap in InvalidateProfilesInChannelCacheByUser. This is not expected")
|
s.rootStore.logger.Warn("Found nil userMap in InvalidateProfilesInChannelCacheByUser. This is not expected")
|
||||||
continue
|
continue
|
||||||
@@ -147,7 +146,7 @@ func (s *LocalCacheUserStore) GetAllProfiles(options *model.UserGetOptions) ([]*
|
|||||||
|
|
||||||
func (s *LocalCacheUserStore) GetAllProfilesInChannel(ctx context.Context, channelId string, allowFromCache bool) (map[string]*model.User, error) {
|
func (s *LocalCacheUserStore) GetAllProfilesInChannel(ctx context.Context, channelId string, allowFromCache bool) (map[string]*model.User, error) {
|
||||||
if allowFromCache {
|
if allowFromCache {
|
||||||
var cachedMap map[string]*model.User
|
var cachedMap model.UserMap
|
||||||
if err := s.rootStore.doStandardReadCache(s.rootStore.profilesInChannelCache, channelId, &cachedMap); err == nil {
|
if err := s.rootStore.doStandardReadCache(s.rootStore.profilesInChannelCache, channelId, &cachedMap); err == nil {
|
||||||
return cachedMap, nil
|
return cachedMap, nil
|
||||||
}
|
}
|
||||||
|
|||||||
5
server/platform/services/cache/lru.go
поставляемый
5
server/platform/services/cache/lru.go
поставляемый
@@ -220,11 +220,6 @@ func (l *LRU) get(key string, value any) error {
|
|||||||
_, err := u.UnmarshalMsg(val)
|
_, err := u.UnmarshalMsg(val)
|
||||||
*v = &u
|
*v = &u
|
||||||
return err
|
return err
|
||||||
case *map[string]*model.User:
|
|
||||||
var u model.UserMap
|
|
||||||
_, err := u.UnmarshalMsg(val)
|
|
||||||
*v = u
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slow path for other structs.
|
// Slow path for other structs.
|
||||||
|
|||||||
6
server/platform/services/cache/lru_test.go
поставляемый
6
server/platform/services/cache/lru_test.go
поставляемый
@@ -294,12 +294,12 @@ func TestLRUMarshalUnMarshal(t *testing.T) {
|
|||||||
u.Timezone = nil
|
u.Timezone = nil
|
||||||
require.Equal(t, user, u)
|
require.Equal(t, user, u)
|
||||||
|
|
||||||
tt := make(map[string]*model.User)
|
tt := make(model.UserMap)
|
||||||
tt["1"] = u
|
tt["1"] = u
|
||||||
err = l.SetWithDefaultExpiry("mm", model.UserMap(tt))
|
err = l.SetWithDefaultExpiry("mm", tt)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var out map[string]*model.User
|
var out model.UserMap
|
||||||
err = l.Get("mm", &out)
|
err = l.Get("mm", &out)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
out["1"].Timezone = nil
|
out["1"].Timezone = nil
|
||||||
|
|||||||
11
server/platform/services/cache/redis.go
поставляемый
11
server/platform/services/cache/redis.go
поставляемый
@@ -123,11 +123,6 @@ func (r *Redis) Get(key string, value any) error {
|
|||||||
_, err := u.UnmarshalMsg(val)
|
_, err := u.UnmarshalMsg(val)
|
||||||
*v = &u
|
*v = &u
|
||||||
return err
|
return err
|
||||||
case *map[string]*model.User:
|
|
||||||
var u model.UserMap
|
|
||||||
_, err := u.UnmarshalMsg(val)
|
|
||||||
*v = u
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slow path for other structs.
|
// Slow path for other structs.
|
||||||
@@ -193,12 +188,6 @@ func (r *Redis) GetMulti(keys []string, values []any) []error {
|
|||||||
*v = &u
|
*v = &u
|
||||||
errs[i] = err
|
errs[i] = err
|
||||||
continue
|
continue
|
||||||
case *map[string]*model.User:
|
|
||||||
var u model.UserMap
|
|
||||||
_, err := u.UnmarshalMsg(buf)
|
|
||||||
*v = u
|
|
||||||
errs[i] = err
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slow path for other structs.
|
// Slow path for other structs.
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user