Skip to content
This repository was archived by the owner on May 28, 2021. It is now read-only.

Commit

Permalink
Workaround the improper behavior of MySQL shell with respect to
Browse files Browse the repository at this point in the history
auto_increment_offset and auto_increment_increment values override.

Signed-off-by: Gianluca Borello <[email protected]>
  • Loading branch information
gianlucaborello committed Jun 26, 2018
1 parent d9b3b4f commit c75b6a2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/controllers/cluster/manager/cluster_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ func (m *ClusterManager) handleInstanceMissing(ctx context.Context, primaryAddr
glog.Errorf("Failed to rejoin cluster: %v", err)
return false
}

if !m.Instance.MultiMaster {
err = m.localMySh.SetSinglePrimaryAutoIncrementParams(ctx)
if err != nil {
glog.Errorf("Failed setting auto increment parameters: %v", err)
return false
}
}
} else {
glog.V(4).Infof("Removing instance from cluster")
if err := primarySh.RemoveInstanceFromCluster(ctx, m.Instance.GetShellURI(), mysqlsh.Options{"force": "True"}); err != nil {
Expand Down Expand Up @@ -289,6 +297,15 @@ func (m *ClusterManager) handleInstanceNotFound(ctx context.Context, primaryAddr
glog.Errorf("Failed to add to cluster: %v", err)
return false
}

if !m.Instance.MultiMaster {
err = m.localMySh.SetSinglePrimaryAutoIncrementParams(ctx)
if err != nil {
glog.Errorf("Failed setting auto increment parameters: %v", err)
return false
}
}

return true
}

Expand Down Expand Up @@ -326,6 +343,14 @@ func (m *ClusterManager) createCluster(ctx context.Context) (*innodb.ClusterStat
if err != nil {
return nil, errors.Wrap(err, "failed to create new cluster")
}

if !m.Instance.MultiMaster {
err = m.localMySh.SetSinglePrimaryAutoIncrementParams(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed setting auto increment parameters")
}
}

return status, nil
}

Expand All @@ -341,6 +366,14 @@ func (m *ClusterManager) rebootFromOutage(ctx context.Context) (*innodb.ClusterS
if err != nil {
return nil, errors.Wrap(err, "getting cluster status")
}

if !m.Instance.MultiMaster {
err = m.localMySh.SetSinglePrimaryAutoIncrementParams(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed setting auto increment parameters")
}
}

return status, nil
}

Expand Down
28 changes: 28 additions & 0 deletions pkg/util/mysqlsh/mysqlsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type Interface interface {
// RebootClusterFromCompleteOutage recovers a cluster when all of its members
// have failed.
RebootClusterFromCompleteOutage(ctx context.Context) error
// SetSinglePrimaryAutoIncrementParams sets auto increment parameters to 1 and
// it should be called in single primary mode.
SetSinglePrimaryAutoIncrementParams(ctx context.Context) error
}

// errorRegex is used to parse Python tracebacks generated by mysql-shell.
Expand Down Expand Up @@ -202,6 +205,31 @@ func (r *runner) RebootClusterFromCompleteOutage(ctx context.Context) error {
return err
}

func (r *runner) SetSinglePrimaryAutoIncrementParams(ctx context.Context) error {
// Restore auto_increment_offset and auto_increment_increment
// to a safe 1 value, since we are in single primary mode.
// There seems to be a bug in MySQL Shell, and it initializes
// them to 7 and 1+id%7, which is not ideal. Also, from MySQL 8,
// MySQL will not overwrite these values according to
// group_replication_auto_increment_increment and its default of 7,
// so there's a wrong MySQL Shell assumption
// (https://github.com/mysql/mysql-server/commit/846ced27f8315a4697405b2b9a7bdeadb44cf070)

python := fmt.Sprintf("session.query('SET PERSIST auto_increment_offset = 1')")
_, err := r.run(ctx, python)
if err != nil {
return err
}

python = fmt.Sprintf("session.query('SET PERSIST auto_increment_increment = 1')")
_, err = r.run(ctx, python)
if err != nil {
return err
}

return nil
}

// Error holds errors from mysql-shell commands.
type Error struct {
error
Expand Down

0 comments on commit c75b6a2

Please sign in to comment.