PLT-6355: Use separate Read Replicas for Search. (#6216)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
5ab7726c1e
Коммит
597641545d
@@ -66,33 +66,36 @@ const (
|
||||
)
|
||||
|
||||
type SqlStore struct {
|
||||
master *gorp.DbMap
|
||||
replicas []*gorp.DbMap
|
||||
team TeamStore
|
||||
channel ChannelStore
|
||||
post PostStore
|
||||
user UserStore
|
||||
audit AuditStore
|
||||
compliance ComplianceStore
|
||||
session SessionStore
|
||||
oauth OAuthStore
|
||||
system SystemStore
|
||||
webhook WebhookStore
|
||||
command CommandStore
|
||||
preference PreferenceStore
|
||||
license LicenseStore
|
||||
token TokenStore
|
||||
emoji EmojiStore
|
||||
status StatusStore
|
||||
fileInfo FileInfoStore
|
||||
reaction ReactionStore
|
||||
SchemaVersion string
|
||||
rrCounter int64
|
||||
master *gorp.DbMap
|
||||
replicas []*gorp.DbMap
|
||||
searchReplicas []*gorp.DbMap
|
||||
team TeamStore
|
||||
channel ChannelStore
|
||||
post PostStore
|
||||
user UserStore
|
||||
audit AuditStore
|
||||
compliance ComplianceStore
|
||||
session SessionStore
|
||||
oauth OAuthStore
|
||||
system SystemStore
|
||||
webhook WebhookStore
|
||||
command CommandStore
|
||||
preference PreferenceStore
|
||||
license LicenseStore
|
||||
token TokenStore
|
||||
emoji EmojiStore
|
||||
status StatusStore
|
||||
fileInfo FileInfoStore
|
||||
reaction ReactionStore
|
||||
SchemaVersion string
|
||||
rrCounter int64
|
||||
srCounter int64
|
||||
}
|
||||
|
||||
func initConnection() *SqlStore {
|
||||
sqlStore := &SqlStore{
|
||||
rrCounter: 0,
|
||||
srCounter: 0,
|
||||
}
|
||||
|
||||
sqlStore.master = setupConnection("master", utils.Cfg.SqlSettings.DriverName,
|
||||
@@ -111,6 +114,17 @@ func initConnection() *SqlStore {
|
||||
}
|
||||
}
|
||||
|
||||
if len(utils.Cfg.SqlSettings.DataSourceSearchReplicas) == 0 {
|
||||
sqlStore.searchReplicas = sqlStore.replicas
|
||||
} else {
|
||||
sqlStore.searchReplicas = make([]*gorp.DbMap, len(utils.Cfg.SqlSettings.DataSourceSearchReplicas))
|
||||
for i, replica := range utils.Cfg.SqlSettings.DataSourceSearchReplicas {
|
||||
sqlStore.searchReplicas[i] = setupConnection(fmt.Sprintf("search-replica-%v", i), utils.Cfg.SqlSettings.DriverName, replica,
|
||||
utils.Cfg.SqlSettings.MaxIdleConns, utils.Cfg.SqlSettings.MaxOpenConns,
|
||||
utils.Cfg.SqlSettings.Trace)
|
||||
}
|
||||
}
|
||||
|
||||
sqlStore.SchemaVersion = sqlStore.GetCurrentSchemaVersion()
|
||||
return sqlStore
|
||||
}
|
||||
@@ -231,6 +245,19 @@ func (ss *SqlStore) TotalReadDbConnections() int {
|
||||
return count
|
||||
}
|
||||
|
||||
func (ss *SqlStore) TotalSearchDbConnections() int {
|
||||
if len(utils.Cfg.SqlSettings.DataSourceSearchReplicas) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
count := 0
|
||||
for _, db := range ss.searchReplicas {
|
||||
count = count + db.Db.Stats().OpenConnections
|
||||
}
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetCurrentSchemaVersion() string {
|
||||
version, _ := ss.GetMaster().SelectStr("SELECT Value FROM Systems WHERE Name='Version'")
|
||||
return version
|
||||
@@ -611,6 +638,11 @@ func (ss *SqlStore) GetMaster() *gorp.DbMap {
|
||||
return ss.master
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetSearchReplica() *gorp.DbMap {
|
||||
rrNum := atomic.AddInt64(&ss.srCounter, 1) % int64(len(ss.searchReplicas))
|
||||
return ss.searchReplicas[rrNum]
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetReplica() *gorp.DbMap {
|
||||
rrNum := atomic.AddInt64(&ss.rrCounter, 1) % int64(len(ss.replicas))
|
||||
return ss.replicas[rrNum]
|
||||
|
||||
Ссылка в новой задаче
Block a user