Disable read/search db replicas in TE/E0 (#14400)
* Disable read/search db replicas in TE/E0 * fixing tests * Removing unnecesary text. * Updating without-license read-replicas config before store initialization * Reconnecting to database after remove read replicas
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
37f43a7094
Коммит
ef5ac519d9
@@ -41,6 +41,7 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v5/services/timezones"
|
||||
"github.com/mattermost/mattermost-server/v5/services/tracing"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/mattermost/mattermost-server/v5/store/sqlstore"
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
)
|
||||
|
||||
@@ -48,6 +49,7 @@ var MaxNotificationsPerChannelDefault int64 = 1000000
|
||||
|
||||
type Server struct {
|
||||
Store store.Store
|
||||
sqlStore *sqlstore.SqlSupplier
|
||||
WebSocketRouter *WebSocketRouter
|
||||
|
||||
// RootRouter is the starting point for all HTTP requests to the server.
|
||||
@@ -276,11 +278,22 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
|
||||
license := s.License()
|
||||
|
||||
if license == nil && len(s.Config().SqlSettings.DataSourceReplicas) > 1 {
|
||||
mlog.Warn("More than 1 read replica functionality disabled by current license. Please contact your system administrator about upgrading your enterprise license.")
|
||||
if license == nil && len(s.Config().SqlSettings.DataSourceReplicas) > 0 {
|
||||
mlog.Warn("Read replicas functionality disabled by current license. Please contact your system administrator about upgrading your enterprise license.")
|
||||
s.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.SqlSettings.DataSourceReplicas = cfg.SqlSettings.DataSourceReplicas[:1]
|
||||
cfg.SqlSettings.DataSourceReplicas = []string{}
|
||||
})
|
||||
s.Store.Close()
|
||||
s.Store = s.newStore()
|
||||
}
|
||||
|
||||
if license == nil && len(s.Config().SqlSettings.DataSourceSearchReplicas) > 0 {
|
||||
mlog.Warn("Search replicas functionality disabled by current license. Please contact your system administrator about upgrading your enterprise license.")
|
||||
s.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.SqlSettings.DataSourceSearchReplicas = []string{}
|
||||
})
|
||||
s.Store.Close()
|
||||
s.Store = s.newStore()
|
||||
}
|
||||
|
||||
if license == nil {
|
||||
|
||||
@@ -61,10 +61,11 @@ func (s *Server) RunOldAppInitialization() error {
|
||||
|
||||
if s.newStore == nil {
|
||||
s.newStore = func() store.Store {
|
||||
s.sqlStore = sqlstore.NewSqlSupplier(s.Config().SqlSettings, s.Metrics)
|
||||
return store.NewTimerLayer(
|
||||
searchlayer.NewSearchLayer(
|
||||
localcachelayer.NewLocalCacheLayer(
|
||||
sqlstore.NewSqlSupplier(s.Config().SqlSettings, s.Metrics),
|
||||
s.sqlStore,
|
||||
s.Metrics,
|
||||
s.Cluster,
|
||||
s.CacheProvider,
|
||||
|
||||
@@ -6,7 +6,6 @@ package app
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/tls"
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -16,6 +15,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/config"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/utils/fileutils"
|
||||
@@ -36,6 +37,66 @@ func TestStartServerSuccess(t *testing.T) {
|
||||
require.NoError(t, serverErr)
|
||||
}
|
||||
|
||||
func TestReadReplicaDisabledBasedOnLicense(t *testing.T) {
|
||||
t.Run("Read Replicas with no License", func(t *testing.T) {
|
||||
s, err := NewServer(func(server *Server) error {
|
||||
configStore, _ := config.NewFileStore("config.json", true)
|
||||
server.configStore = configStore
|
||||
server.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.SqlSettings.DataSourceReplicas = []string{*cfg.SqlSettings.DataSource}
|
||||
})
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, s.sqlStore.GetMaster(), s.sqlStore.GetReplica())
|
||||
require.Len(t, s.Config().SqlSettings.DataSourceReplicas, 0)
|
||||
})
|
||||
|
||||
t.Run("Read Replicas With License", func(t *testing.T) {
|
||||
s, err := NewServer(func(server *Server) error {
|
||||
configStore, _ := config.NewFileStore("config.json", true)
|
||||
server.configStore = configStore
|
||||
server.licenseValue.Store(model.NewTestLicense())
|
||||
server.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.SqlSettings.DataSourceReplicas = []string{*cfg.SqlSettings.DataSource}
|
||||
})
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, s.sqlStore.GetMaster(), s.sqlStore.GetReplica())
|
||||
require.Len(t, s.Config().SqlSettings.DataSourceReplicas, 1)
|
||||
})
|
||||
|
||||
t.Run("Search Replicas with no License", func(t *testing.T) {
|
||||
s, err := NewServer(func(server *Server) error {
|
||||
configStore, _ := config.NewFileStore("config.json", true)
|
||||
server.configStore = configStore
|
||||
server.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.SqlSettings.DataSourceSearchReplicas = []string{*cfg.SqlSettings.DataSource}
|
||||
})
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, s.sqlStore.GetMaster(), s.sqlStore.GetSearchReplica())
|
||||
require.Len(t, s.Config().SqlSettings.DataSourceSearchReplicas, 0)
|
||||
})
|
||||
|
||||
t.Run("Search Replicas With License", func(t *testing.T) {
|
||||
s, err := NewServer(func(server *Server) error {
|
||||
configStore, _ := config.NewFileStore("config.json", true)
|
||||
server.configStore = configStore
|
||||
server.licenseValue.Store(model.NewTestLicense())
|
||||
server.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.SqlSettings.DataSourceSearchReplicas = []string{*cfg.SqlSettings.DataSource}
|
||||
})
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, s.sqlStore.GetMaster(), s.sqlStore.GetSearchReplica())
|
||||
require.Len(t, s.Config().SqlSettings.DataSourceSearchReplicas, 1)
|
||||
})
|
||||
}
|
||||
|
||||
func TestStartServerRateLimiterCriticalError(t *testing.T) {
|
||||
// Attempt to use Rate Limiter with an invalid config
|
||||
ms, err := config.NewMemoryStoreWithOptions(&config.MemoryStoreOptions{
|
||||
|
||||
Ссылка в новой задаче
Block a user