[MM-44329] Add a method to store.Store interface to get sql.DB object (#20351)
* [MM-44329] Added methods to sqlstore.Store * [MM-44329] Added methods to the store.Store interface * [MM-44329] Regenerated mocks * [MM-44329] Added comments for the store.Store interface Co-authored-by: Tim Scheuermann <tim.scheuermann@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8f912b697e
Коммит
f836826c1d
@@ -381,11 +381,12 @@ func (ss *SqlStore) SetMasterX(db *sql.DB) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetInternalMasterDB() *sql.DB {
|
||||
return ss.GetMasterX().DB.DB
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetSearchReplicaX() *sqlxDBWrapper {
|
||||
ss.licenseMutex.RLock()
|
||||
license := ss.license
|
||||
ss.licenseMutex.RUnlock()
|
||||
if license == nil {
|
||||
if !ss.hasLicense() {
|
||||
return ss.GetMasterX()
|
||||
}
|
||||
|
||||
@@ -398,10 +399,7 @@ func (ss *SqlStore) GetSearchReplicaX() *sqlxDBWrapper {
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetReplicaX() *sqlxDBWrapper {
|
||||
ss.licenseMutex.RLock()
|
||||
license := ss.license
|
||||
ss.licenseMutex.RUnlock()
|
||||
if len(ss.settings.DataSourceReplicas) == 0 || ss.lockedToMaster || license == nil {
|
||||
if len(ss.settings.DataSourceReplicas) == 0 || ss.lockedToMaster || !ss.hasLicense() {
|
||||
return ss.GetMasterX()
|
||||
}
|
||||
|
||||
@@ -409,6 +407,21 @@ func (ss *SqlStore) GetReplicaX() *sqlxDBWrapper {
|
||||
return ss.ReplicaXs[rrNum]
|
||||
}
|
||||
|
||||
func (ss *SqlStore) GetInternalReplicaDBs() []*sql.DB {
|
||||
if len(ss.settings.DataSourceReplicas) == 0 || ss.lockedToMaster || !ss.hasLicense() {
|
||||
return []*sql.DB{
|
||||
ss.GetMasterX().DB.DB,
|
||||
}
|
||||
}
|
||||
|
||||
dbs := make([]*sql.DB, len(ss.ReplicaXs))
|
||||
for i, rx := range ss.ReplicaXs {
|
||||
dbs[i] = rx.DB.DB
|
||||
}
|
||||
|
||||
return dbs
|
||||
}
|
||||
|
||||
func (ss *SqlStore) TotalMasterDbConnections() int {
|
||||
return ss.GetMasterX().Stats().OpenConnections
|
||||
}
|
||||
@@ -946,6 +959,14 @@ func (ss *SqlStore) GetLicense() *model.License {
|
||||
return ss.license
|
||||
}
|
||||
|
||||
func (ss *SqlStore) hasLicense() bool {
|
||||
ss.licenseMutex.Lock()
|
||||
hasLicense := ss.license != nil
|
||||
ss.licenseMutex.Unlock()
|
||||
|
||||
return hasLicense
|
||||
}
|
||||
|
||||
func (ss *SqlStore) migrate(direction migrationDirection) error {
|
||||
assets := db.Assets()
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user