MM-25238: Fix system ping check to read from master (#14580)

The code was writing to master and immediately after that reading
from a replica causing it to fail intermittently.

Since this is not a very high-traffic table, it should be safe to read
from master always.
Этот коммит содержится в:
Agniva De Sarker
2020-05-15 14:19:46 +05:30
коммит произвёл GitHub
родитель 76ed77663a
Коммит 21af1f49f1
2 изменённых файлов: 6 добавлений и 6 удалений

Просмотреть файл

@@ -86,23 +86,23 @@ func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
Value: currentTime,
})
if writeErr != nil {
mlog.Debug("Unable to write to database.", mlog.Err(writeErr))
mlog.Warn("Unable to write to database.", mlog.Err(writeErr))
s[dbStatusKey] = model.STATUS_UNHEALTHY
s[model.STATUS] = model.STATUS_UNHEALTHY
} else {
healthCheck, readErr := c.App.Srv().Store.System().GetByName(healthCheckKey)
if readErr != nil {
mlog.Debug("Unable to read from database.", mlog.Err(readErr))
mlog.Warn("Unable to read from database.", mlog.Err(readErr))
s[dbStatusKey] = model.STATUS_UNHEALTHY
s[model.STATUS] = model.STATUS_UNHEALTHY
} else if healthCheck.Value != currentTime {
mlog.Debug("Incorrect healthcheck value", mlog.String("expected", currentTime), mlog.String("got", healthCheck.Value))
mlog.Warn("Incorrect healthcheck value", mlog.String("expected", currentTime), mlog.String("got", healthCheck.Value))
s[dbStatusKey] = model.STATUS_UNHEALTHY
s[model.STATUS] = model.STATUS_UNHEALTHY
}
_, writeErr = c.App.Srv().Store.System().PermanentDeleteByName(healthCheckKey)
if writeErr != nil {
mlog.Debug("Unable to remove ping health check value from database", mlog.Err(writeErr))
mlog.Warn("Unable to remove ping health check value from database", mlog.Err(writeErr))
s[dbStatusKey] = model.STATUS_UNHEALTHY
s[model.STATUS] = model.STATUS_UNHEALTHY
}

Просмотреть файл

@@ -37,7 +37,7 @@ func (s SqlSystemStore) Save(system *model.System) *model.AppError {
}
func (s SqlSystemStore) SaveOrUpdate(system *model.System) *model.AppError {
if err := s.GetReplica().SelectOne(&model.System{}, "SELECT * FROM Systems WHERE Name = :Name", map[string]interface{}{"Name": system.Name}); err == nil {
if err := s.GetMaster().SelectOne(&model.System{}, "SELECT * FROM Systems WHERE Name = :Name", map[string]interface{}{"Name": system.Name}); err == nil {
if _, err := s.GetMaster().Update(system); err != nil {
return model.NewAppError("SqlSystemStore.SaveOrUpdate", "store.sql_system.update.app_error", nil, err.Error(), http.StatusInternalServerError)
}
@@ -71,7 +71,7 @@ func (s SqlSystemStore) Get() (model.StringMap, *model.AppError) {
func (s SqlSystemStore) GetByName(name string) (*model.System, *model.AppError) {
var system model.System
if err := s.GetReplica().SelectOne(&system, "SELECT * FROM Systems WHERE Name = :Name", map[string]interface{}{"Name": name}); err != nil {
if err := s.GetMaster().SelectOne(&system, "SELECT * FROM Systems WHERE Name = :Name", map[string]interface{}{"Name": name}); err != nil {
return nil, model.NewAppError("SqlSystemStore.GetByName", "store.sql_system.get_by_name.app_error", nil, err.Error(), http.StatusInternalServerError)
}