Skip to content

Commit bf00608

Browse files
authored
Merge branch 'percona:master' into DISTMYSQL-226
2 parents fe63cdd + c0a82c7 commit bf00608

37 files changed

+1935
-31
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/openark/orchestrator
33
go 1.16
44

55
require (
6+
github.com/Showmax/go-fqdn v1.0.0 // indirect
67
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6
78
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect
89
github.com/cyberdelia/go-metrics-graphite v0.0.0-20161219230853-39f87cc3b432
@@ -47,6 +48,7 @@ require (
4748

4849
replace (
4950
github.com/hashicorp/raft => github.com/openark/raft v0.0.0-20170918052300-fba9f909f7fe
51+
github.com/openark/golib => ./go/golib
5052
golang.org/x/text v0.3.0 => golang.org/x/text v0.3.8
5153
golang.org/x/text v0.3.7 => golang.org/x/text v0.3.8
5254
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/Showmax/go-fqdn v1.0.0 h1:0rG5IbmVliNT5O19Mfuvna9LL7zlHyRfsSvBPZmF9tM=
2+
github.com/Showmax/go-fqdn v1.0.0/go.mod h1:SfrFBzmDCtCGrnHhoDjuvFnKsWjEQX/Q9ARZvOrJAko=
13
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
24
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 h1:G1bPvciwNyF7IUmKXNt9Ak3m6u9DE1rF+RmtIkBpVdA=
35
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=

go/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ type Configuration struct {
278278
EnforceExactSemiSyncReplicas bool // If true, semi-sync replicas will be enabled/disabled to match the wait count in the desired priority order; this applies to LockedSemiSyncMaster and MasterWithTooManySemiSyncReplicas
279279
RecoverLockedSemiSyncMaster bool // If true, orchestrator will recover from a LockedSemiSync state by enabling semi-sync on replicas to match the wait count; this behavior can be overridden by EnforceExactSemiSyncReplicas
280280
ReasonableLockedSemiSyncMasterSeconds uint // Time to evaluate the LockedSemiSyncHypothesis before triggering the LockedSemiSync analysis; falls back to ReasonableReplicationLagSeconds if not set
281+
PrependMessagesWithOrcIdentity string // use FQDN/hostname/custom to prefix error message returned to the client. Empty string (default)/none skips prefixing.
282+
CustomOrcIdentity string // use if PrependMessagesWithOrcIdentity is 'custom'
281283
}
282284

283285
// ToJSONString will marshal this configuration as JSON
@@ -452,6 +454,8 @@ func newConfiguration() *Configuration {
452454
EnforceExactSemiSyncReplicas: false,
453455
RecoverLockedSemiSyncMaster: false,
454456
ReasonableLockedSemiSyncMasterSeconds: 0,
457+
PrependMessagesWithOrcIdentity: "",
458+
CustomOrcIdentity: "",
455459
}
456460
}
457461

go/db/db.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"regexp"
24+
"strconv"
2425
"strings"
2526
"sync"
2627
"time"
@@ -100,7 +101,8 @@ func openTopology(host string, port int, readTimeout int) (db *sql.DB, err error
100101
return nil, err
101102
}
102103
}
103-
if db, _, err = sqlutils.GetDB(mysql_uri); err != nil {
104+
sqlUtilsLogger := SqlUtilsLogger{client_context: host + ":" + strconv.Itoa(port)}
105+
if db, _, err = sqlutils.GetDB(mysql_uri, sqlUtilsLogger); err != nil {
104106
return nil, err
105107
}
106108
if config.Config.MySQLConnectionLifetimeSeconds > 0 {
@@ -123,7 +125,8 @@ func openOrchestratorMySQLGeneric() (db *sql.DB, fromCache bool, err error) {
123125
if config.Config.MySQLOrchestratorUseMutualTLS {
124126
uri, _ = SetupMySQLOrchestratorTLS(uri)
125127
}
126-
return sqlutils.GetDB(uri)
128+
sqlUtilsLogger := SqlUtilsLogger{client_context: config.Config.MySQLOrchestratorHost + ":" + config.Config.MySQLOrchestratorHost}
129+
return sqlutils.GetDB(uri, sqlUtilsLogger)
127130
}
128131

129132
func IsSQLite() bool {
@@ -174,7 +177,7 @@ func safeMySQLURI(dsn string) string {
174177
func OpenOrchestrator() (db *sql.DB, err error) {
175178
var fromCache bool
176179
if IsSQLite() {
177-
db, fromCache, err = sqlutils.GetSQLiteDB(config.Config.SQLite3DataFile)
180+
db, fromCache, err = sqlutils.GetSQLiteDB(config.Config.SQLite3DataFile, nil)
178181
if err == nil && !fromCache {
179182
log.Debugf("Connected to orchestrator backend: sqlite on %v", config.Config.SQLite3DataFile)
180183
}
@@ -191,7 +194,8 @@ func OpenOrchestrator() (db *sql.DB, err error) {
191194
}
192195
}
193196
dsn := getMySQLURI()
194-
db, fromCache, err = sqlutils.GetDB(dsn)
197+
sqlUtilsLogger := SqlUtilsLogger{client_context: dsn}
198+
db, fromCache, err = sqlutils.GetDB(dsn, sqlUtilsLogger)
195199
if err == nil && !fromCache {
196200
log.Debugf("Connected to orchestrator backend: %v", safeMySQLURI(dsn))
197201

go/db/tls.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package db
1919
import (
2020
"crypto/tls"
2121
"fmt"
22+
"strconv"
2223
"strings"
2324
"time"
2425

@@ -55,6 +56,23 @@ func init() {
5556
metrics.Register("instance_tls.write_cache", writeInstanceTLSCacheCounter)
5657
}
5758

59+
type SqlUtilsLogger struct {
60+
client_context string
61+
}
62+
63+
func (logger SqlUtilsLogger) OnError(caller_context string, query string, err error) error {
64+
query = strings.Join(strings.Fields(query), " ") // trim whitespaces
65+
query = strings.Replace(query, "%", "%%", -1) // escape %
66+
67+
msg := fmt.Sprintf("%+v(%+v) %+v: %+v",
68+
caller_context,
69+
logger.client_context,
70+
query,
71+
err)
72+
73+
return log.Errorf(msg)
74+
}
75+
5876
func requiresTLS(host string, port int, mysql_uri string) bool {
5977
cacheKey := fmt.Sprintf("%s:%d", host, port)
6078

@@ -64,7 +82,8 @@ func requiresTLS(host string, port int, mysql_uri string) bool {
6482
}
6583

6684
required := false
67-
db, _, _ := sqlutils.GetDB(mysql_uri)
85+
sqlUtilsLogger := SqlUtilsLogger{client_context: host + ":" + strconv.Itoa(port)}
86+
db, _, _ := sqlutils.GetDB(mysql_uri, sqlUtilsLogger)
6887
if err := db.Ping(); err != nil && (strings.Contains(err.Error(), Error3159) || strings.Contains(err.Error(), Error1045)) {
6988
required = true
7089
}

go/golib/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module golib
2+
3+
go 1.18

0 commit comments

Comments
 (0)