1 package setup_instruments
7 "github.com/sjmudd/pstop/lib"
10 // Error 1142: UPDATE command denied to user
11 // Error 1290: The MySQL server is running with the --read-only option so it cannot execute this statement
12 var EXPECTED_UPDATE_ERRORS = []string { "Error 1142", "Error 1290" }
14 type setup_instruments_row struct {
20 type SetupInstruments struct {
22 rows []setup_instruments_row
25 // Change settings to monitor wait/synch/mutex/%
26 func (si *SetupInstruments) EnableMutexMonitoring(dbh *sql.DB) {
27 si.rows = make([]setup_instruments_row, 0, 100)
29 // populate the rows which are not set
30 sql := "SELECT NAME, ENABLED, TIMED FROM setup_instruments WHERE NAME LIKE 'wait/synch/mutex/%' AND ( enabled <> 'YES' OR timed <> 'YES' )"
32 lib.Logger.Println("Collecting p_s.setup_instruments wait/synch/mutex configuration settings")
34 rows, err := dbh.Query(sql)
42 var r setup_instruments_row
46 &r.TIMED); err != nil {
49 // we collect all information even if it's mainly empty as we may reference it later
50 si.rows = append(si.rows, r)
53 if err := rows.Err(); err != nil {
56 lib.Logger.Println("- found", count, "rows whose configuration need changing")
58 // update the rows which need to be set - do multiple updates but I don't care
59 lib.Logger.Println("Updating p_s.setup_instruments to allow wait/synch/mutex configuration")
62 for i := range si.rows {
63 sql := "UPDATE setup_instruments SET enabled = 'YES', TIMED = 'YES' WHERE NAME = '" + si.rows[i].NAME + "'"
64 if _, err := dbh.Exec(sql); err == nil {
65 si.update_succeeded = true
67 found_expected := false
68 for i := range EXPECTED_UPDATE_ERRORS {
69 if err.Error()[0:10] == EXPECTED_UPDATE_ERRORS[i] {
77 lib.Logger.Println( "Insufficient privileges to UPDATE setup_instruments: " + err.Error() )
82 if si.update_succeeded {
83 lib.Logger.Println(count, "rows changed in p_s.setup_instruments")
87 // restore any changed rows back to their original state
88 func (si *SetupInstruments) Restore(dbh *sql.DB) {
89 // If the previous update didn't work then don't try to restore
90 if ! si.update_succeeded {
91 lib.Logger.Println("Not restoring p_s.setup_instruments to its original settings as previous UPDATE had failed")
94 lib.Logger.Println("Restoring p_s.setup_instruments to its original settings")
97 // update the rows which need to be set - do multiple updates but I don't care
99 for i := range si.rows {
100 sql := "UPDATE setup_instruments SET enabled = '" + si.rows[i].ENABLED + "', TIMED = '" + si.rows[i].TIMED + "' WHERE NAME = '" + si.rows[i].NAME + "'"
101 if _, err := dbh.Exec(sql); err != nil {
106 lib.Logger.Println(count, "rows changed in p_s.setup_instruments")