Skip to content

Commit

Permalink
Support for MySQL 5.7 as backend database
Browse files Browse the repository at this point in the history
- implied by support for NO_ZERO_DATE,NO_ZERO_IN_DATE sql_mode, so
shockingly ignored by now.
- fixed schemas to never have zero in date
- ugly sql_mode hack as backwards-compatability mechanism

orchestrator -c help does now initiate any db action
  • Loading branch information
shlomi-noach committed Nov 3, 2015
1 parent 4a2e19a commit f925732
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
set -e

RELEASE_VERSION="1.4.475"
RELEASE_VERSION="1.4.476"
TOPDIR=/tmp/orchestrator-release
export RELEASE_VERSION TOPDIR

Expand Down
4 changes: 3 additions & 1 deletion go/cmd/orchestrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,9 @@ Full blown documentation:
os.Exit(1)
}

process.ContinuousRegistration(string(executionMode))
if *command != "help" {
process.ContinuousRegistration(string(executionMode))
}
switch executionMode {
case CliMode:
app.Cli(*command, *strict, *instance, *destination, *owner, *reason, *duration, *pattern, *clusterAlias, *pool, *hostnameFlag)
Expand Down
66 changes: 64 additions & 2 deletions go/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,37 @@ var generateSQLPatches = []string{
ALTER TABLE node_health
ADD COLUMN extra_info varchar(128) CHARACTER SET utf8 NOT NULL
`,
`
ALTER TABLE agent_seed
MODIFY end_timestamp timestamp NOT NULL DEFAULT '1971-01-01 00:00:00'
`,
`
ALTER TABLE active_node
MODIFY last_seen_active timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
`,

`
ALTER TABLE node_health
MODIFY last_seen_active timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
`,
`
ALTER TABLE candidate_database_instance
MODIFY last_suggested timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
`,
`
ALTER TABLE master_position_equivalence
MODIFY last_suggested timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
`,
`
ALTER TABLE
database_instance
ADD COLUMN last_attempted_check TIMESTAMP NOT NULL DEFAULT '1971-01-01 00:00:00' AFTER last_checked
`,
`
ALTER TABLE
database_instance
MODIFY last_attempted_check TIMESTAMP NOT NULL DEFAULT '1971-01-01 00:00:00'
`,
}

// Track if a TLS has already been configured for topology
Expand Down Expand Up @@ -775,6 +806,27 @@ func SetupMySQLOrchestratorTLS(uri string) (string, error) {
// deployIfNotAlreadyDeployed will issue given sql queries that are not already known to be deployed.
// This iterates both lists (to-run and already-deployed) and also verifies no contraditions.
func deployIfNotAlreadyDeployed(db *sql.DB, queries []string, deployedQueries []string, deploymentType string, fatalOnError bool) error {
tx, err := db.Begin()
if err != nil {
log.Fatale(err)
}
// Ugly workaround ahead.
// Origin of this workaround is the existence of some "timestamp NOT NULL," column definitions,
// where in NO_ZERO_IN_DATE,NO_ZERO_DATE sql_mode are invalid (since default is implicitly "0")
// This means installation of orchestrator fails on such configured servers, and in particular on 5.7
// where this setting is the dfault.
// For purpose of backwards compatability, what we do is force sql_mode to be more relaxed, create the schemas
// along with the "invalid" definition, and then go ahead and fix those definitions via following ALTER statements.
// My bad.
originalSqlMode := ""
err = tx.QueryRow(`select @@session.sql_mode`).Scan(&originalSqlMode)
if _, err := tx.Exec(`set @@session.sql_mode=REPLACE(@@session.sql_mode, 'NO_ZERO_DATE', '')`); err != nil {
log.Fatale(err)
}
if _, err := tx.Exec(`set @@session.sql_mode=REPLACE(@@session.sql_mode, 'NO_ZERO_IN_DATE', '')`); err != nil {
log.Fatale(err)
}

for i, query := range queries {
queryAlreadyExecuted := false
// While iterating 'queries', also iterate 'deployedQueries'. Expect identity
Expand All @@ -787,19 +839,29 @@ func deployIfNotAlreadyDeployed(db *sql.DB, queries []string, deployedQueries []
if queryAlreadyExecuted {
continue
}
if i == 0 {
log.Debugf("sql_mode is: %+v", originalSqlMode)
}
if config.Config.SmartOrchestratorDatabaseUpdate {
log.Debugf("initOrchestratorDB executing: %.80s", strings.TrimSpace(strings.Replace(query, "\n", "", -1)))
}

if fatalOnError {
if _, err := execInternal(db, query); err != nil {
if _, err := tx.Exec(query); err != nil {
return log.Fatalf("Cannot initiate orchestrator: %+v", err)
}
} else {
execInternalSilently(db, query)
tx.Exec(query)
// And ignore any error
}
writeInternalDeployment(db, deploymentType, query, i)
}
if _, err := tx.Exec(`set session sql_mode=?`, originalSqlMode); err != nil {
log.Fatale(err)
}
if err := tx.Commit(); err != nil {
log.Fatale(err)
}
return nil
}

Expand Down

0 comments on commit f925732

Please sign in to comment.