MM-11886: materialize channel search (#9349)
* materialize PublicChannels table Introduce triggers for each supported database that automatically maintain a subset of the Channels table corresponding to only public channels. This improves corresponding queries that no longer need to filter out 99% DM channels. This initial commit modifies the channel store directly for easier code reviewing, but the next wraps an experimental version around it to enable a kill switch in case there are unforeseen performance regressions. This addresses [MM-11886](https://mattermost.atlassian.net/browse/MM-11886) and [MM-11945](https://mattermost.atlassian.net/browse/MM-11945). * extract the experimental public channels materialization Wrap the original channel store with an experimental version that leverages the materialized public channels, but can be disabled to fallback to the original implementation. This addresses MM-11947. * s/ExperimentalPublicChannelsMaterialization/EnablePublicChannelsMaterialization/ * simplify error handling * move experimental config listener until after store is initialized
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0a5f792d2d
Коммит
8b17bf9e42
@@ -33,6 +33,7 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
EXIT_GENERIC_FAILURE = 1
|
||||
EXIT_CREATE_TABLE = 100
|
||||
EXIT_DB_OPEN = 101
|
||||
EXIT_PING = 102
|
||||
@@ -116,8 +117,13 @@ func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInter
|
||||
|
||||
supplier.initConnection()
|
||||
|
||||
enableExperimentalPublicChannelsMaterialization := true
|
||||
if settings.EnablePublicChannelsMaterialization != nil && !*settings.EnablePublicChannelsMaterialization {
|
||||
enableExperimentalPublicChannelsMaterialization = false
|
||||
}
|
||||
|
||||
supplier.oldStores.team = NewSqlTeamStore(supplier)
|
||||
supplier.oldStores.channel = NewSqlChannelStore(supplier, metrics)
|
||||
supplier.oldStores.channel = NewSqlChannelStoreExperimental(supplier, metrics, enableExperimentalPublicChannelsMaterialization)
|
||||
supplier.oldStores.post = NewSqlPostStore(supplier, metrics)
|
||||
supplier.oldStores.user = NewSqlUserStore(supplier, metrics)
|
||||
supplier.oldStores.audit = NewSqlAuditStore(supplier)
|
||||
@@ -151,10 +157,19 @@ func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInter
|
||||
os.Exit(EXIT_CREATE_TABLE)
|
||||
}
|
||||
|
||||
// This store's triggers should exist before the migration is run to ensure the
|
||||
// corresponding tables stay in sync. Whether or not a trigger should be created before
|
||||
// or after a migration is likely to be decided on a case-by-case basis.
|
||||
if err := supplier.oldStores.channel.(*SqlChannelStoreExperimental).CreateTriggersIfNotExists(); err != nil {
|
||||
mlog.Critical("Error creating triggers", mlog.Err(err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
}
|
||||
|
||||
UpgradeDatabase(supplier)
|
||||
|
||||
supplier.oldStores.team.(*SqlTeamStore).CreateIndexesIfNotExists()
|
||||
supplier.oldStores.channel.(*SqlChannelStore).CreateIndexesIfNotExists()
|
||||
supplier.oldStores.channel.(*SqlChannelStoreExperimental).CreateIndexesIfNotExists()
|
||||
supplier.oldStores.post.(*SqlPostStore).CreateIndexesIfNotExists()
|
||||
supplier.oldStores.user.(*SqlUserStore).CreateIndexesIfNotExists()
|
||||
supplier.oldStores.audit.(*SqlAuditStore).CreateIndexesIfNotExists()
|
||||
@@ -461,6 +476,52 @@ func (ss *SqlSupplier) DoesColumnExist(tableName string, columnName string) bool
|
||||
}
|
||||
}
|
||||
|
||||
func (ss *SqlSupplier) DoesTriggerExist(triggerName string) bool {
|
||||
if ss.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||
count, err := ss.GetMaster().SelectInt(`
|
||||
SELECT
|
||||
COUNT(0)
|
||||
FROM
|
||||
pg_trigger
|
||||
WHERE
|
||||
tgname = $1
|
||||
`, triggerName)
|
||||
|
||||
if err != nil {
|
||||
mlog.Critical(fmt.Sprintf("Failed to check if trigger exists %v", err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
|
||||
} else if ss.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
||||
count, err := ss.GetMaster().SelectInt(`
|
||||
SELECT
|
||||
COUNT(0)
|
||||
FROM
|
||||
information_schema.triggers
|
||||
WHERE
|
||||
trigger_schema = DATABASE()
|
||||
AND trigger_name = ?
|
||||
`, triggerName)
|
||||
|
||||
if err != nil {
|
||||
mlog.Critical(fmt.Sprintf("Failed to check if trigger exists %v", err))
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
}
|
||||
|
||||
return count > 0
|
||||
|
||||
} else {
|
||||
mlog.Critical("Failed to check if column exists because of missing driver")
|
||||
time.Sleep(time.Second)
|
||||
os.Exit(EXIT_GENERIC_FAILURE)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (ss *SqlSupplier) CreateColumnIfNotExists(tableName string, columnName string, mySqlColType string, postgresColType string, defaultValue string) bool {
|
||||
|
||||
if ss.DoesColumnExist(tableName, columnName) {
|
||||
|
||||
Ссылка в новой задаче
Block a user