|
| 1 | +// replication-manager - Replication Manager Monitoring and CLI for MariaDB and MySQL |
| 2 | +// Copyright 2017 Signal 18 Cloud SAS |
| 3 | +// Authors: Guillaume Lefranc <[email protected]> |
| 4 | +// Stephane Varoqui <[email protected]> |
| 5 | +// This source code is licensed under the GNU General Public License, version 3. |
| 6 | + |
| 7 | +package cluster |
| 8 | + |
| 9 | +import ( |
| 10 | + "errors" |
| 11 | + |
| 12 | + "github.com/signal18/replication-manager/utils/dbhelper" |
| 13 | +) |
| 14 | + |
| 15 | +func (cluster *Cluster) JobAnalyzeSQL() error { |
| 16 | + var err error |
| 17 | + var logs string |
| 18 | + server := cluster.master |
| 19 | + |
| 20 | + if server == nil { |
| 21 | + cluster.LogPrintf(LvlInfo, "Analyze tables cancel as no leader ") |
| 22 | + return errors.New("Analyze tables cancel as no leader") |
| 23 | + } |
| 24 | + if !cluster.Conf.MonitorSchemaChange { |
| 25 | + cluster.LogPrintf(LvlInfo, "Analyze tables cancel no schema monitor in config") |
| 26 | + return errors.New("Analyze tables cancel no schema monitor in config") |
| 27 | + } |
| 28 | + if cluster.inAnalyzeTables { |
| 29 | + cluster.LogPrintf(LvlInfo, "Analyze tables cancel already running") |
| 30 | + return errors.New("Analyze tables cancel already running") |
| 31 | + } |
| 32 | + if cluster.master.Tables == nil { |
| 33 | + cluster.LogPrintf(LvlInfo, "Analyze tables cancel no table list") |
| 34 | + return errors.New("Analyze tables cancel no table list") |
| 35 | + } |
| 36 | + cluster.inAnalyzeTables = true |
| 37 | + defer func() { |
| 38 | + cluster.inAnalyzeTables = false |
| 39 | + }() |
| 40 | + for _, t := range cluster.master.Tables { |
| 41 | + |
| 42 | + // for _, s := range cluster.slaves { |
| 43 | + logs, err = dbhelper.AnalyzeTable(server.Conn, server.DBVersion, t.TableSchema+"."+t.TableName) |
| 44 | + cluster.LogSQL(logs, err, server.URL, "Monitor", LvlErr, "Could not get database variables %s %s", server.URL, err) |
| 45 | + |
| 46 | + // cluster.LogPrintf(LvlInfo, "Analyse table %s on %s", t, s.URL) |
| 47 | + // } |
| 48 | + } |
| 49 | + return err |
| 50 | +} |
0 commit comments