Skip to content

Commit

Permalink
When a new master is initialized, make it writable when ignoreReadOnl…
Browse files Browse the repository at this point in the history
…y is true.
  • Loading branch information
dougfales committed Apr 6, 2020
1 parent 4e461de commit 5ab4183
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/controller/node/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ func (r *ReconcileMysqlNode) initializeMySQL(ctx context.Context, sql SQLInterfa
if err != nil {
return err
}
defer enableSuperReadOnly()
defer func() {
if !cluster.Spec.IgnoreReadOnly {
enableSuperReadOnly()
}
}()

// check if the skip GTID_PURGED annotation is set on the cluster first
// and if it's set then mark the GTID_PURGED set in status table
Expand All @@ -289,6 +293,12 @@ func (r *ReconcileMysqlNode) initializeMySQL(ctx context.Context, sql SQLInterfa
if err := sql.ChangeMasterTo(ctx, cluster.GetMasterHost(), c.ReplicationUser, c.ReplicationPassword); err != nil {
return err
}
} else if cluster.Spec.IgnoreReadOnly {
// When ignoreReadOnly setting is true, then only on initialization, we will set the master to writable.
// This kicks off the new cluster with a writable master; otherwise it would never be marked writable, as the
//ignoreReadOnly setting prevents any interference whatsoever in the Orchestrator reconciliation loop.
log.Info("setting master writable on initialization *only* due to ignoreReadOnly=true")
sql.DisableReadOnly(ctx)
}

// write the configuration complete flag into MySQL, this will make the node ready
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/node/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
type SQLInterface interface {
Wait(ctx context.Context) error
DisableSuperReadOnly(ctx context.Context) (func(), error)
DisableReadOnly(ctx context.Context) error
ChangeMasterTo(ctx context.Context, host string, user string, pass string) error
MarkConfigurationDone(ctx context.Context) error
IsConfigured(ctx context.Context) (bool, error)
Expand Down Expand Up @@ -90,6 +91,10 @@ func (r *nodeSQLRunner) DisableSuperReadOnly(ctx context.Context) (func(), error
return enable, r.runQuery(ctx, "SET GLOBAL READ_ONLY = 1; SET GLOBAL SUPER_READ_ONLY = 0;")
}

func (r *nodeSQLRunner) DisableReadOnly(ctx context.Context) error {
return r.runQuery(ctx, "SET GLOBAL SUPER_READ_ONLY = 0; SET GLOBAL READ_ONLY = 0;")
}

// ChangeMasterTo changes the master host and starts slave.
func (r *nodeSQLRunner) ChangeMasterTo(ctx context.Context, masterHost, user, pass string) error {
// slave node
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/node/sql_fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func (f *fakeSQLRunner) DisableSuperReadOnly(ctx context.Context) (func(), error
return func() {}, nil
}

func (f *fakeSQLRunner) DisableReadOnly(ctx context.Context) error {
return nil
}

func (f *fakeSQLRunner) ChangeMasterTo(ctx context.Context, host, user, pass string) error {
return nil
}
Expand Down

0 comments on commit 5ab4183

Please sign in to comment.