[MM-31094] Replication Lag (#16888)
* MM-31094: Adds tooling to develop and test using a MySQL instance with replication lag. Adds some lazy lookups to fallback to master if results are not found. * MM-31094: Removes mysql-read-replica from default docker services. * MM-31094: Switches (store..SessionStore).Get and (store.TeamStore).GetMember to using context.Context. * MM-31094: Updates (store.UsersStore).Get to use context. * MM-31094: Updates (store.PostStore).Get to use context. * MM-31094: Removes feature flag and config setting. * MM-31094: Rolls back some master reads. * MM-31094: Rolls a non-cache read. * MM-31094: Removes feature flag from the store. * MM-31094: Removes unused constant and struct field. * MM-31094: Removes some old feature flag references. * MM-31094: Fixes some tests. * MM-31094: App layers fix. * MM-31094: Fixes mocks. * MM-31094: Don't reparse flag. * MM-31094: No reparse. * MM-31094: Removed unused FeatureFlags field. * MM-31094: Removes unnecessary feature flags variable declarations. * MM-31094: Fixes copy-paste error. * MM-31094: Fixes logical error. * MM-30194: Removes test method from store. * Revert "MM-30194: Removes test method from store." This reverts commit d5a6e8529bd5f4d993824c828e239d009b05e567. * MM-31094: Conforming to make's strange syntax. * MM-31094: Configures helper for read replica with option. * MM-31094: Adds some missing ctx's. * MM-31094: WIP * MM-31094: Updates test names. * MM-31094: WIP * MM-31094: Removes unnecessary master reads. * MM-31094: ID case changes out of scope. * MM-31094: Removes unused context. * MM-31094: Switches to a helper. Removes some var naming changes. Fixes a merge error. * MM-31094: Removes SQLITE db driver ref. * MM-31094: Layer generate fix. * MM-31094: Removes unnecessary changes. * MM-31094: Moves test method. * MM-31094: Re-add previous fix. * MM-31094: Removes make command for dev. * MM-31094: Fix for login. Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f31a9ed1a8
Коммит
58dce5930e
@@ -132,7 +132,7 @@ type SqlStore struct {
|
||||
rrCounter int64
|
||||
srCounter int64
|
||||
master *gorp.DbMap
|
||||
replicas []*gorp.DbMap
|
||||
Replicas []*gorp.DbMap
|
||||
searchReplicas []*gorp.DbMap
|
||||
stores SqlStoreStores
|
||||
settings *model.SqlSettings
|
||||
@@ -318,9 +318,9 @@ func (ss *SqlStore) initConnection() {
|
||||
ss.master = setupConnection("master", *ss.settings.DataSource, ss.settings)
|
||||
|
||||
if len(ss.settings.DataSourceReplicas) > 0 {
|
||||
ss.replicas = make([]*gorp.DbMap, len(ss.settings.DataSourceReplicas))
|
||||
ss.Replicas = make([]*gorp.DbMap, len(ss.settings.DataSourceReplicas))
|
||||
for i, replica := range ss.settings.DataSourceReplicas {
|
||||
ss.replicas[i] = setupConnection(fmt.Sprintf("replica-%v", i), replica, ss.settings)
|
||||
ss.Replicas[i] = setupConnection(fmt.Sprintf("replica-%v", i), replica, ss.settings)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,8 +395,8 @@ func (ss *SqlStore) GetReplica() *gorp.DbMap {
|
||||
return ss.GetMaster()
|
||||
}
|
||||
|
||||
rrNum := atomic.AddInt64(&ss.rrCounter, 1) % int64(len(ss.replicas))
|
||||
return ss.replicas[rrNum]
|
||||
rrNum := atomic.AddInt64(&ss.rrCounter, 1) % int64(len(ss.Replicas))
|
||||
return ss.Replicas[rrNum]
|
||||
}
|
||||
|
||||
func (ss *SqlStore) TotalMasterDbConnections() int {
|
||||
@@ -409,7 +409,7 @@ func (ss *SqlStore) TotalReadDbConnections() int {
|
||||
}
|
||||
|
||||
count := 0
|
||||
for _, db := range ss.replicas {
|
||||
for _, db := range ss.Replicas {
|
||||
count = count + db.Db.Stats().OpenConnections
|
||||
}
|
||||
|
||||
@@ -1008,9 +1008,9 @@ func IsUniqueConstraintError(err error, indexName []string) bool {
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetAllConns() []*gorp.DbMap {
|
||||
all := make([]*gorp.DbMap, len(ss.replicas)+1)
|
||||
copy(all, ss.replicas)
|
||||
all[len(ss.replicas)] = ss.master
|
||||
all := make([]*gorp.DbMap, len(ss.Replicas)+1)
|
||||
copy(all, ss.Replicas)
|
||||
all[len(ss.Replicas)] = ss.master
|
||||
return all
|
||||
}
|
||||
|
||||
@@ -1033,7 +1033,7 @@ func (ss *SqlStore) RecycleDBConnections(d time.Duration) {
|
||||
|
||||
func (ss *SqlStore) Close() {
|
||||
ss.master.Db.Close()
|
||||
for _, replica := range ss.replicas {
|
||||
for _, replica := range ss.Replicas {
|
||||
replica.Db.Close()
|
||||
}
|
||||
|
||||
@@ -1210,6 +1210,10 @@ func (ss *SqlStore) UpdateLicense(license *model.License) {
|
||||
ss.license = license
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetLicense() *model.License {
|
||||
return ss.license
|
||||
}
|
||||
|
||||
func (ss *SqlStore) migrate(direction migrationDirection) error {
|
||||
var driver database.Driver
|
||||
var err error
|
||||
|
||||
Ссылка в новой задаче
Block a user